Open ivailotsvetkov opened 1 year ago
could you try the latest package @ivailotsvetkov
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.
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.
Describe the bug
`/**
features.${key}
, options); }` So we have the following code that translates strings and on version 9.1.10 it works properly, however, if we update the version to 9.2.0 it brakes with.[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
Used Package Manager
npm
Validations