By hand: translating an extension
Tutorial 20. Every text of mysite_hello went through i18n or ezpI18n::tr() with the context
extension/mysite_hello. Now you add German. With the files below and the extension registered,
ezpI18n::tr( 'extension/mysite_hello', 'Hello, %name!', null, array( '%name' => 'Ada' ) ) returned Hallo, Ada! for
the locale ger-DE.
1. Collect the texts
grep -rhoE "'[^']+'\|i18n\( 'extension/mysite_hello'" extension/mysite_hello/design | sort -u
grep -rhoE "ezpI18n::tr\( 'extension/mysite_hello', '[^']+'" extension/mysite_hello --include=*.php | sort -uEach line is one source text of the context.
2. The German file
extension/mysite_hello/translations/ger-DE/translation.ts:
<TS version="2.0" language="de_DE">
<context>
<name>extension/mysite_hello</name>
<message>
<source>Hello, %name!</source>
<translation>Hallo, %name!</translation>
</message>
<message>
<source>Newest articles</source>
<translation>Neueste Artikel</translation>
</message>
<message>
<source>Compose a greeting</source>
<translation>Einen Gruß verfassen</translation>
</message>
</context>
</TS>The source must match the text in the code exactly, placeholders included. Add every text; a missing one shows in
English.
Keep translations/untranslated/translation.ts with the same source lines and empty <translation type="unfinished"></translation>
elements, as a template for the next translator.
3. Check and register
xmllint --noout extension/mysite_hello/translations/ger-DE/translation.tsIn extension/mysite_hello/settings/site.ini.append.php:
[RegionalSettings]
TranslationExtensions[]=mysite_helloThen:
php bin/php/ezcache.php --clear-id=translation
php bin/php/ezcache.php --clear-tag=ini4. See it
Open /hello/world/Ada in a siteaccess whose Locale is ger-DE (or switch the administration's language to German):
"Hallo, Ada!" and "Neueste Artikel". Check the coverage:
./console exp:i18n fallbacks --locale=ger-DElists, per extension, how much is translated for the locale and its fallbacks.
Related pages
- Previous: By hand: a rich text custom tag
- Next: By hand: help pages for your extension
- Translations in an extension
- 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.