-
Notifications
You must be signed in to change notification settings - Fork 2
Translations and languages
Translations are stored at _data/translations.yml
with the following structure:
slogan:
ca: El proper gran esdeveniment Drupal a Barcelona
en: Next big Drupal event in Barcelona
es: El próximo gran evento Drupal en Barcelona
learn_more:
ca: descobreix més
en: discover more
es: descubre más
To load a translation in any place it is needed to use:
{{ site.data.translations.KEY["LANGUAGE"] }}
For instance, to load catalan version of slogan you need to use
{{ site.data.translations.slogan["ca"] }}
.
In order to write less code the variable T is defined in the main layouts (landing.html and default.html) like:
{% assign T = site.data.translations %}
This definition lets us load translations as follows:
{{ T.slogan["ca"] }}
or using the current_language
{{ T.slogan[current_language] }}
variable or page.language variable
{{ T.slogan[page.language] }}
get-current-language.html in _includes
directoy sets current_language. It parses the url and uses the first element after the base url to detect the language of the site. This element is checked agains site.enabled_languages (from _config.yml
). If the element is not in site.enabled_languages, site default language is provided.
In _config.yml
is defined site.enabled_languages. For instance:
enabled_languages: ["ca", "en", "es"]
The first array item ("ca") is the default language.