Translations
Adding a translation is done by expanding the configuration. Translations are stored in the configuration parameter
-
Translation format specified by the object
The object must have two fields that contain the target language and translations:
-
string language - target languageobject translations - Translation object. The key is the string to be translated, and the value is a string containing the translation into the language specified in thelanguage property.Example:
fcf.getConfiguration().
append ({ translations: [ { language: "ja", translations: { "Hello world": "こんにちは世界", } } ], }); fcf.getContext().language = "ja" console.log(fcf.t("Hello world"));Output:
こんにちは世界
-
-
Array element given by file path
Translations can be supplied from a JSON file. In this case, the array element of the translations configuration parameter must be set to the string, which must contain the path to this file in FCF notation, since the file can be loaded both from the server side and from the browser side.
The format of the translation file may be in the format of a translation object, as described earlier, or may be an array containing objects with information about translations.
:translations/translations.json file
{ language: "ja", translations: { "Hello world": "こんにちは世界", } }
Execution example:
fcf.getConfiguration().
append ({ translations: [":translations/translations.json"], }); fcf.getContext().language = "ja" console.log(fcf.t("Hello world"));Output:
こんにちは世界