diff --git a/doc_src/cmds/_.rst b/doc_src/cmds/_.rst new file mode 100644 index 000000000..c1b73464e --- /dev/null +++ b/doc_src/cmds/_.rst @@ -0,0 +1,38 @@ +.. _cmd-_: + +_ - call fish's translations +============================ + +Synopsis +-------- + +:: + + _ STRING... + +Description +----------- + +``_`` translates its arguments into the current language, if possible. + +It is equivalent to ``gettext fish STRING``, meaning it can only be used to look up fish's own translations. + +It requires fish to be built with gettext support. If that support is disabled, or there is no translation it will simply echo the argument back. + +The language depends on the current locale, set with ``$LANG`` and ``$LC_MESSAGES``. + + +Options +------- + +``_`` has no options. + +Examples +-------- + + + +:: + + > _ File + Datei diff --git a/share/functions/_.fish b/share/functions/_.fish deleted file mode 100644 index ee4e25b37..000000000 --- a/share/functions/_.fish +++ /dev/null @@ -1,22 +0,0 @@ -# -# Alias for gettext or a fallback if gettext isn't installed. -# -# Use ggettext if available. -# This is the case on OpenIndiana, where the default gettext -# interprets `\n` itself, so -# printf (_ 'somemessage\n') -# won't print a newline. -if command -sq ggettext - function _ --description "Alias for the ggettext command" - command ggettext fish $argv - end -else if command -sq gettext - function _ --description "Alias for the gettext command" - command gettext fish $argv - end -else - function _ --description "Fallback alias for the gettext command" - echo -n $argv - end -end - diff --git a/src/builtin.cpp b/src/builtin.cpp index 3914f59a5..af5388ab4 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -327,6 +327,15 @@ int builtin_false(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return STATUS_CMD_ERROR; } +int builtin_gettext(parser_t &parser, io_streams_t &streams, wchar_t **argv) { + UNUSED(parser); + UNUSED(streams); + for (int i = 1; i < builtin_count_args(argv); i++) { + streams.out.append(_(argv[i])); + } + return STATUS_CMD_OK; +} + // END OF BUILTIN COMMANDS // Below are functions for handling the builtin commands. // THESE MUST BE SORTED BY NAME! Completion lookup uses binary search. @@ -338,6 +347,7 @@ static const builtin_data_t builtin_datas[] = { {L".", &builtin_source, N_(L"Evaluate contents of file")}, {L":", &builtin_true, N_(L"Return a successful result")}, {L"[", &builtin_test, N_(L"Test a condition")}, + {L"_", &builtin_gettext, N_(L"Translate a string")}, {L"and", &builtin_generic, N_(L"Execute command if previous command succeeded")}, {L"argparse", &builtin_argparse, N_(L"Parse options in fish script")}, {L"begin", &builtin_generic, N_(L"Create a block of code")}, @@ -393,7 +403,8 @@ static const builtin_data_t builtin_datas[] = { {L"true", &builtin_true, N_(L"Return a successful result")}, {L"ulimit", &builtin_ulimit, N_(L"Set or get the shells resource usage limits")}, {L"wait", &builtin_wait, N_(L"Wait for background processes completed")}, - {L"while", &builtin_generic, N_(L"Perform a command multiple times")}}; + {L"while", &builtin_generic, N_(L"Perform a command multiple times")}, +}; #define BUILTIN_COUNT (sizeof builtin_datas / sizeof *builtin_datas)