[Migration to v4] Lazy plural? #1729
Unanswered
Minishlink
asked this question in
Q&A
Replies: 1 comment 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.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
While migrating to v4, I noticed some logic in our code that calls
plural
outside a react component, making it incompatible with v4. Witht
, you can workaround this withmsg
. What aboutplural
?Thanks
Beta Was this translation helpful? Give feedback.
All reactions