Skip to content

Commit add6d13

Browse files
committed
Document the CLDR↔GlotPress slug mismatch in the plural-rules generator
`generate_ios_plural_rules.rb` keys CLDR locale codes against GlotPress slugs 1:1, so a language GlotPress addresses by a different code than CLDR (Belarusian is `bel` in GlotPress vs `be` in CLDR; likewise `mya`/`my`, `dzo`/`dz`, …) returns `nil` from `nplurals_for` and is omitted from the generated table. Those locales fail loud (UnknownLocaleError, now a clean `UI.user_error!`) rather than being mis-mapped, and none are in the apps' shipped set — but the omission was undocumented and reads as accidental, since the old hand-written table had `be`. Note the limitation at `nplurals_for` and in the header, including the fix (a vetted CLDR→GlotPress alias map — a literal mapping, not prefix-matching, since `sc`/`scn` and `ve`/`vec` are different languages) for if one of these locales ever ships. Comment-only; the generated table is unchanged.
1 parent 27ac9cb commit add6d13

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

rakelib/generate_ios_plural_rules.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
# 6 categories) the locale is omitted on purpose — the
1717
# converter then fails loud rather than guessing.
1818
#
19+
# A locale is also omitted when GlotPress addresses it under a different slug
20+
# than CLDR (e.g. Belarusian is `bel` in GlotPress vs `be` in CLDR) — see
21+
# `nplurals_for`. These too fail loud rather than mis-map; none are in SHIPPED.
22+
#
1923
# Inputs are vendored under rakelib/plural_rules_data/ for offline reproducibility:
2024
# - cldr_plurals.xml — Unicode CLDR common/supplemental/plurals.xml
2125
# - glotpress_nplurals.json — { slug => nplurals } from GlotPress GP_Locales
@@ -65,6 +69,16 @@ def glotpress_nplurals
6569
JSON.parse(File.read(File.join(DATA_DIR, 'glotpress_nplurals.json')))
6670
end
6771

72+
# GlotPress's plural-form count for a CLDR locale code. CLDR and GlotPress
73+
# usually agree on slugs, but not always: GlotPress addresses some languages by
74+
# an ISO-639-2/3 code where CLDR uses the 639-1 code (Belarusian is `bel` in
75+
# GlotPress vs `be` in CLDR; likewise `mya`/`my`, `dzo`/`dz`, `wol`/`wo`, …). We
76+
# only try the CLDR code and its regional variants, so those locales return
77+
# `nil` here and are omitted from the table — they then fail loud
78+
# (UnknownLocaleError) at runtime rather than being mis-mapped. None are in the
79+
# apps' shipped set today; to support one, add a vetted CLDR→GlotPress alias
80+
# here — a literal mapping, NOT a prefix match (`sc`→`scn` is Sardinian vs
81+
# Sicilian, `ve`→`vec` is Venda vs Venetian, so prefix-guessing is unsafe).
6882
def nplurals_for(base, glotpress)
6983
glotpress[base] || glotpress[glotpress.keys.sort.find { |slug| slug.start_with?("#{base}-") }]
7084
end

0 commit comments

Comments
 (0)