l10n: implement status language builtin

Based on the discussion in
https://github.com/fish-shell/fish-shell/pull/11967

Introduce a `status language` builtin, which has subcommands for
controlling and inspecting fish's message localization status.

The motivation for this is that using only the established environment
variables `LANGUAGE`, `LC_ALL`, `LC_MESSAGES`, and `LANG` can cause
problems when fish interprets them differently from GNU gettext.
In addition, these are not well-suited for users who want to override
their normal localization settings only for fish, since fish would
propagate the values of these variables to its child processes.

Configuration via these variables still works as before, but now there
is the `status language set` command, which allows overriding the
localization configuration.
If `status language set` is used, the language precedence list will be
taken from its remaining arguments.
Warnings will be shown for invalid arguments.
Once this command was used, the localization related environment
variables are ignored.
To go back to taking the configuration from the environment variables
after `status language set` was executed, users can run `status language
unset`.

Running `status language` without arguments shows information about the
current message localization status, allowing users to better understand
how their settings are interpreted by fish.

The `status language list-available` command shows which languages are
available to choose from, which is used for completions.

This commit eliminates dependencies from the `gettext_impl` module to
code in fish's main crate, allowing for extraction of this module into
its own crate in a future commit.

Closes #12106
This commit is contained in:
Daniel Rainer
2025-11-24 00:22:13 +01:00
committed by Johannes Altmanninger
parent c0b95a0ee1
commit aa8f5fc77e
18 changed files with 776 additions and 112 deletions

View File

@@ -23,6 +23,8 @@ If other programs launched via fish should respect these locale variables they h
For :envvar:`LANGUAGE` you can use a list, or use colons to separate multiple languages.
If the :ref:`status language set <status-language>` command was used, its arguments specify the language precedence, and the environment variables are ignored.
Options
-------

View File

@@ -33,6 +33,7 @@ Synopsis
status list-files [PATH ...]
status terminal
status test-terminal-feature FEATURE
status language [list-available|set [LANGUAGE ...]|unset]
Description
-----------
@@ -146,6 +147,32 @@ The following operations (subcommands) are available:
Currently the only available *FEATURE* is :ref:`scroll-content-up <term-compat-indn>`.
An error will be printed when passed an unrecognized feature.
.. _status-language:
**language**
Show or modify message localization settings.
When invoked without arguments, the current language settings are shown.
Available subcommands:
**list-available**
prints the language names for which fish has translations.
These names can be used with the **set** subcommand.
**set**
sets the language precedence for fish's messages.
Overrides language settings configured via :ref:`environment variables <variables-locale>`, but only applies to fish itself, not to any child processes.
Takes a list of language names from the set shown by the **list-available** subcommand.
For some languages, fish's translation catalogs are incomplete, meaning not all messages can be shown in these languages.
Therefore, we allow specifying a list here, with translations taken from the first specified language which has a translation available for a message.
For example, after running ``status language set pt_BR fr``, all messages which have a translation into Brazilian Portuguese will be shown in that language.
The remaining messages will be shown in French, if a French translation is available.
If none of the specified languages have a translation available for a message, the message will be shown in English.
**unset**
undoes the effects of the **set** subcommand.
Language settings will be taken from environment variables again.
Notes
-----

View File

@@ -1549,7 +1549,8 @@ You can change the settings of fish by changing the values of certain variables.
.. describe:: Locale Variables
Locale variables such as :envvar:`LANG`, :envvar:`LC_ALL`, :envvar:`LC_MESSAGES`, :envvar:`LC_NUMERIC` and :envvar:`LC_TIME` set the language option for the shell and subprograms. See the section :ref:`Locale variables <variables-locale>` for more information.
Locale variables such as :envvar:`LANG`, :envvar:`LC_ALL`, :envvar:`LC_MESSAGES`, :envvar:`LC_NUMERIC` and :envvar:`LC_TIME` set the language option for the shell and subprograms.
See the section :ref:`Locale variables <variables-locale>` and :ref:`status language <status-language>` for more information.
.. describe:: Color variables