mod_translation

This module provides support for dealing with multiple languages.

How content and static strings are translated is explained in full in Translation.

Language as part of the URL

By default, mod_translation prefixes each URL (using URL rewriting) in your website with the code of the current language. The idea behind this is that each language version of a resource gets its own URL, and is as such indexable for Google.

This behaviour is enabled by default, but can be switched off in the admin, by going to Structure, Translation. There is a checkbox labelled “Show the language in the URL”.

Alternatively you can set the config key mod_translation.rewrite_url to false.

Programmatically switching languages

In a template, you can use mod_translation’s postback hook to switch between languages:

{% button text="Dutch" postback={set_language code="nl"} delegate=`mod_translation` %}

Creates a button which switches to Dutch. And another one for english:

{% button text="English" postback={set_language code="en"} delegate=`mod_translation` %}

Supporting right-to-left languages

For basic use you don’t need to do anything. Zotonic base site adds a lang attribute to the html tag, and when a right-to-left language is selected (for instance Arabic), the browser will interpret lang="ar" and automatically adapt the content to right-to-left.

Custom right-to-left content

If you write your own templates, you can add the lang tag in the html or body tag, for instance:

<body {% include "_language_attrs.tpl" id=id %} >

This will generate the following, when Zotonic selected Arabic for the page with id id:

<body xml:lang="ar" lang="ar" dir="rtl" class="rtl">

When you want to add an extra class added to the rtl or ltr class you can use:

<body {% include "_language_attrs.tpl" id=id class="my-body-class" %} >

To create individual right-to-left elements, you can use the same principle:

<div {% include "_language_attrs.tpl" %}></div>

And when you want to force a specific language:

<div {% include "_language_attrs.tpl" language=`en` %} >This is English content</div>

Edit on GitHub

Models

m_translation

The m_translation model gives easy access to language and translation related information.

Controllers

controller_language_set

Controller which sets the language as given in the code argument, and redirects the user back to the page given in the…

Dispatch rules

dispatch_translation

Dispatch rules Name Path Resource Args admin_translation [“admin”,”translation”] controller_admin [{acl_module

Filters

is_rtl

Check if the given language is a rtl or ltr language.

language

Return the language the resource (or translated text) will be displayed in.

language_dir

Return rtl or ltr depening on the direction of the language.

language_sort

Sort a list of language codes or map with languages on their name. Return a list of {Code, LanguageProps} pairs.

set_url_language

Change the language of an URL to another language. Useful to generate alternative URLs for a page.

translate

Translates a (English) value to the current language or the given language.

Referred by

Translation

Many sites need to support content and templates in multiple languages. Luckily, Zotonic is completely multilingual

All dispatch rules

All the dispatch rules from all modules. For a background on dispatch rules, see The URL dispatch system.