toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
646 stars 111 forks source link

Polish and Croatian unable to be translated at version 9.2.0 #531

Open ivailotsvetkov opened 1 year ago

ivailotsvetkov commented 1 year ago

Describe the bug

`/**

[Nest] 46587 - 08/14/2023, 11:42:34 AM ERROR [ExceptionsHandler] template.replace is not a function TypeError: template.replace is not a function at Object.formatter (/Users/ivaylotsvetkov/Projects/awz-owner-property-api/node_modules/string-format/index.js:19:23)

Does anyone know how to resolve?

Reproduction

Version 9.2.0 / either try lang=hr or lang=pl

System Info

Node version >= 18

Used Package Manager

npm

Validations

rubiin commented 1 year ago

could you try the latest package @ivailotsvetkov

toniek commented 11 months ago

I had the same error. In my case, I was missing "other" in the translations. As it turned out, for the "pl" language, the number 7 used the translation for "many," but for "cs," 7 was already "other" - which I didn't have. You can check what is used for a given number in a particular language with the following function:

const pluralRules = (lang, number) => {
    const rules = new Intl.PluralRules(lang);
    return rules.select(number);
}
pluralRules('pl', 7); // return 'many'
pluralRules('cs', 7); // return 'other'

However, I am surprised by the behavior of the translation library. In the case of translations without plurals, if I don't have a key, an error will occur. It should also be the case here. Instead, strange things happen. Object.formatter should receive a string, but it does get an object (replace can only be performed on a string) - which is the direct cause of the error.

jooocy commented 6 months ago

I faced a similar error with version 10.4.5. My JSON template had keys for 'zero' and 'other', but was missing 'one'. Despite expecting 'other' to be used when 'one' was accessed, I encountered the error message template.replace is not a function.

What's peculiar is that this issue only manifested in English; testing in Korean and Japanese didn't reveal the problem.

For now to resolve it, I simply added the 'one' key to the JSON template.