next-translate
@opensea/next-translate
provides a useTranslate
hook that returns a translation function that wraps next-translate's t
function to support in-code defaults for plural translation variants and a slightly improved interface for translations without variables.
Getting started
Install
npm install
Usage
import { useTranslate } from '@opensea/next-translate';
const Example = () => {
const t = useTranslate('ns1');
const [count, setCount] = useState(0);
const noVariables = t('example.noVariables', 'No variables');
const plurals = t(
'example.plurals',
{
zero: 'No items',
one: '1 item',
other: '{{count}} items'
},
{ count }
);
const optionalZero = t(
'example.optionalZero',
{ one: '1 item', other: '{{count}} items' },
{ count }
);
};
Local development
Running tests
npm run test