glebm / i18n-tasks

Manage translation and localization with static analysis, for Ruby i18n
http://glebm.github.io/i18n-tasks
MIT License
2.05k stars 257 forks source link

Translation of few/many keys #582

Open marselmustafin opened 1 month ago

marselmustafin commented 1 month ago

I have such keys in my base en locale:

    friends:
      one: one friend
      other: "${count} friends"
      zero: no friends

When I translate it to other languages with translate-missing I have the same keys everywhere. E.g. in Russian:

    friends:
      one: один друг
      other: "%{count} друзей"
      zero: нет друзей

But I would like to have more values included in locales that require more pluralization keys, expected result for Russian:

    friends:
      one: один друг
      few: "%{count} друга"
      many: "%{count} друзей"
      other: "%{count} друзей"
      zero: нет друзей

Is it possible to achieve this result currently? Or it requires additional feature implementation?

davidwessman commented 1 month ago

I do not think there is any such behaviour available today. It will only translate the missing keys. Do you think any translation API supports something like this? E.g. returning all the needed pluralisation keys based on one key?

marselmustafin commented 4 weeks ago

@davidwessman no, I never faced with such ready-made API. We have been using Lokalise for a long time and they provided us with these keys, but afaik they use real people for that.

In i18n-tasks project there's a plural mode exists for missing task which shows all missed plural keys for non-en locales like ar, ru, etc. But translate-missing provides only 1-to-1 keys translation. Even adding of few/many keys to en didn't help because the translation engine google/openai is not aware of context of the number and it gives wrong translation.

I think it would be awesome to upgrade translate-missing task to add translations for plurals as well. As an idea we could pass some number related to the key like few: 2, many: 5 to the translation request and then replace it with %{count} again.

davidwessman commented 4 weeks ago

Yes, that would be interesting to try out. Send translate for multiple plural-keys and see if they are different

davidwessman commented 3 weeks ago

Seems like it would be pretty complex rules to set this up: https://guides.rubyonrails.org/i18n.html#locale-specific-rules https://cldr.unicode.org/index/cldr-spec/plural-rules https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html