-
-
Notifications
You must be signed in to change notification settings - Fork 959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails yml import: the key 'one' is loaded as plural form 'zero' if the key 'zero' is missing #4484
Comments
The parser in translate-toolkit has no knowledge of the plurals, it only assumes that CLDR ordering is used. So there is probably no other way to change plural than adding missing keys to the file. See https://github.com/translate/translate/blob/a88557a4a00eec3cc153b1c6edaf31ab377ebe16/translate/storage/yaml.py#L221-L227 for parsing code. |
Thanks for your help. Forcing user to always specify the 'zero' key is a bit boring. In our case, it means adding a thousand useless strings to enable the feature for some keys. The alernative are stopping using zero quantifier or patching the parser/serializer (we use the docker image with auto update script, so it will be more difficult). This issue impacts default configuration of weblate too. With plural_count = 2 for French, just having the key 'other' (without 'one') will silently corrupt the loaded hash. It appened to us in production. Their is a real risk of corrupting imported files, specially when theses files were hand-crafted or exported from localeapp. |
Can you please describe how does the consumer determine which key to use? Does it have defined the custom plural equation as well? I'm just trying to understand how you use the resulting files because that's important part of the picture as well. Having "one" key doesn't really define for which counts it should be used. For some languages it's really just for one, but there are languages where this form is used for all numbers ending with one (for example https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html#be). That's why it's a good idea to have a consistent definition of the plurals. |
Oh... You have an hard work to support all these locales 👍 Our usage The current implementation works pretty well for the nominal case, so it is important to keep it easy to use. Theses patches updates 2 behaviours :
Example of usage In our ruby code, we will write : I18n.t('controllers.users.show_count', count: User.count) With weblate like today, the en.yml could contains: en:
controllers:
users:
show_count:
one: '%{count} user confirmed its account'.
other: '%{count} users confirmed their accounts.' If User.count = 0, the resulting string is `0 user confirmed its account' But, Ruby On Rails allows to write: en:
controllers:
users:
show_count:
zero: 'Nobody registred at this time'
one: 'One user confirmed its account'.
other: '%{count} users confirmed their accounts.' In this case, the 'zero' key is not required by CLDR since '0' and '1' quantifier uses the same plural form. It use usefull to write a more natural text. Some ideas for a generic implementation Configuration elements could be :
I think that storage options should be customizable on a "per project and format" basis. Considering your example with 'one' defined as any number ending with '1', the default configuration (without zero) could be:
If the customer need to support the zero, it could change the settings to look like:
And finally, in the locale configuration, we could mark 'zero' as optional. In weblate, it would allow to translate a key even when 'zero' is not in the source. In translate, it would export the file without the 'zero' key and let the software gracefully fallbacks to 'one' or 'other' key. This covers our needs, but I haven't enough experience with other locales to understand all implications. I hope this will help you :-) |
Okay, so this is specific to Ruby i18n module and applies only to the
To address this behavior properly in Weblate following changes would be needed:
Given that it looks like a complex change, I'm not sure it's worth of the effort... |
The issue you've reported needs to be addressed in the translate-toolkit. Please file the issue there and do not forget to include links to any relevant specifications about the formats (if applicable). |
This issue has been added to the backlog. It is not scheduled on our roadmap, but it eventually might be implemented. In case you desperately need this feature, please consider helping or funding the development. |
Describe the bug
I changed the plural count and formula of French to support the 'zero' case.
Then, I load the following rails i18n file:
The first key
successful_key
is successfully parsed. But the second keyfailing_key
like if the input was :I other words, if the 'zero' key is missing, the 'one' key will be used for the plural form
n = 0
.To Reproduce
Expected behavior
If the zero key was missing during import, it should not corrupt other plural form.
Rails supports that the zero key is missing, so we only set it when necessary.
Screenshots
Server configuration and status
The text was updated successfully, but these errors were encountered: