Skip to content
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

Pluralisations quirk will cause fallbacks to English locale #6501

Open
ChrisBAshton opened this issue Mar 30, 2022 · 0 comments
Open

Pluralisations quirk will cause fallbacks to English locale #6501

ChrisBAshton opened this issue Mar 30, 2022 · 0 comments

Comments

@ChrisBAshton
Copy link
Contributor

ChrisBAshton commented Mar 30, 2022

Looking at cy.yml:

      blog_post:
        few:
        many:
        one: Postiad blog
        other: Postiadau blog
        two:
        zero:

If we spin up a Rails console locally, and try out the Rails i18n commands, I think we'll be surprised at the result:

irb(main):003:0> I18n.translate("document.type.blog_post", count: 1, locale: "cy")
=> "Postiad blog"
# So far, so good

irb(main):004:0> I18n.translate("document.type.blog_post", count: 2, locale: "cy")
=> "Blog posts"
# not good!

irb(main):005:0> I18n.translate("document.type.blog_post", count: 3, locale: "cy")
=> "Blog posts"
# still not good!

irb(main):006:0> I18n.translate("document.type.blog_post", count: 0, locale: "cy")

=> "Blog posts"
# still not good!

irb(main):007:0> I18n.translate("document.type.blog_post", count: 5, locale: "cy")
=> "Postiadau blog"
# better

Suggested action

It seems that in languages with the same pluralisation rules as English, we need to duplicate the value for other across the other keys, e.g.

      blog_post:
        few: Postiadau blog
        one: Postiad blog
        other: Postiadau blog
        two: Postiadau blog

This fixes the output:

irb(main):001:0> I18n.translate("document.type.blog_post", count: 2, locale: "cy")
=> "Postiadau blog"
irb(main):002:0> I18n.translate("document.type.blog_post", count: 3, locale: "cy")
=> "Postiadau blog"
irb(main):003:0> I18n.translate("document.type.blog_post", count: 4, locale: "cy")
=> "Postiadau blog"
irb(main):004:0> I18n.translate("document.type.blog_post", count: 10, locale: "cy")
=> "Postiadau blog"
irb(main):005:0> I18n.translate("document.type.blog_post", count: 100000, locale: "cy")
=> "Postiadau blog"

Note that I did try removing the empty keys as per the English version, but it causes runtime errors:

irb(main):001:0> I18n.translate("document.type.blog_post", count: 2, locale: "cy")
Traceback (most recent call last):
       16: from thor (1.2.1) lib/thor/invocation.rb:127:in `invoke_command'
       15: from thor (1.2.1) lib/thor/command.rb:27:in `run'
       14: from railties (6.1.5) lib/rails/commands/console/console_command.rb:102:in `perform'
       13: from railties (6.1.5) lib/rails/commands/console/console_command.rb:19:in `start'
       12: from railties (6.1.5) lib/rails/commands/console/console_command.rb:70:in `start'
       11: from (irb):1
       10: from i18n (1.10.0) lib/i18n.rb:217:in `translate'
        9: from i18n (1.10.0) lib/i18n.rb:217:in `catch'
        8: from i18n (1.10.0) lib/i18n.rb:221:in `block in translate'
        7: from i18n (1.10.0) lib/i18n/backend/fallbacks.rb:47:in `translate'
        6: from i18n (1.10.0) lib/i18n/backend/fallbacks.rb:47:in `each'
        5: from i18n (1.10.0) lib/i18n/backend/fallbacks.rb:49:in `block in translate'
        4: from i18n (1.10.0) lib/i18n/backend/fallbacks.rb:49:in `catch'
        3: from i18n (1.10.0) lib/i18n/backend/fallbacks.rb:50:in `block (2 levels) in translate'
        2: from i18n (1.10.0) lib/i18n/backend/base.rb:50:in `translate'
        1: from i18n (1.10.0) lib/i18n/backend/pluralization.rb:37:in `pluralize'
I18n::InvalidPluralizationData (translation data {:one=>"Postiad blog", :other=>"Postiadau blog"} can not be used with :count => 2. key 'two' is missing.)

I18n.translate("document.type.blog_post", count: 2, locale: "en")
=> "Blog posts"

Thoughts welcome!

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

No branches or pull requests

1 participant