6.
Listing 14.6: Zend_Translate using the gettext() adapter
$filename = 'translations/uppercase.po'; A
$translate = new Zend_Translate(gettect, $filename, 'en'); A
print $translate->_("hello")."\n"; B
print "=======\n"; B
printf($translate->_('today %1$s')."\n", date('d/m/Y')); B
A Change the adapter to gettext
B Everything else is the same
As you can see, the use of the translation object is exactly the same, regardless of the translation source
adapter used. Let??™s look at integrating what we have learnt into a real application. We will use our Places
application and adapt it to support two languages.
14.3 Adding a second language to Places
The initial goal for making Places multi-lingual is to present the user interface in the language of the
viewer. We will use the same view templates for all languages, and ensure that all phrases are translated
appropriately. Each language will have its own translation file stored, in our case using the array adapter to
kept things simple and if the user requests a language for which we do not have a translation, then we will use
English. The result can be seen in Figure 14.1 which shows the German version of Places. (Note that the
translation was done using Google translate ??“ a human translator would do a much better job of it!)
Licensed to Menshu You
Pages:
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351