Localized
Occasionally, we want to have the option to add multiple languages in one input text field. This means that you can store Dutch, French or English text in one field and the right language will appear based upon the language you chose in the environment (called user language).
Make the field localized
Add the localized:true
attribute to a text input, adding the localized
attribute to any other input types will throw a liquid error.
For example:
{% input custom.some.thing localized:true %}
{% input custom.some.thing as:text localized:true %}
To print the localized variable:, you can use the filter | localized
:
{{ custom.some.thing | localized }}
Specifications
Adding localized:true
to an input field ensures that a suffix is added to the variable name. This suffix follows the locale
, which is toggled by selecting different user languages.
For instance, when selecting Dutch as user language _nl
is added after the variable. In our example, custom.some.thing
becomes custom.some.thing_nl
.
Due to adding the suffix in the background you should always assign the localized field to a local variable when using the localized field in further logic. If not, you will still look for the local variable without the suffix.
{% assign localized_field = custom.some.thing | localized %}
Access a localized value
The value entered in a localized field will be pushed through to every language. This is called the fallback procedure.
Therefor, custom.some.thing_nl
, custom.some.thing_fr
, custom.some.thing_en
, ... will all have the same original entered value out of one language.
This value is stored in the variable where the input text is originally entered and added as a default for the other variables. So, deleting in one language without confirming in the other will make the default disappear in all languages.
Due to the fallback procedure, you should always keep a fallback to the default or to the unlocalized variable when calling the result of the localized
variable (think fi. when the field has already been filled in before adding the localized logic).
When you assign the localized variable, you have to make sure that the localized filter is directly after the custom and not after the default. Otherwise, liquid will try to localize the default and this will throw a liquid error.
{% assign localized_field = custom.some.thing | *localized* %}
{% result 'result_localized_field' localized_field %}
{% assign note_title = period.reconciliations.vkt_6_5.results.result_localized_field %}
Updated over 2 years ago