Plural
- To allow automatic plural detection, you will need to pass a
count
parameter to Talkr's translation function. Talkr will then chose the right word or sentence betweenzero
,one
,two
,few
andmany
. - To make it work, make sure to add related keys in your JSON files:
"message-count": {
"zero": "you don't have new messages",
"one": "you have 1 message",
"many": "you have __count__ messages"
}
🤓: Some languages have more complex plural rules, that may require these five options to offer a perfect user experience. For instance, Arabic handle
zero
,one
,two
,numbers between 3 and 10
andnumbers over 10
as separate entities. If a language doesn't need all these subtleties - like english - you can only writezero
,one
andmany
in the JSON file.
import React, { useState } from "react";
import { useT } from "talkr";
export default function MyComponent() {
const { T } = useT();
const [count, setCount] = useState(0);
return (
<>
<h1>{T("message-count", { count })}</h1>
<button onClick={() => setCount(count + 1)}>+1</button>
</>
);
}