New translations mechanism
In Newscoop 4.3 we have introduced a new mechanism for translations.
Major changes:
- Removed Localizer feature. (Replaced with new Symfony2 translation concept.)
- Added event listener to load old plugins translations from directory
../newscoop/newscoop/plugins/
- Translations files are located in ../newscoop/newscoop/src/Newscoop/NewscoopBundle/Resources/translations directory
- Added a new feature for theme implementors to translate strings
Usage in templates:
- old translation tags usage:
{{ #search# }}
- new translation tags usage:
{{ 'search'|translate:'translation_domain':['%variable%' => 'some value'] }}
e.g
{{ 'search'|translate:"null":['%val%' => 2] }}
default domain is set to null so it will be theme_translation
search
value in theme_translation.en.yml
:
search: "You must type at least %val% letters to enable search"
Display result will be:
You must type at least 2 letters to enable search
search
- given text to translatetranslation_domain
- name of translation file, for ex. if our translation file name iscustodian.en.yml
then the translation domain iscustodian
and translation strings will be loaded from that file, if translation domain isn't set ({{ 'search'|translate }}
then default translation domain is used:theme_translation
.
Translation domains allow you to split translations to many files, ex. users.en.yml
, front.en.yml
etc.
- how to use it with global variables:
{{ assign var="welcome" value="{{ 'welcome'|translate }}" }}
and call it: {{ $welcome }}
- new translation directory:
theme_name/translations
Usage for core developers:
-
in Twig files:
variableName - parameter to be displayed in translated string
home - translation domain (e.g. home.en.yml file)where:
-
in Controllers:
- array('%cache%' => $cache_engine) - parameter to be displayed in translated stringwhere:
- system_pref - translation domain (e.g. system_pref.en.yml file)
-
Yaml file structure example
Translation files can be translated using Transifex now, where we keep them all together with plugins strings.
- Newscoop project on Transifex - You can help us translate Newscoop in many languages
- Symfony2 - Translations - More information about Symfony2 translations