i18next: Problems with plurals >= 3
Hi! I have some problems with plurals. I’m Russian, and our language has 3 plural forms: single, multiple for x2–x4 except x11–x14, that work like other multiple plurals. And sometimes I need to use parts for text formatting, like <a>
or <mark>
tags around some words. So, I split my text like this:
locales/ru/common.json
{
"SomeTextKey": {
"part0": "Укажите, пожалуйста",
"part1": "не менее",
"part2": "предметов.",
},
"SomeTextKey_0": {
"part0": "Укажите",
"part1": "не менее",
"part2": "предметов.",
},
"SomeTextKey_1": {
"part0": "Укажите",
"part1": "не менее",
"part2": "предмета.",
},
"SomeTextKey_2": {
"part0": "Укажите",
"part1": "не менее",
"part2": "предметов.",
}
}
So, part2
depends on count
.
I use React+ES7 syntax and your react-i18next
plugin, so, in my component, I use this translation like
@translate(['common'])
export default class MyComponent extends React.Component {
render() {
const {
count,
t,
valid,
} = this.props;
return (
<div>
{t('SomeTextKey.part0', { count })}
<mark className={`mark ${valid ? 'mark_no-style' : ''}`}>
{t('SomeTextKey.part1', { count })} {count}
</mark>
{t('SomeTextKey.part2', { count })}
</div>
);
}
}
This should look like: Укажите не менее 0 предметов. Укажите не менее 1 предмета. Укажите не менее 2 предметов. … Укажите не менее 22 предметов.
and so on…
Docs for plurals said that I need only plural keys (0, 1, 2). But this doesn’t work. If I specify the default key, it works, but without plurals, because I get
Укажите, пожалуйста, не менее 1 предметов.
I used word ‘пожалуйста’ to know, if plurals don’t work. And there it is, sadly.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (8 by maintainers)
If i have more time for this. Thanks.
Btw,
t('SomeTextKey.part2', { context: 'plural', count: 1 })
works for now.