json-autotranslate icon indicating copy to clipboard operation
json-autotranslate copied to clipboard

i18next plurals

Open zeljkocurcic opened this issue 3 years ago • 4 comments

Hi @leolabs, first, thank you for this wonderful library, it is really useful for projects that are translated into multiple languages. We are using plurals in our i18next project, something like this:

English:

    "Show older comments_one": "Show {{count}} older comment",
    "Show older comments_other": "Show {{count}} older comments",

Polish:

    "Show older comments_one": "Pokaż {{count}} starszy komentarz",
    "Show older comments_few": "Pokaż {{count}} starsze komentarze",
    "Show older comments_many": "Pokaż {{count}} starszych komentarzy",

As you can see, Polish has different plural forms. When I ran json-autotranslate with -d, it removed all these and added the key with _other as the last entry under the parent key. Is there a way to do it correctly for languages like this or this is something that's not implemented?

zeljkocurcic avatar Jan 25 '22 11:01 zeljkocurcic

Hmm, that's a good question. JSON Autotranslate doesn't have any specific behavior when it comes to plurals. Adding the "_few" and "_many" keys to the English source file could work, although I guess it adds a bit of redundant content since these aren't actually needed in English.

leolabs avatar Jan 28 '22 11:01 leolabs

This could be a workaround. It's not ideal, though, since we have 15ish languages and this form is used only in a few

zeljkocurcic avatar Jan 28 '22 11:01 zeljkocurcic

Yeah, that's a valid concern. Do you have an idea for how JSON Autotranslate could be improved to accomodate for this situation?

leolabs avatar Jan 31 '22 16:01 leolabs

I haven't actually looked at the code, but I guess we could use i18next's plural resolver when we see a key has plural forms in the default language: https://github.com/i18next/i18next/blob/master/src/PluralResolver.js

But what to do with other translation engines supported by json-autotranslate?

zeljkocurcic avatar Feb 03 '22 13:02 zeljkocurcic