Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.04 KB

i18n.md

File metadata and controls

48 lines (32 loc) · 1.04 KB

i18n

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

Usage in code

  • 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>
}

Extract keys to JSON files

npm run i18n:extract-keys

NOTE: all string literal arguments from _() and t() functions will extracts

Testing

  • all spec|testing files ignored when extract keys
  • we enable cimode when testing that will cause the t function to always return the key