Translation in Mapbender¶
Mapbender uses the translator service which is a Symfony component. You get more information at the Symfony Translation 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');
yaml-files for translations¶
The translations can be stored in different formats. We use yaml-format for Mapbender.
We use place holder for every text e.g. mb.core.featureinfo.popup.btn.ok. Like this you can define different translations for the same word which occurs 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.yaml file. The fallback language will be used if you define a language in parameters.yaml that does not exist.
This is how a translation file messages.de.yaml for German translation could look like.
mb:
core:
featureinfo:
error:
nolayer: 'Informationsebene existiert nicht.'
unknownoption: 'Unbekannte Option %key% für %namespace%.%widgetname%.'
noresult: 'kein Ergebnis'
popup:
btn:
ok: Schließen
class:
title: Information
description: Information
tag:
featureinfo: Information
feature: Objekt
info: Info
dialog: Dialog
aboutdialog:
content:
versionprefix: Version
learnmore: 'Lernen Sie Mapbender kennen '
linktitle: 'Besuchen Sie die offizielle Mapbender Webseite.'
website: '- zur Webseite'
.....
Notice: Each time you create a new translation resource you have to clear your cache.
bin/console cache:clear
How can you activate translation?¶
Mapbender is automatically adjusted to your browser’s language. Moreover, you can set fallback language options in the configuration file parameters.yaml. If a translation from your browser’s default language is not translated in Mapbender yet, it will fall back to the predefined language instead. We recommend to set English and/or German as fallback options.
fallback_locale: en
locale: en
Check whether translations (yaml-files) for your language exist
mapbender/src/Mapbender/CoreBundle/Resources/translations/
mapbender/src/Mapbender/ManagerBundle/Resources/translations/
mapbender/src/Mapbender/PrintBundle/Resources/translations/
mapbender/src/Mapbender/WmcBundle/Resources/translations/
mapbender/src/Mapbender/WmsBundle/Resources/translations/
fom/src/FOM/CoreBundle/Resources/translations/
fom/src/FOM/ManagerBundle/Resources/translations/
fom/src/FOM/UserBundle/Resources/translations/
…
Create yaml-files for your language¶
If your language is not translated yet, it is easy to add a new language.
Check the translation directories and create a new file by copying the English locale (messages.en.yaml)
translate
set locale in your parameters.yaml to the new language
clear your cache
adjust your browser language to the translated language - Mapbender will be translated automatically.
if everything is fine with your new language, give the files to the Mapbender community - best would be a pull request on GitHub in the Mapbender repository.
Naming conventions and locations¶
Symfony looks for translation files in the following directories in the following order:
the <kernel root directory>/Resources/translations
the <kernel root directory>/Resources/<bundle name>/translations
Resources/translations/ directory of the bundle.
Bundle translations can overwrite translations of the other directories.
Naming¶
The naming convention is domain.locale.loader.
domain - we use the default domain messages
locale - locale that the translations is made for (e.g. de, de_DE);
loader - defines the loader to load and parse the file. We use YAML.