The project that's using the agent-ui can dictate which locale to use in our components. Below is an example of how to achieve this from an app that's also using `i18next` to handle localization.
npm install cobrowse-agent-uiThe project that's using the agent-ui can dictate which locale to use in our components. Below is an example of how to
achieve this from an app that's also using i18next to handle localization.
``js
// i18n.js
import i18n from 'i18next';
import { i18n as i18nAgentUI } from 'cobrowse-agent-ui';
i18n.init({
// ...
});
i18n.on('languageChanged', (language) => {
i18nAgentUI.changeLanguage(language);
});
export default i18n;
`
To add a new locale follow these steps:
- Add a new entry to the locales array inside i18next-parser.config.js.npm run i18n
- Run the command to generate a new locale file.lib/i18n.js
- Import the new locale JSON file inside and add it to the resources object (in the i18n instancedate-fns
configuration) keyed by the locale key.
- Import the relevant locale inside lib/i18n.js.SUPPORTED_LOCALES
- Add a new entry to the constant inside lib/i18n.js`.
Note: ensure the locale code matches the ones provided by the
date-fns library as these are used to localize dates as well.