Repository navigation
Add a public pluralization hook so language packs can render correct plurals #10147
nemezida1337
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Context: I maintain a language pack for DSH — an external client plugin that adds Russian to the web UI (3058 interface strings and 421 plugin display strings, https://github.com/nemezida1337/dsh-locale-russian). It works on 0.1.5-rc.x and 0.2.1-rc.2 and passes its checks on Linux and Windows, but it runs into two things an external plugin cannot reach around. Both are below with code references.
Summary. The locale catalog is documented as extensible, but the runtime has
no plural selection, so a language pack cannot render languages whose plural
rules differ from English.
What happens today.
LocaleRuntime.translateresolves exactly one templateper key:
Components choose the grammatical form themselves, by English rules — for
example
packages/client/ui-trajectory/src/client/TrajectoryTable.tsx:Russian has three categories (1 файл, 2 файла, 5 файлов; 21 файл, 22 файла,
25 файлов), so
count === 1 ? one : othercannot express it. The.one/.otherkey pairs are already in the dictionaries, but the selection lives in component
code, outside anything a language pack can reach.
Workaround a language pack needs today. Wrapping the private prototype
method and encoding up to three
|-separated forms per dictionary value:That works (our pack ships it), but it depends on an internal method name, its
argument order, and its interpolation rules — none of which are part of the
language-pack contract. A rename or a signature change breaks every pack that
supports a language with non-English plural rules, and the failure is silent:
copy keeps rendering, only the agreement degrades.
Proposal. Pick one of:
ctx.locale.addPluralRules({ id: 'ru', select(count) { … } }),applied inside
translatefor keys whose value carries multiple forms; or(count, params) => string) for keys thatneed agreement; or
|-separated multi-form convention as part of thepublic dictionary contract and keep
translate's signature stable.Compatibility. Any of the three is additive: English and Chinese dictionaries
keep single-form values and the existing
.one/.otherselection keeps workingunchanged.
All reactions