i18n: Add charset related settings

Fixes #404758
This commit is contained in:
Doron Behar 2025-05-18 12:35:11 +03:00
parent 455782de23
commit e8581078a1
2 changed files with 45 additions and 15 deletions

View File

@ -374,6 +374,7 @@
- `i18n.extraLocales` should now be the preferred way to install additional locales. - `i18n.extraLocales` should now be the preferred way to install additional locales.
- `i18n.supportedLocales` is now considered an implementation detail and will be hidden from the documentation. But the option will still continue to work. - `i18n.supportedLocales` is now considered an implementation detail and will be hidden from the documentation. But the option will still continue to work.
- `i18n.supportedLocales` will now trigger a warning when it omits any locale set in `i18n.defaultLocale`, `i18n.extraLocales` or `i18n.extraLocaleSettings`. - `i18n.supportedLocales` will now trigger a warning when it omits any locale set in `i18n.defaultLocale`, `i18n.extraLocales` or `i18n.extraLocaleSettings`.
- The options `i18n.defaultCharset` & `i18n.localeCharsets` were added, and they complement `i18n.defaultLocale` & `i18n.extraLocaleSettings` respectively - allowing to control the character set used per locale setting.
- `titaniumenv`, `titanium`, and `titanium-alloy` have been removed due to lack of maintenance in Nixpkgs []{#sec-nixpkgs-release-25.05-incompatibilities-titanium-removed}. - `titaniumenv`, `titanium`, and `titanium-alloy` have been removed due to lack of maintenance in Nixpkgs []{#sec-nixpkgs-release-25.05-incompatibilities-titanium-removed}.

View File

@ -5,15 +5,21 @@
... ...
}: }:
let let
sanitizeUTF8Capitalization =
lang: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] lang);
aggregatedLocales = aggregatedLocales =
(builtins.map [
(l: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8") "${config.i18n.defaultLocale}/${config.i18n.defaultCharset}"
( ]
[ config.i18n.defaultLocale ] ++ lib.pipe config.i18n.extraLocaleSettings [
++ (lib.optionals (builtins.isList config.i18n.extraLocales) config.i18n.extraLocales) # TODO: Explain why is this filter added here...
++ (lib.attrValues (lib.filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings)) (lib.filterAttrs (n: v: n != "LANGUAGE"))
) (lib.mapAttrs (n: v: (sanitizeUTF8Capitalization v)))
) (lib.mapAttrsToList (LCRole: lang: lang + "/" + (config.i18n.localeCharsets.${LCRole} or "UTF-8")))
]
++ (builtins.map sanitizeUTF8Capitalization (
lib.optionals (builtins.isList config.i18n.extraLocales) config.i18n.extraLocales
))
++ (lib.optional (builtins.isString config.i18n.extraLocales) config.i18n.extraLocales); ++ (lib.optional (builtins.isString config.i18n.extraLocales) config.i18n.extraLocales);
in in
{ {
@ -48,16 +54,24 @@ in
default = "en_US.UTF-8"; default = "en_US.UTF-8";
example = "nl_NL.UTF-8"; example = "nl_NL.UTF-8";
description = '' description = ''
The default locale. It determines the language for program The default locale. It determines the language for program messages,
messages, the format for dates and times, sort order, and so on. the format for dates and times, sort order, and so on. Setting the
It also determines the character set, such as UTF-8. default character set is done via {option}`i18n.defaultCharset`.
'';
};
defaultCharset = lib.mkOption {
type = lib.types.str;
default = "UTF-8";
example = "ISO-8859-8";
description = ''
The default locale character set.
''; '';
}; };
extraLocales = lib.mkOption { extraLocales = lib.mkOption {
type = lib.types.either (lib.types.listOf lib.types.str) (lib.types.enum [ "all" ]); type = lib.types.either (lib.types.listOf lib.types.str) (lib.types.enum [ "all" ]);
default = [ ]; default = [ ];
example = [ "nl_NL.UTF-8" ]; example = [ "nl_NL.UTF-8/UTF-8" ];
description = '' description = ''
Additional locales that the system should support, besides the ones Additional locales that the system should support, besides the ones
configured with {option}`i18n.defaultLocale` and configured with {option}`i18n.defaultLocale` and
@ -74,9 +88,24 @@ in
LC_TIME = "de_DE.UTF-8"; LC_TIME = "de_DE.UTF-8";
}; };
description = '' description = ''
A set of additional system-wide locale settings other than A set of additional system-wide locale settings other than `LANG`
`LANG` which can be configured with which can be configured with {option}`i18n.defaultLocale`. Note that
{option}`i18n.defaultLocale`. the `/UTF-8` suffix used in {option}`i18n.extraLocales` indicates a
character set, and it must not be added manually here. To use a
non-`UTF-8` character set such as ISO-XXXX-8, the
{option}`i18n.localeCharsets` can be used.
'';
};
localeCharsets = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = { };
example = {
LC_MESSAGES = "ISO-8859-15";
LC_TIME = "ISO-8859-1";
};
description = ''
Per each {option}`i18n.extraLocaleSettings`, choose the character set
to use for it. Essentially defaults to UTF-8 for all of them.
''; '';
}; };