5 using Zend_Translate??™s array adapter In this case, we make life
easier by ???translating??? to upper case, but we could equally have translated to German, if I knew enough!
Listing 14.4: Standard PHP output
print "Welcome\n"; A
print "=======\n";
print "Today's date is " . date("d/m/Y") . "\n"; B
A Standard PHP print statement
B UK format date
Listing 14.4. is a very simple piece of code that displays three lines of text, maybe for a command line
script. To provide a translation we need to create an array of translation date for the target language. The array
consists of identifying keys mapped against the actual text to be displayed. The keys can be anything, but it
makes it easier if it is essentially the same as the source language.
Listing 14.5: Translated version of Listing 14.4
$data = array(); A
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 39
$data['hello'] = 'WELCOME'; A
$data['today %1$s'] = 'TODAY\'S DATE IS %1$s'; A
$translate = new Zend_Translate('array', $data, 'en'); B
print $translate->_("hello")."\n"; 1
print "=======\n";
printf($translate->_('today %1$s')."\n", date('d/m/Y')); 2
A Translation array
B Create an instance of Zend_Translate
C Print the ???hello??? translation text
C printf() palceholders also work
In this example, we use the _() function to do the translation (1).
Pages:
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349