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

Feature: Translation of few/many keys based on the locale #582

Open
marselmustafin opened this issue May 30, 2024 · 6 comments
Open

Feature: Translation of few/many keys based on the locale #582

marselmustafin opened this issue May 30, 2024 · 6 comments

Comments

@marselmustafin
Copy link

marselmustafin commented May 30, 2024

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
Copy link
Collaborator

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
Copy link
Author

@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
Copy link
Collaborator

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

@markedmondson
Copy link

This is something we'd gain from. We currently use Phrase for managing our strings because this is something they support quite well (and a lot of the other "Rails compatible" translation SaaS don't) but the relative cost is high considering we don't use 90% of their other features.

@markedmondson
Copy link

Ok I think I have this "working" at least as a proof of concept.

As per the comments above, it's a little tricky and assumptions have to be made - as a result it probably only works well from en to other languages because I took the approach of using the other key to fill in the missing keys so it would work well with translations. Ultimately, if you're just looking to get the missing keys, that's a lot easier.

I pushed our large application using it through the OpenAI translator and it did a pretty good job at ensuring the correct keys were translated.

I'll push up a branch, there were a bunch of other changes that I made along the way so I'll try and split it up nicely.

@davidwessman davidwessman changed the title Translation of few/many keys Feature: Translation of few/many keys based on the locale Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants