For the complete documentation index, see llms.txt. This page is also available as Markdown.

Resource-Based Translations

Resource-based translations replace the embedded i18n definitions with a Form.io Language resource. Each submission holds one language’s translations, and a controller loads them with form.addLanguage() when a user selects that language. Non-developers can then manage translations without changing the application.

Create a Language Resource

To use resource-based translations, first create a language resource that will contain each language's text terms and corresponding translations. To do so:

  1. Create a Language resource within the Project, called Language.

  2. Within this resource, add a Select Field (typically called "Language") for the Language Code. This maps the plaintext language name to the language identifier.

  3. Within the Select Field's Data tab, set Data Source to Values.

  4. For each language the form is localized to, create a Label identifying the plantext language name, and a Value identifying the language identifier.

    Setting the available languages in a Language Resource.
  5. Add a Data Map to the Language Resource (typically called "Translation"), which contains Text Field that maps the default language text to the translated text, like the following:

The key-value pair in a Translation Resource Data Map.

The completed resource will look like the following:

  1. Press Create Resource button to create the new Resource.

Filling the Language Resource

Once this is created, use the resource to create a new submission for each translation. The following example illustrates the fields for EspaƱol:

Each submission will add the "language". This will be used to manage all of the translations in a standard way. Input the rest of the language translations the same way until there are multiple to choose from.

Language Resource "Read All Submissions" Access

For most applications, the end user will be authenticated when they are switching between languages. In some cases, the user may be anonymous. As with any resource, ensure that the proper Role has access to the Read All Submissions permission within the Access section of the Language form.

Dynamic Language Controller

To allow a user to dynamically switch languages, write the logic that will perform the dynamic language display. The form controller that establishes a dynamic language is straightforwad. It will send an API call to the form resource submission API (where the user has Read All submission access) to fetch the Submission that is associated with the language that was chosen.

Implement some in-memory cache to reduce re-fetching the submissions as the user clicks between different languages.

Put most of the logic within the window.setLanguage method. Here is what the Form Controller should look like:

Here is a JSFiddle demonstrating this dynamic loading system working:

Last updated

Was this helpful?