I’m having trouble getting i18next to work with react-i18next and i18next-parser.
In my source code, I have something like:
<p>{t('{{count}} Sensors', { count: getSensorCount() })}</p>
where getSensorCount()
returns a number.
My i18next-parser config is as follows:
{
locales: ['en', 'fr', 'es'],
output: 'src/locales/$LOCALE/$NAMESPACE.json',
defaultValue: (locale, namespace, key, value) => value || key,
keySeparator: false,
namespaceSeparator: false,
verbose: true,
createOldCatalogs: false
}
Running the parser generates a JSON file with the keys like:
{
...
"{{count}} Sensors_one": "{{count}} Sensors",
"{{count}} Sensors_other": "{{count}} Sensors",
...
}
I expect this to return “1 Sensor” when count
is 1. This is also how the i18next documentation describes plurals to work.
However, it just returns the key, and it seems like it is unable to find the translation in the JSON file.
The only way I can get it to return the proper value is if I change the keys like this:
"{{count}} Sensors": "{{count}} Sensor",
"{{count}} Sensors_plural": "{{count}} Sensors",
I’m trying to understand the proper syntax for plural keys and how to configure my project to recognize it. My package versions are:
"i18next": "^20.6.1",
"i18next-parser": "^8.0.0",
"react-i18next": "^13.0.0",
"react": "^18.2.0",
A Codesandbox example of my project is available.
Can someone please help me determine the proper syntax for plural keys and how to configure my project and parser accordingly?