any way to change namespace like i18n.changeLanguage("en") ?
Hi, is there any way to change the namespace like i18n.changeLanguage("en")
E.g.
i18n.changeNamespace("blue-theme");
no need for that:
you can do i18next.t('namespace:key') to get a key from another namespace
when using the translate hoc or I18n render prop you get a t function set to the first namespace passed in: https://react.i18next.com/components/translate-hoc.html or https://react.i18next.com/components/i18n-render-prop.html
<I18n ns={['defaultNamespace', 'anotherNamespace']}>
{
(t, { i18n, t, ready }) => (
// t will return keys of 'defaultNamespace
)
}
</I18n>
you also can use: https://www.i18next.com/api.html#getfixedt to get a fixed t function
thanks @jamuhl, i'll give that a go
If you need to set namespace based on a per customer base (client subdomain) -> correctly that is done by using a language in form lng-script-Region-x-customerId eg. en-x-github. -x- is the marker for custom language variation.
There is also setDefaultNamespace which changes the default namespace obviously.
@veelenga
- default -> used as default
- useTranslation -> gets a t function bound to the namespace passed
- getFixedT -> create a t function bound to a namespace
- prepend namespace in from of key to use that namespace
t(ns:key)
https://www.i18next.com/overview/api#setdefaultnamespace