Translations, locales and right-to-left
This page is for developers who translate an application with message catalogues and format dates and numbers by locale. Exponential separates two things that frameworks often mix: the interface (texts in templates and PHP, translated with catalogues) and the content (translated by editors, each object version holding one set of values per language).
Contents
- Interface texts
- Locales and formatting
- Content in several languages
- Right-to-left
- Compared with other frameworks
Interface texts
| Where | How |
|---|---|
| Templates | {'Latest items'|i18n( 'extension/expdemo' )}; placeholders: {'%count items'|i18n( 'extension/expdemo',, hash( '%count', $count ) )} |
| PHP | ezpI18n::tr( 'extension/expdemo', 'Latest items' ) (kernel/common/ezpi18n.php) |
| Catalogues | extension/<ext>/translations/<locale>/translation.ts, Qt Linguist XML; the kernel's in share/translations/<locale>/translation.ts |
| Registration | site.ini [RegionalSettings] TranslationExtensions[]=<ext> |
The first argument is the context, which groups strings the way a translation domain does. The source text is the
key, as in gettext (View results: translated texts,
i18n operator, Translation catalogues).
The interface language of a siteaccess is site.ini [RegionalSettings] Locale.
Locales and formatting
Locales are INI files in share/locale/ (eng-GB.ini, ger-DE.ini, ara-SA.ini ...), read by eZLocale. They hold
date, time, number and currency formats and the text direction. Templates format with the locale operators
l10n, datetime and locale (Dates, numbers and l10n):
{$node.object.published|l10n( 'shortdate' )}
{$price|l10n( 'currency' )}Locale codes are the three-letter language plus country form (eng-US, ger-DE), not en_US; the standard page
explains how they relate to BCP 47 tags (Language tags).
Content in several languages
- Each content object can be translated into the languages of the installation; every version holds one set of attribute values per language. Editors translate in the administration; there is no translation table to design.
- A siteaccess shows content in the languages of
site.ini [RegionalSettings] SiteLanguageList[], in order, falling back to the next one (Content languages). - A typical multilingual site uses one siteaccess per language, matched by path or host (Siteaccesses, Multilingual sites).
- URL aliases exist per translation (Pretty URLs).
- In PHP,
$object->fetchDataMap( false, 'ger-DE' )reads one language.
Right-to-left
The direction comes only from the locale file ([LanguageSettings] TextDirection=rtl); eZLocale::isRightToLeft() and
eZLocale::textDirectionOf( 'heb-IL' ) answer it in PHP, and $site.text_direction in templates. Print it on <html>
in your pagelayout:
<html lang="{$site.http_equiv.Content-language|wash}"{if eq( first_set( $site.text_direction, 'ltr' ), 'rtl' )} dir="rtl"{/if}>Write stylesheets with logical properties (margin-inline-start, text-align: start) so one stylesheet serves both
directions (Right-to-left sites,
Right-to-left languages in the administration).
Compared with other frameworks
| Framework | Interface strings | Content translations | Exponential |
|---|---|---|---|
| Symfony | Translation component, XLIFF or YAML | separate bundles | .ts catalogues; translations built into content |
| Laravel | lang/ files, __() | packages | the same |
| Django | gettext .po, gettext() | packages such as model translation apps | the same |
| Rails | I18n YAML, t() | gems | the same |
| Spring | MessageSource, properties | your own design | the same |
Related pages
- Internationalization standard
- Translations and languages
- Languages
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.