Skip to content

Label the locales that language and territory cannot tell apart - #1

Merged
sbelcl merged 2 commits into
sbelcl:system-languagefrom
linyiru:locale-label-disambiguation
Oct 1, 2026
Merged

sbelcl merged 2 commits into
sbelcl:system-languagefrom
linyiru:locale-label-disambiguation

Conversation

@linyiru

@linyiru linyiru commented Sep 30, 2026

Copy link
Copy Markdown

The @modifier disambiguation and the Chinese script hint, against system-language as you invited in #10949. Two commits: one moves the language prompt's tests off the host, the other does the labelling.

The fourth field

You left the side of the line to me, so: omarchy-locale-list grows a fourth field carrying the label, and both in-tree callers read it instead of building one.

The reason is not convenience, it is that the rule cannot be applied anywhere else. "Append the modifier only where the label is not unique" is not a property of a row: whether Serbian (Serbia) is ambiguous depends on the other 326 rows, which a caller formatting one row does not have. A caller could only implement it by making a second pass over the whole list, which is the producer's job by then. The script table has the same shape for a different reason: it is knowledge, and three copies of it would be three copies to keep right.

It also fixes something I had not spotted when I wrote the review. The setup form matched the user's choice back against a label it rebuilt, and the two rows of each pair rebuilt the same string, so the lookup took the first match. On glibc 2.44 the plain locale won all ten times, which means all ten modifier-bearing locales were unreachable from setup: picking "Serbian (Serbia)" got you sr_RS whichever row you clicked, and ca_ES@valencia, uz_UZ@cyrillic and the rest could not be chosen at all. Matching on field 4 makes that lookup single-valued, which is the actual fix; the readable label is the visible half of it.

Your menu was never wrong, since it carries the locale name as subtext and returns that. It was just asking the user to read zh_TW.UTF-8 and know what it implies.

Your plugin keeps working untouched: fields 1 to 3 are byte-for-byte what they were, and opting into the label is a one-line change whenever suits you.

One slot, two sources

You were right that the two fixes share a mechanism. They are one thing: the label drops a distinction the locale name keeps. So there is one qualifier slot, and it is fed from the two places the distinction can come from.

The modifier is read off the name. The script cannot be read off anything, because LC_IDENTIFICATION has no script field, so those four are a table. It stays four entries long because zh is the only language on the list that is written two ways.

Serbian (Serbia, Latin)                       sr_RS@latin
Chinese (Taiwan, Traditional)                 zh_TW.UTF-8

What changes on screen

The setup form, for the three ambiguous groups a reader is most likely to recognise:

before                                       after
-------------------------------------------- --------------------------------------------
Serbian (Montenegro)                         Serbian (Montenegro)
Serbian (Serbia)                             Serbian (Serbia)
Serbian (Serbia)                             Serbian (Serbia, Latin)

Catalan (Andorra)                            Catalan (Andorra)
Catalan (France)                             Catalan (France)
Catalan (Italy)                              Catalan (Italy)
Catalan (Spain)                              Catalan (Spain)
Catalan (Spain)                              Catalan (Spain, Valencia)

Uzbek (Uzbekistan)                           Uzbek (Uzbekistan)
Uzbek (Uzbekistan)                           Uzbek (Uzbekistan, Cyrillic)

And typing "Chinese", where the fix is the other source:

before                                       after
-------------------------------------------- --------------------------------------------
Chinese (China)                              Chinese (China, Simplified)
Chinese (Hong Kong SAR China)                Chinese (Hong Kong SAR China, Traditional)
Chinese (Singapore)                          Chinese (Singapore, Simplified)
Chinese (Taiwan)                             Chinese (Taiwan, Traditional)
Hakka Chinese (Taiwan)                       Hakka Chinese (Taiwan)
Literary Chinese (Taiwan)                    Literary Chinese (Taiwan)
Mandarin Chinese (Taiwan)                    Mandarin Chinese (Taiwan)
Min Nan Chinese (Taiwan)                     Min Nan Chinese (Taiwan)
Min Nan Chinese (Taiwan)                     Min Nan Chinese (Taiwan, Latin)

14 of 327 rows are qualified, so 313 are the length they were. The longest new label, "Chinese (Hong Kong SAR China, Traditional)" at 42 characters, ties "Lingala (Democratic Republic of the Congo)", which was already there. 327 rows produced 317 distinct labels before and produce 327 now.

The modifier only where it disambiguates

Your framing, kept, with one honest caveat: on glibc 2.44 every modifier-bearing locale does share its label, so today "where the label is shared" and "where there is a modifier" pick exactly the same ten rows, and the guard saves nothing yet. I kept it anyway because it is conditioned on the ambiguity rather than on the spelling, so a future locale that is the only one of its language and territory gets the short label it deserves. There is a test for that case, using tt_RU@iqtelif with no plain sibling.

Where I stopped

I did not name the plain row's script. Serbian (Serbia) is still only identifiable by elimination, and a table could say "Cyrillic". I left it because it is not uniformly a script question: @abegede is an alternative alphabetic order for Ge'ez rather than a second script, so gez_ER has no other script to be named, and for the rest it would be a claim about ten languages that nothing in the data can check. The slot is where that table would go if you want it, and it is additive.

I did not extend the script table past zh. cmn_TW, hak_TW, lzh_TW, nan_TW and yue_HK are all Traditional, but no row of those languages spans two scripts, so a qualifier would lengthen a label without resolving anything.

I did not touch the glibc-complete list, which you said you were leaving alone deliberately, and I agree with the reason.

Tests

The first commit is separable and you may want it either way. The setup form's prompts are tested against stubs for gum, tzupdate and timedatectl, but the language prompt ran the real omarchy-locale-list and so read the host's /usr/share/i18n, with $ROOT/bin on PATH for that one command. Off Arch that directory does not exist, the list comes back empty and the language assertions fail; on Arch it is a list that moves with glibc. Stubbing it is also what let me pin the pair that only a modifier tells apart, since asserting that against the host would be asserting that glibc still ships sr_RS@latin.

bin/omarchy-locale-list takes an OMARCHY_I18N_PATH override so the new test/shell.d/locale-list-test.sh can point it at a fixture tree, the way omarchy-windows-key takes OMARCHY_MSDM_PATH. That test covers each labelling rule by name, asserts every emitted label is unique, and asserts a missing locale tree is still empty rather than fatal.

On Arch, glibc 2.44:

                 ./test/cli          ./test/shell
system-language  112 ok, 0 not ok    3212 ok, 4 not ok
this branch      112 ok, 0 not ok    3229 ok, 4 not ok

The same four failures on both, all environmental: three want an omarchy-pkgs checkout that is not there, one is an unrelated migration test. The 17 new passes are this branch's assertions. ./test/cli also fails identically on quattro when run on macOS, which is a platform artefact rather than anything either of us did.

One thing I could not do: I have no Omarchy box on hand, so none of this was seen in a running session. What I verified instead is the exact strings the two pickers receive, generated from real glibc data, which is what the tables above are.

🤖 Generated with Claude Code

The setup form's prompts are tested against stubs for everything they
reach for -- gum, tzupdate, timedatectl -- except the language prompt,
which ran the real omarchy-locale-list and so read the host's
/usr/share/i18n. That is absent anywhere but Arch, where the list comes
back empty and the language assertions fail, and it is a list that moves
with glibc everywhere else.

Stub it like the rest. The assertions that matter are about the prompt,
not about which locales the box building it happens to ship, and pinning
the list is what lets them name a locale on purpose: the pair that only
an @modifier tells apart is the case worth testing, and asserting it
against the host would be asserting that glibc still ships sr_RS@latin.

$ROOT/bin was on PATH for that one command and comes back off.
omarchy-locale-list names a locale by its language and territory, and ten
of glibc's 327 UTF-8 locales share both with another. The difference is
the @modifier the label drops, so the setup form showed "Serbian
(Serbia)" on two rows, and matching the chosen label back against a
rebuilt one took the first row that matched: all ten modifier-bearing
locales were unreachable there, and picking Catalan could not reach
Valencian at all. The menu fared better only because it carries the
locale name as subtext, which is a name, not an answer.

Chinese is ambiguous for a different reason. All four of its locales call
their language "Chinese", and nothing on screen said which of Simplified
and Traditional a territory implies, so the user had to already know that
Taiwan and Hong Kong are Traditional while China and Singapore are not.

Both are one shape: the label drops a distinction the locale name keeps.
So both go in one qualifier slot -- "Serbian (Serbia, Latin)", "Chinese
(Taiwan, Traditional)" -- fed from the two places the distinction can
come from. The modifier is read off the name. The script cannot be read
off anything: LC_IDENTIFICATION has no script field, so those four are a
table, and it stays four entries long because no other language on the
list is written two ways.

A modifier is appended only where the label is shared, leaving the 313
rows that already name one locale as short as they were. Every
modifier-bearing locale glibc ships today does share its label, so today
the two rules pick the same rows; the test is the ambiguity rather than
the modifier so that a future locale which is the only one of its
language and territory keeps the shorter label.

The label is a fourth field rather than something each caller builds,
because uniqueness is not a property of a row: it depends on the rest of
the list, which the caller formatting one row does not have. Both callers
were already rebuilding the same label from fields 2 and 3, and the setup
form was matching the user's choice against a third rebuild of it.
Reading field 4 makes that lookup single-valued and hands the same
disambiguation to anything else that lists locales.

Measured on glibc 2.44: 327 rows before and after, fields 1 to 3
byte-for-byte unchanged, 14 labels qualified, and now 327 distinct
labels where there were 317.

@sbelcl sbelcl left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against glibc 2.44: on the base branch 10 of 327 locales were unreachable from the setup form; with this, every label maps back to exactly one locale, and the setup default still resolves to en_US.UTF-8. Both test files pass. Thanks!

@sbelcl
sbelcl merged commit 0a0bf14 into sbelcl:system-language Oct 1, 2026
@linyiru

linyiru commented Oct 1, 2026

Copy link
Copy Markdown
Author

Thank you, and thank you for the number I did not have. I asserted that the setup form's lookup became single-valued, but I never checked that the default still resolves to en_US.UTF-8, which is the one row a wrong answer would hit every install.

Re-ran at your merged head on Arch, glibc 2.44: the tree is identical to the PR head, so the rebase cost nothing. omarchy-locale-list gives 327 rows, 327 distinct labels, 0 labels shared by more than one row, and 10 rows carrying a modifier. test/shell.d/locale-list-test.sh is 13 ok / 0 not ok and test/shell.d/setup-form-test.sh is 22 ok / 0 not ok, and ./test/shell is 17 ahead of the parent commit with the same failures on both sides.

The two things I deliberately left are still yours to take or leave, and both are additive to the slot rather than changes to it: naming the plain row's script (Serbian (Serbia) is still only identifiable by elimination, and the reason I stopped is that @abegede is an alphabetic order rather than a script, so it cannot be done uniformly), and extending the script table past zh. Say the word on either and I will send it the same way.

The shape is yours: the fourth field is where it is because of your "only where it disambiguates" framing, and the invitation on omacom#10949 is why the work exists at all. Thanks for reviewing a patch to your own branch as closely as you reviewed mine.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants