🌐Internationalization
Setup
// Import our translation API
import { useTranslation } from '@toeverything/datasource/i18n';
// src/resources/en.json
// {
// 'Text': 'some text',
// 'Switch to language': 'Switch to {{language}}', // <- you can interpolation by curly brackets
// };
const App = () => {
// Define a variable for our translation function
const { t } = useTranslation();
// This function allows for i18n on the page - updating the keys to the selected langauge
const changeLanguage = (language: string) => {
i18n.changeLanguage(language);
};
return (
<div>
// This usees our t function to display the 'text' key.
<div>{t('Text')}</div>
// These buttons change the current active language
<button onClick={() => changeLanguage('en')}>
{t('Switch to language', { language: 'en' })}
</button>
<button onClick={() => changeLanguage('zh-Hans')}>
{t('Switch to language', { language: 'zh-Hans' })}
</button>
</div>
);
};Updating keys

Last updated
Was this helpful?