Localization is currently available as a Public Beta product and the information contained in this document is subject to change. Some features are not yet implemented and others may be changed before the product is declared as Generally Available. Public Beta products are not covered by a SLA.
Use this guide to localize your plugins so they display in the same language as the native Flex UI when a user changes their language setting.
To render plugin text in a different language, follow these steps:
This guide assumes your plugin uses a file structure similar to this:
PluginName
src
components
: directory that contains your plugin components.locales
: directory that contains your localization files.
es-MX.js
: file that contains the localized strings for Español (México).en-US.js
: file that contains the localized strings for English (US).pt-BR.js
: file that contains the localized strings for Português (Brasil).index.ts
PluginName.ts
: file that contains the plugin code, including the code to read Flex's locale setting.locales
directory, add a file for each supported language.The code samples below show an example string for Español (México) and for English (US), respectively.
1export const mexicanSpanishStrings = {2WelcomeButton: "Bienvenido"3};
1export const usEnglishStrings = {2WelcomeButton: "Welcome"3};
Your plugin can read Flex's current locale setting from the manager
object at manager.localization.localeTag
. The localeTag
property defines the IETF (Internet Engineering Task Force) language tag of the current UI locale. For example, en-US
.
To read Flex's current locale:
localeTag
value.1// Read Flex's locale setting2const localeTag = manager.localization.localeTag; // e.g. "en-US"3// Conditionally apply the relevant strings4switch (localeTag) {5case "en-US":6manager.strings = {...usEnglishStrings, ...manager.strings }7break;8case "es-MX":9manager.strings = {...mexicanSpanishStrings, ...manager.strings }10break;11}
availableLocales
: the list of locales the user sees when setting their language. Currently, this list is read-only.setLocalePreference
: a method to save the user's locale preference without using the native language selector. You can use this for implementing a custom locale selection widget.In the definition for each component, add the custom string label you defined to localize that component. For example, step 1 shows how to define a string for WelcomeButton
, and the code sample below shows how to add that string to the WelcomeButton
component.
1// Use your localized strings in a component2const WelcomeButton = ({strings}) => (<Button>{strings.WelcomeButton}</Button>));3...4<WelcomeButton strings={customStrings}/>
This lets Flex show the locale-specific string based on the current UI locale.