This will help support more projects that use this FileFormat. Inspired by T375653
Description
Related Objects
- Mentioned Here
- T375653: Add Lingua Libre Django to translatewiki.net
Event Timeline
In my opinion we cannot support this:
Vue I18n has only a simple, English-style default. For languages with different plural rules (e.g., Slavic), you must supply your own rule via pluralizationRules (Options API) or pluralRules (Composition API). The official docs show this explicitly and provide an example for Russian.
Because of this, there is no guarantee what rules each project would use, and there is no way to map this to our familiar plural syntax and add required validators for number of expected plural forms.
CC @Tacsipacsi
I see. ☹ Then maybe we should do it better, both in Lingua Libre Django and other non-MediaWiki projects using Codex/Vue? For example by creating a new library? (With a quick search, I couldn’t find any other i18n library for Vue.) Because this not only means that Translate cannot support this syntax, it also means that Lingua Libre Django doesn’t really support languages with complex pluralization rules.
For Gettext we have a database for plural rules, and those are part of the po files. Naturally vue-i18n makes it difficult having the rules as javascript code (with all the security implications).
Actually, the Gettext rules are pretty close to what Vue I18n needs. I think if a Gettext rule (the part after plural=) is stored in the variable rule as a string, then
const customRule = new Function('n', `return Number(${rule}};`); // Number() needed to turn booleans into numbers, which is implicit in C
would be a valid custom rule, except that it doesn’t honor the second parameter (choices length), but maybe that can be handled on the translatewiki.net side. Of course, it should be guaranteed somehow that rule is safe, but given the constrained syntax, it’s probably possible.
This could either be upstreamed or be published as an NPM package depending on Vue I18n, and then any non-MediaWiki Vue project that wishes to use translatewiki.net could be asked to use it.
Although if there is an NPM package anyway, we could just as well provide the rules themselves in it, without any need for storing data in the JSON files.