Prev | Current Page 347 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Before we
load a language file, we first check that the selected language is available (#1) as the user could, in theory, type
any text within the language element of the address path. As we only have a limited number of language files
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 44
in the translations directory, we check that the choice of the user is available. If not, then we pick English
instead. Similarly, although the language is valid, we double check that the file actually exists (2) in order to
avoid errors later and load the file using a simple include statement. An assumption is made that the language
file contains an array called $translationStrings which contains the actual translations and so we throw an
exception if this array doesn??™t exist. Having completed our error checking, we then instantiate a new
Zend_Translate object (#3) and assign it to the action controller and the view for use within the rest of the
application.
As we discovered when we looked at Zend_Translate, the system supports multiple adapters to allow for a
variety of input sources for the translation strings. For Places, we have chosen arrays as they are the simplest
to get going, however if the site grows significantly, then moving to gettext would be easy to do and would
require changes to just this init() function.


Pages:
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
nieruchomości kielce Books Pozycjonowanie obrączki ślubne kraków Wiadomości ze świata