When parts of a template need to vary by language or country, conditional logic based on the store's country and language can be defined instead of creating multiple templates.
The store's language is represented by its two-character ISO 639-1 code, whereas the country is represented by the two-character ISO 3166-1 alpha-2 code.
Please note the country codes are always in upper case, while the language codes are always in lower case.
Language-based content
To display a piece of content or HTML code for the English language only, the following syntax is available.
{% if receipt.language_code in ['en'] %}
Content for English
{% endif %}
{% if receipt.language_code in ['fr'] %}
Content for French
{% endif %}
Multiple language codes can be defined. They need to be delimited with apostrophes and separated by commas.
{% if receipt.language_code in ['de', 'nl'] %}
Content for German and Dutch
{% endif %}
It is also possible to define content for all other languages using the else statement.
{% if receipt.language_code in ['de', 'nl'] %}
Content for German and Dutch
{% else %}
Content for all languages apart from German and Dutch
{% endif %}
If content is required by all languages apart from a number of them, the following syntax can be used instead.
{% if receipt.language_code not in ['de', 'nl'] %}
Content for all languages apart from German and Dutch
{% endif %}
Country-based content
Analogically, content can be filtered by country:
{% if receipt.country_code in ['GB'] %}
Content for the UK
{% endif %}
Language and country-based media
Both the country code and language code can be printed anywhere in the template with {{receipt.country_code}} and {{receipt.language_code}} statements respectively.
This can be used to easily specify language and/or country based imagery. For example, the code below will refer to icon_en.png, icon_fr.png, and so on, based on the language.
<img src="icon_{{language_code}}.png" />