Multi-Language Page

Last updated on June 26, 2024.

This document details the following aspects of a Multi-Language Page:

  • Defaults
  • Switching between languages
  • Simple usage
  • Arrays
  • Parameterisation (variables)
  • Pluralisation

Defaults

English is the default language.

If there is a query param in the URL, it will render the parameter's value. For example,  renders a page in German.

You can also set the language in  , and modify it with the param. Please visit the Context Variable documentation to learn more.

Switching between languages

You can check and set the language to switch using the following code:

Simple usage

To use the feature, at least one translation file must be present.

We will use the page translation key in two languages in this example to demonstrate the mechanism.

app/translations/en.yml

app/translations/pl.yml

Having these two files enables you to use the filter. stands for , and you can use both methods to implement the filter. Please visit our documentation on Insites Liquid Filters for more information.

For example, opening will default to English. Opening will try to use Polish and fall back to English for keys that have yet to be found.

/multilanguage

/multilanguage?language=pl

Arrays

Inside YAML, it is possible to include any data structure that is usable in JSON, including arrays.

Visit json2yaml to learn how YAML will convert to JSON or vice-versa if you feel more comfortable in JSON.

You can use this feature alongside other filters to store collections in a readable form.

app/translations/en.yml

app/translations/jp.yml

Example page

/multilanguage?language=en

/multilanguage?language=jp

Parameterisation (variables)

Sometimes you'll need to translate parts of a sentence but keep others (e.g. names). In these cases, some of the content should be parameterised.

The filter accepts named arguments, and the syntax is available in translation keys.

app/translations/en.yml

app/translations/pl.yml

Example page

/multilanguage?language=en&name=John&url=https://docs.growthgardens.com

/multilanguage?language=pl&name=Pawel&url=https://growthgardens.io

Pluralisation

In many languages — including English — there are only two forms: singular and plural for a given string, e.g. "1 message" and "2 messages". Other languages (Arabic, Japanese, Russian and many more) have different grammar with additional or fewer plural forms. Thus, the provides a flexible pluralisation feature.

The interpolation variable has a unique role in that it is interpolated to the translation and used to pick a pluralisation from the translations according to the pluralisation rules defined in the backend. By default, only the English pluralisation rules are applied.

If you set this to your language file:

Then:

The output rendered is:

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.