If your implementation supports multiple locales, you can localize your custom editors.
You can create resource property files for each locale for storing localized strings.
Each
resource property file name must follow this format:
Resources_<locale>.properties
where
<locale>
is the ISO language code. For example
Resources_fr.properties
indicates that French values
are stored in it. Place these files in a locales folder for your custom editor:
<app dir>\config\import\editors\<editor
name>\locales
or
<app dir>\config\import\editors\custom\<editor
name>\locales
.
Here is an example of the contents of the
Resources_en.properties
file in the under
<app
dir>/config/import/editors/custom/StringEditor/locales
directory.
... sample.message = This message is loaded from resource bundle error.message.summary = Incorrect format for the input text error.message.detail = Value must match this pattern: {0} ...
Your custom editor obtains localized content using the jQuery.i18n.properties plugin to retrieve the content from the resource properties file.
When a custom editor has property-based resource bundles in it's
locales folder, the system loads the bundle corresponding to the Workbench
user's locale during editor instantiation and makes the localized content
available in a data attribute,
editorBundle
, defined within the editor instance.
This bundle provides a method,
getMessage(resourceKey, arguments...)
, to load
localized text.
To retrieve localized content from resource properties files, follow these steps
Load localized messages for the custom editor, using the following syntax in your
editor.js
:var message1 = this.editorBundle.getMessage('<resource-key-to-localized-message>'); // Loading a parameterized message. var message2 = this.editorBundle.getMessage('<resource-key-to-localized-message>', <param1>, <param2>);
For example:
var message1 = this.editorBundle.getMessage('error.message.summary'); // Loading a parameterized message. var message2 = this.editorBundle.getMessage('error.message.detail', '[a-b0-9]\{6}');
Load localized messages for the custom editor, use the following syntax in your
editor.html:
<label data-bind="text: editorBundle.getMessage('editor.proeprty.label')"/> // Loading a parameterized message. <span data-bind="text: editorBundle.getMessage('error.message.detail', '[a-b0-9]\{6}')"/>