We
also define the defaults for each part of the route for when it is missing. As we are replacing the default route
with our new route, we keep the same defaults so that the index action of the index controller is called for an
empty address. We set the default language to the browser??™s default language as determined by Zend_Locale??™s
getLanguage() function. However, as we set this as a default, it means that if the user chooses a specific
language, the choice will take precedence. This allows for people using a Spannish browser to view the site in
English, for instance.
Now that we have routing working, we need load the translation files. We need to do this after routing has
happened, but before we get to the action function. An action helper is the ideal vehicle for this.
14.3.2 The language action helper
An action helper has a number of different hooks into the various stages of the dispatch process. In our
case, we are interested in the init() hook as we want to load the language files after routing has happened and
we only need it to be called once per request. Our action helper, Language will be stored in the Places library
and in order to take advantage of Zend_Loader, the class is called Places_Controller_Action_Helper_Language
and so lives in library/Places/Controller/Action/Helper/Language.
Pages:
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356