React Localization
React supports localization of applications into different languages through the use of i18n. This example below will walk through how to add support for the language, Kannada. These steps can be applied to a language that fits your desired requirements.
Localize the Strings¶
-
Navigate to the
ui-toolkit-react/src/public/locales/
directory. -
Create a new
kn/
directory within theui-toolkit-react/src/public/locales/
directory.The directory name must match one of the codes listed.
-
Copy the
translation.json
file in the/locales/en/
directory to the new/locales/kn/
language directory. -
Translate the strings in the copied
translation.json
file to the new language. -
Save and close the file.
Add to Bundle¶
-
Open the
i18n.ts
file in theui-toolkit-react/src/public/
directory. -
Import the new
public/locales/kn/translation.json
file.import i18n from 'i18next' import LanguageDetector from 'i18next-browser-languagedetector' import { initReactI18next } from 'react-i18next' import translationEN from './public/locales/en/translation.json' import translationKN from './public/locales/kn/translation.json' ...
-
Edit the
resources
const to include the new translation.... import translationEN from './public/locales/en/translation.json' import translationKN from './public/locales/kn/translation.json'; const resources = { en: { translations: translationEN }, kn: { translations: translationKN } }; ...
-
Save the file.
-
Rebuild and generate a new bundle before testing the changes.
Language can be changed in the browser under language section of the browser settings. English is the default language if no customized translation file is provided for an alternative language.
Get Localized Strings for Web Consoles with Localization Enabled¶
If your web console already has localization enabled, make sure to add the translations of the UI-controls into your web console's translations file.