Mapbender3 uses the translator service which is a Symfony component. You get more information at the Symfony Translation Documentation and Translator Class Documentation .
In the code you use the function trans to translate a text into another language.
Example how the function trans can be used in a Twig template:
{% block title %}{{ application.title | trans }}{% endblock %}
or
{% trans %}{{ application.title }}{% endtrans %}
Example for PHP:
echo $translator->trans('Hello World');
The translations can be stored in different formats. We use XLIFF-format for Mapbender3. Symfony will take the XLIFF-loader to load and parse the file.
We use place holder for every text. Like this you can define different tranlsation for the same word which accurs in different modules.
We translate the place holder to different languages. English is the default language that we provide. It is also defined as the fallback language in the parameters.yml file. The fallback language wil be used if you define a language in parameters.yml that does not exist.
This is how a translation file messages.de.xliff for german translation could look like.
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="de" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="20bbe30e6fcefd2ab10c780590b458af" resname="mb.core.admin.button.show_label">
<source>mb.core.admin.button.show_label</source>
<target>Beschriftung anzeigen</target>
</trans-unit>
<trans-unit id="7cb565a35d95af70959282faf4989642" resname="mb.manager.admin.element.delete">
<source>mb.manager.admin.element.delete</source>
<target>Element entfernen</target>
</trans-unit>
<trans-unit id="04cd08843fed089f29b6aa525b3380cf" resname="mb.manager.admin.element.delete.confirm">
<source>mb.manager.admin.element.delete.confirm</source>
<target>Wollen Sie ddas Element wirklich löschen?</target>
</trans-unit>
<trans-unit id="8f31981eb7f9c7b4331f1550f0e68b6c" resname="mb.manager.admin.element.btn.delete">
<source>mb.manager.admin.element.btn.delete</source>
<target>Löschen</target>
</trans-unit>
.....
Notice: Each time you create a new translation resource you have to clear your cache.
app/console cache:clear
Activate your default locale in the configuration file app/config/parameters.yml
fallback_locale: en
locale: de
Check whether translations (xliff-files) for your language exist
If your language is not translated yet, it is easy to add a new language.
Symfony looks for translation files in the following directories in the following order:
Bundle translations can overwrite translations of the other directories.
The naming convention is domain.locale.loader.