Translate-plugin: Can I change template with selected language condition?

Created on 16 Oct 2016  路  2Comments  路  Source: rainlab/translate-plugin

Hello, straight to action:

Is it possible to use {% if %} tag to change template based on current language?
Something like

{% if lang="es" %}
    {% component 'componentEs' %}
{% else %}
    {% component 'componentEn' %}
<% endif %>

That could help a lot with some components/plugins.

Question

Most helpful comment

"activeLocale" variable provides current language.

For example:

{% if activeLocale == 'es' %}
   Current language is "es"
{% else %}
   Current language is "{{ activeLocale }}"
{% endif %}

All 2 comments

"activeLocale" variable provides current language.

For example:

{% if activeLocale == 'es' %}
   Current language is "es"
{% else %}
   Current language is "{{ activeLocale }}"
{% endif %}

If you are using the LocalePicker component on the page, it will inject the activeLocale variable already. Otherwise you can inject it yourself in the page/layout code with:

$this['activeLocale'] = Lang::getLocale();
Was this page helpful?
0 / 5 - 0 ratings