Closed chinchang closed 5 years ago
@chinchang Good question, you can use the <Text>
component with nested <Text>
components as fields to accomplish this:
+ dictionary.json
{
"fruits": {
"youHave": "You have {{oranges}} and {{bananas}}",
"oranges": {
"none": "no oranges",
"singular": "{{count}} orange",
"plural": "{{count}} oranges"
},
"bananas": {
"none": "no bananas",
"singular": "{{count}} banana",
"plural": "{{count}} bananas"
},
}
};
function HowManyFruits({ orangeCount, bananaCount }) {
return (
<Text
id="fruits.youHave"
fields={{
oranges: <Text id="fruits.oranges" fields={{ count: orangeCount }} plural={orangeCount} />,
bananas: <Text id="fruits.bananas" fields={{ count: bananaCount }} plural={bananaCount} />
}}
/>
);
}
You can play around with this example here: https://jsfiddle.net/kup94zmy/1/
I think that answers the question so I'll close this out, but let me know if this is still an issue.
This is not working for me. I have:
{
editEntity: "Edit '{{entityType}}'",
entities: {
CONS: 'Load'
}
}
<Text id="editEntity" fields={{
entityType: <Text id="entities.CONS" />,
}}
/>
But it results in: Edit '[object Object]'
@donkeyDau Please make sure you are using at least version 1.4.0
for this feature to work.
Can't remember which version I was using when I wrote the comment. Switched to 2.1.2-preactx
and it works like a charm now. Thank you @pl12133 Also for the hooks. It'll relief some pain :)
Have to revert my answer: Still not working with 2.1.2-preactx
in my case ... Output is stil Edit [object Object]
Looks like that is caused by the master
branch being ahead of the preactX
branch, once master
is merged into preactX
this should be resolved.
Alright. I'm looking forward to this merge :)
Let's say I have this string:
You have 2 oranges and 5 bananas
. What do I provide in theplural
prop when I have multiple numeric expressions to pluralize? Examples show passing only 1 value toplural
prop.