Skip to content

Localization

The Cloudrexx localization system provides a robust solution for creating and managing multilingual content as well as localized interfaces.

Architectural Overview

The localization system revolves around the following key entities:

Language Entity

The \Cx\Core\Locale\Model\Entity\Language entity represents a language and its corresponding ISO 639-1 (Language::$iso1) and ISO 639-3 (Language::$iso3) codes.
Language entities that provide Interface Texts have the property Language::$source set to true and are mapped through Language::$localeRelatedBySourceLanguages by Locale entities using it as Locale::$sourceLanguage.
Language entities that are installed in the Backend have an association to a Backend entity (through Language::$backend).
Language entities that are used in the Frontend are associated to Locale entities (through Language::$localeRelatedByIso1s).

Backend Entity

The \Cx\Core\Locale\Model\Entity\Backend entity represents an installed Language (referenced through Backend::$iso1) of the Backend.

Locale Entity

The \Cx\Core\Locale\Model\Entity\Locale entity represents an installed locale of the Frontend which is specificed as a Language-Country combination.

Language

The associated Language entity (which is mandatory for every Locale) is represented by Locale::$iso1.

Country

The associated Country entity (which is optional) is represented by Locale::$country.

Source

Aside from the associated Language entity, each locale is assigned a second Language entity as its $sourceLanguage property. The source language refers to the localization set used for Interface Texts.

Label

By default the label (Locale::$label) of a locale is autogenerated based on its Language-Country combination.
However it can be overwritten using Locale::setLabel().

Examples for autogenerated labels (if not set manually)

The following combinations show the generated labels:

Language Country Label
German Switzerland Schweiz (Deutsch)
French Canada Canada (français)
Arabic Morocco المغرب (العربية)

Fallback

For each Locale a Fallback Locale can be defined (as Locale::$fallback). The Fallback Locale should be used by Components for autogenerated translation of missing localized data.
A Fallback Locale is represented as an other already existing Locale.

Frontend

Each Locale entity is mapped by one or more \Cx\Core\View\Model\Entity\Frontend entities.

Translation Entity

The entity \Cx\Core\Locale\Model\Entity\Translation is used to store the localized data of localized Doctrine entities.

Implementation Examples

Here are some common usage scenarios when working with the Cloudrexx localization system:

Add a new locale

$language = $this->cx->getDb()->getEntityManager()->getRepository(
    \Cx\Core\Locale\Model\Entity\Language::class
)->findOneBy(['iso1' => 'en']);
$locale = new \Cx\Core\Locale\Model\Entity\Locale();
$locale->setIso1($language);
$locale->setLabel('English');
$locale->setOrderNo(1);
$locale->setSourceLanguage($language);
$this->cx->getDb()->getEntityManager()->persist($locale);
$this->cx->getDb()->getEntityManager()->flush();

Retrieving a locale by language and country

$language = $this->cx->getDb()->getEntityManager()->getRepository(
    \Cx\Core\Locale\Model\Entity\Language::class
)->findOneBy(['iso1' => 'de']);
$country = $this->cx->getDb()->getEntityManager()->getRepository(
    \Cx\Core\Country\Model\Entity\Country::class
)->findOneBy(['alpha2' => 'CH']);
$locale = $this->cx->getDb()->getEntityManager()->getRepository(
    \Cx\Core\Locale\Model\Entity\Locale::class
)->findOneBy(
    ['iso1' => $language, 'country' => $country]
);