Skip to content

Commit a4e8e74

Browse files
authored
i18n: Add charset related settings (#408307)
2 parents e3a5e6a + 263297b commit a4e8e74

File tree

4 files changed

+87
-15
lines changed

4 files changed

+87
-15
lines changed

doc/release-notes/rl-2505.section.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
- `i18n.extraLocales` should now be the preferred way to install additional locales.
375375
- `i18n.supportedLocales` is now considered an implementation detail and will be hidden from the documentation. But the option will still continue to work.
376376
- `i18n.supportedLocales` will now trigger a warning when it omits any locale set in `i18n.defaultLocale`, `i18n.extraLocales` or `i18n.extraLocaleSettings`.
377+
- 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.
377378

378379
- `titaniumenv`, `titanium`, and `titanium-alloy` have been removed due to lack of maintenance in Nixpkgs []{#sec-nixpkgs-release-25.05-incompatibilities-titanium-removed}.
379380

nixos/modules/config/i18n.nix

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
...
66
}:
77
let
8+
sanitizeUTF8Capitalization =
9+
lang: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] lang);
810
aggregatedLocales =
9-
(builtins.map
10-
(l: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8")
11-
(
12-
[ config.i18n.defaultLocale ]
13-
++ (lib.optionals (builtins.isList config.i18n.extraLocales) config.i18n.extraLocales)
14-
++ (lib.attrValues (lib.filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings))
15-
)
16-
)
11+
[
12+
"${config.i18n.defaultLocale}/${config.i18n.defaultCharset}"
13+
]
14+
++ lib.pipe config.i18n.extraLocaleSettings [
15+
(lib.mapAttrs (n: v: (sanitizeUTF8Capitalization v)))
16+
(lib.mapAttrsToList (LCRole: lang: lang + "/" + (config.i18n.localeCharsets.${LCRole} or "UTF-8")))
17+
]
18+
++ (builtins.map sanitizeUTF8Capitalization (
19+
lib.optionals (builtins.isList config.i18n.extraLocales) config.i18n.extraLocales
20+
))
1721
++ (lib.optional (builtins.isString config.i18n.extraLocales) config.i18n.extraLocales);
1822
in
1923
{
@@ -48,16 +52,24 @@ in
4852
default = "en_US.UTF-8";
4953
example = "nl_NL.UTF-8";
5054
description = ''
51-
The default locale. It determines the language for program
52-
messages, the format for dates and times, sort order, and so on.
53-
It also determines the character set, such as UTF-8.
55+
The default locale. It determines the language for program messages,
56+
the format for dates and times, sort order, and so on. Setting the
57+
default character set is done via {option}`i18n.defaultCharset`.
58+
'';
59+
};
60+
defaultCharset = lib.mkOption {
61+
type = lib.types.str;
62+
default = "UTF-8";
63+
example = "ISO-8859-8";
64+
description = ''
65+
The default locale character set.
5466
'';
5567
};
5668

5769
extraLocales = lib.mkOption {
5870
type = lib.types.either (lib.types.listOf lib.types.str) (lib.types.enum [ "all" ]);
5971
default = [ ];
60-
example = [ "nl_NL.UTF-8" ];
72+
example = [ "nl_NL.UTF-8/UTF-8" ];
6173
description = ''
6274
Additional locales that the system should support, besides the ones
6375
configured with {option}`i18n.defaultLocale` and
@@ -74,9 +86,24 @@ in
7486
LC_TIME = "de_DE.UTF-8";
7587
};
7688
description = ''
77-
A set of additional system-wide locale settings other than
78-
`LANG` which can be configured with
79-
{option}`i18n.defaultLocale`.
89+
A set of additional system-wide locale settings other than `LANG`
90+
which can be configured with {option}`i18n.defaultLocale`. Note that
91+
the `/UTF-8` suffix used in {option}`i18n.extraLocales` indicates a
92+
character set, and it must not be added manually here. To use a
93+
non-`UTF-8` character set such as ISO-XXXX-8, the
94+
{option}`i18n.localeCharsets` can be used.
95+
'';
96+
};
97+
localeCharsets = lib.mkOption {
98+
type = lib.types.attrsOf lib.types.str;
99+
default = { };
100+
example = {
101+
LC_MESSAGES = "ISO-8859-15";
102+
LC_TIME = "ISO-8859-1";
103+
};
104+
description = ''
105+
Per each {option}`i18n.extraLocaleSettings`, choose the character set
106+
to use for it. Essentially defaults to UTF-8 for all of them.
80107
'';
81108
};
82109

nixos/tests/all-tests.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ in
994994
orthanc = runTest ./orthanc.nix;
995995
owncast = handleTest ./owncast.nix { };
996996
outline = handleTest ./outline.nix { };
997+
i18n = runTest ./i18n.nix;
997998
image-contents = handleTest ./image-contents.nix { };
998999
openvscode-server = handleTest ./openvscode-server.nix { };
9991000
open-webui = runTest ./open-webui.nix;

nixos/tests/i18n.nix

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{ lib, ... }:
2+
{
3+
name = "glibLocales-custom-builds";
4+
meta.maintainers = with lib.maintainers; [ doronbehar ];
5+
6+
nodes = {
7+
nonUTF8Charset = {
8+
i18n = {
9+
defaultLocale = "en_US";
10+
defaultCharset = "ISO-8859-1";
11+
};
12+
};
13+
extraLocales1 = {
14+
i18n = {
15+
defaultLocale = "en_US.UTF-8";
16+
extraLocales = [
17+
"nl_NL.UTF-8/UTF-8"
18+
];
19+
};
20+
};
21+
extraLocaleSettings = {
22+
i18n = {
23+
defaultLocale = "en_US.UTF-8";
24+
extraLocaleSettings = {
25+
LC_MESSAGES = "en_US.UTF-8";
26+
LC_TIME = "de_DE.UTF-8";
27+
};
28+
};
29+
};
30+
localeCharsets = {
31+
i18n = {
32+
defaultLocale = "en_US.UTF-8";
33+
extraLocaleSettings = {
34+
LC_TIME = "de_DE";
35+
};
36+
localeCharsets = {
37+
LC_TIME = "ISO-8859-1";
38+
};
39+
};
40+
};
41+
};
42+
testScript = { nodes, ... }: "";
43+
}

0 commit comments

Comments
 (0)