FCF 2.0 development in progress...
> > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]


The framework has its own system for translating static strings. It is used in many nodes of the framework. Translation of a static string can be done with the fcf.t() function, which simply returns a string with the translation into the user's language if a translation was found, or the original string if no translation was found. The user's language is specified in the execution context fcf.getContext().language or can be explicitly passed to the fcf.t function as the second argument.

Adding a translation is done by expanding the configuration. Translations are stored in the configuration parameter translations. This configuration setting is an array whose elements can be specified in two ways.

  1. Translation format specified by the object

    The object must have two fields that contain the target language and translations:

    • string language - target language

      object 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 the language property.


      fcf.getConfiguration().append({ translations: [ { language: "ja", translations: { "Hello world": "こんにちは世界", } } ], }); fcf.getContext().language = "ja" console.log(fcf.t("Hello world"));



  2. 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"));