Localizing Archibus Workplace
The Workplace self-service app uses LocaleContext
to apply localized text to strings in the app. Archibus Workplace uses the same localization files as the Web Central applications. The localized strings are located in the ./ab-core/controls/lang/ui-controls-lang-xx.js files. The Workplace LocaleContext
reads the values in these files and loads the localized strings in memory.
The strings are retrieved from the LocaleContext
using the _L
function.
Example: Using a Localized String in Code
const localeState = useLocalState();
const YES = _L({key: 'Yes', localeState})
The above example gets the localeState
using the useLocaleState
hook.
The localeState
contains all of the localized stings used in Workplace.
The _L
function returns the localized string having the key value of 'Yes'.
Tagging Strings for Localization
Use the _L
function and localeState
to indicate that a string is localized
- Tag the string using the
_L
function - The key property should be unique. Typically the English word can be used for the key property.
The _L
function returns the key value if a localized string is not found for the provided language code.
Example: Tagging Strings
const workplaceText = _L({key: 'Workplace', localeState});// The workplaceText variable can be used in code
<p>{workplaceText}</>
Extracting Strings for Use with the Archibus Localization Kit
Strings that are tagged for localization in Workplace will need to be extracted to be used with the Archibus Localization Kit. Complete the following steps to perform the extraction.
- Execute the command
yarn extractlocalizedstrings
from the Workplace project root folder. - This command generates the file ./ab-core/controls/ab-essential-strings.js.
- The
ab-essential-strings.js
file is used by the Archibus localization kit to identify the strings that require localization. - Perform the standard Archibus localization process. The output of this process with result in the Workplace strings being included in the
ui-controls-lang-xx.js
files.
Note: The extractlocalizedstrings
script is also executed when the yarn build script is executed.