Key notes
- Just i18next used without i18next-react wrapper
- Language change lead to full page reload. This reduce runtime performance due to we no need to use hook keep sync current language
- In component template
import { t } from 'modules/core/i18n'
export const MyComponent: React.FC = () => {
return <h1>{t('namespace:dot.separated.translation.key')}</h1>
}
- Translation keys in global constants
import { t, _, I18nKey } from 'modules/core/i18n'
const TRANSLATION_BY_ROLE = Record<'admin' | 'user', I18nKey> = {
admin: _('ns:role.admin'),
user: _('ns:role.user'),
}
export const MyComponent: React.FC = () => {
return <h1>{t(TRANSLATION_BY_ROLE.admin)}</h1>
}
npm run i18n:extract-keys
NOTE: all string literal arguments from
_()
andt()
functions will extracts
- all
spec|testing
files ignored when extract keys - we enable
cimode
when testing that will cause thet
function to always return the key