With the storage format chosen, the next step is to build the templates with translation in mind. For the sake of this tutorial, we will be looking at a purely MVC driven website using the Scorpio framework and the built-in Smarty layer.
The default view renderer in Scorpio is a customised extension of Smarty, a PHP template engine. Scorpio enhances the functionality of Smarty by adding several custom functions and wrappers. In particular, there is a pre-filter that is registered automatically during initialisation. This pre-filter allows text that is marked up correctly to be run through the translation system - if enabled on the site.
The default markup for Smarty templates is to use a pair of 't' tags: {t}{/t}. This can be configured in the site config file to some other letter or phrase.
Using the tag is straight forward; whenever you write text that is shown to the end-user, place the tags around the whole block of text - note this should not include display HTML (strong and em is permissible but is strongly discouraged). This block can include other Smarty functions or Smarty formatting modifiers and variables. For example, you may say hello to the currently logged in user:
Before:
Hello {$oUser->getName()}
After:
{t}Hello {$oUser->getName()}{/t}
Images are problematic as what looks great in English or the native script, may (when translated) be unreadable. At any rate, the image text will need translating and the custom image stored in a language specific location. You can then access the path using the Locale that is registered in the request object.
Your image path may then be something like:
<img src="{$themeimages}/{$oLocale->getLocale()}/welcome.png" />
As a suggestion: keep text in images to a minimum. It becomes difficult to manage and each new language will need new images and remember that changes to the text will need to be made to ALL images - better idea to use CSS sprites and have real text instead.
Once all your templates are in order and all the text is marked up, the next step is building the language resource file.
Posted by: Dave Redfern (Writer), in Tutorials on 07 Sep 2009 @ 22:54
Tags: languages, translation system, tutorial,
Contents:
This
work is licenced under a
Creative Commons Licence.