The next stage is to use the translate object to translate our website
14.3.3 Translating the view
For our website to be multi-lingual, we need every piece of English text on every page to be changed to
run through the _() function of Zend_Translate. We have already assigned the translate object to the view, so
we can change the original
Recent reviews
on the home page to >translate->_(???Recent reviews??™); ?>. That??™s quite a lot of typing though, so we will create a view
helper called _() to reduce our typing and make the view templates a little clearer. The ???_??? view helper is
shown in listing 14.11.
Listing 14.11: The _() view helper
class Zend_View_Helper__
{
protected $_view;
function setView($view)
{
$this->_view = $view;
}
public function _($string)
{
return $this->_view->translate->_($string); A
}
}
A Call through to the translate object??™s function
The oddest thing about this class is its name; due to the naming convention, it looks like it isn??™t finished!
However, other than that, this helper is very simple as it exists solely to reduce typing. Let??™s look at it in use on
the home page. Listing 14.12 shows the top part of the index.phtml view template for the home page before
localization.
Pages:
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360