-
Notifications
You must be signed in to change notification settings - Fork 45
Language Name Liquid Tag
As a special liquid tag, the plugin includes tl
which prints the label of a specific language in the translation of the language that is currently being rendered.
{% tl language_name_expression %}
The first and only argument, language_name_expression
, is an expression evaluating to the language name string of the language for which the label is being printed. This can be a quoted string directly evaluating to the key or a liquid variable whose contents evaluate to the language key.
This liquid filter requires a lang
subset for each language that it is being used with. This specific subset contains labels for each language that this liquid tag is being used for.
Here is the lang
subset for the English and German languages which can be complemented by other languages as well:
---
en:
lang:
en: English
de: German
de:
lang:
en: Englisch
de: Deutsch
This is very straight forward:
{% tl 'en' %}
Since the plugin does not know which languages it is supporting, an array of languages needs to be added to the configuration _config.yml
:
languages: ['en', 'de']
With this array, we can iterate over all supported languages and print out links with labels allowing the user to switch between languages easily:
<ul>
{% for language in site.languages %}
<li>
{% if page.language == language %}
<a class="active" title="{% tl language %}">{% tl language %}</a>
{% else %}
<a href="{{ site.baseurl }}/{{ language }}/" title="{% tl language %}">{% tl language %}</a>
{% endif %}
</li>
{% endfor %}
</ul>