[Migration to v4] Lazy plural? #1729
-
Hello, While migrating to v4, I noticed some logic in our code that calls Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
it's better to wrap it in a function and use as usual: import {plural} from `@lingui/macro`
const eggs = 5;
// ❌ bad, because in non re-executing context
const myMessage = plural(eggs, {one: "# egg", other: "# eggs"})
// ✅ good, wrapped in a function
function getMyMessage(eggs: number) {
return plural(eggs, {one: "# egg", other: "# eggs"})
} // ❗️ Advanced, not recommended
const myPluralMsgDescriptor = msg`Wolf has ${count, plural({one: "# egg", other: "# eggs"})}`
// then somewhere in presentation
i18n._(myPluralMsgDescriptor.id, {count}); // name of the variable should match with definition! Also you could write plural ICU expression by hand: const myPluralMsgDescriptor = msg`Wolf has {plural, count, one {# egg} other {# eggs}}`
// then somewhere in presentation
i18n._(myPluralMsgDescriptor.id, {count}); // name of the variable should match with definition! |
Beta Was this translation helpful? Give feedback.
-
Hello again, 2 years later :) We upgraded from v3 to v5 and I found the problem. It was as simple as the following (it doesn't look like it is in the breaking changes?) In the lingui config: - "runtimeConfigModule": ["src/common/translations/i18n"],
+ "runtimeConfigModule": ["src/common/translations/i18n", "i18n"], |
Beta Was this translation helpful? Give feedback.
Hello again, 2 years later :) We upgraded from v3 to v5 and I found the problem. It was as simple as the following (it doesn't look like it is in the breaking changes?)
In the lingui config: