Multilingual extensions

We saw how to create a new locale file and how to compile a translations file. Now we will see how to upgrade our extension to i18n.

The extension folder structure

To enable multilingual support in our extension, we have to create a new folder structure for the translation files. We have to open a shell, go to the extension folder, and then create a directory named translations.

# cd /var/www/packtmediaproject/extension/packtmedia
# mkdir translations
# mkdir translations/ita-IT
# mkdir translations/fra-FR
# mkdir translations/de-DE

For all of the folders, we have to create the translation.ts file named according to the string that we will use in the templates.

The extension siteaccess

As for the main siteaccess that we configured in Chapter 2, we have to notify the system to also enable the internationalization system for our extension. To do this, we need to open the site.ini.append.php file located in the extension settings/ directory.

# cd /var/www/packtmediaproject/extension/packtmedia
# cd settings
# vi site.ini.append.php

Now, add the following lines to the bottom of the site.ini.append.php file:

[RegionalSettings]
TranslationExtensions[]=packtmedia

As we can see in the above code, the TranslatedExtensions array parameter is used to enable the internationalization system for the named extensions, in this case packtmedia.

After we configure the RegionalSettings section, we have to clear the eZ Publish cache to let the system know that the extension will use the internationalization features of the CMF, and to let the system know that it will have to search for the required translation files.

The template strings

One of the first things to do is to replace all of the hardcoded text that we placed in the templates files using the i18n and l10n operators.

These operators are quite easy to use; we saw them in Chapter 7 when we customized the override template for the profile pages.

{'Original string'|i18n( 'design/packmedia/content/newstring' )}

The i18n operator allows us to change the string placed before the pipe with the one identified by the unique name that we pass as the first parameter.

{$node.object.published|l10n( 'date' )}

Here, the l10n operator will help us to format miscellaneous numeric values according to the current locale settings as dates, times, currencies, numbers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.55.198