Ok, so after listening to what a lot of people have said here, and gettin some feedback from other php devs.

Here's what I've come up with.

[bootstrap]

$zl = new Zend_Locale();
$lang = in_array($zl->getLanguage(), array('en','fr')) ? $zl->getLanguage() : 'en';

$router = new Zend_Controller_Router_Rewrite();
$router->removeDefaultRoutes(); //not sure if this is required as the addDefaultRoutes method checks for a 'default' route. $router->addRoute('default', new Zend_Controller_Router_Route(':lang/:module/:controller/:action/', array('controller'=>'index','action' => 'index','module'=>'default', 'lang'=>$lang)));

This has the benefit of using locale detection, but also providing a url variable which can override it [some bilingual people prefer to read englsih content despite their locale being a different language]

It also means that there can be x supported languages defaulting to a specific one [no need for full support of every possibly encountered accept language]

As for the templates, the localization of data is cool for Zend_Locale related classes, but for templates I want two distinct designs for different audiences; different fonts/styles/graphics. Instead of trying to make a french peg fit an english designed hole, two independantly designed templates are used.

Which leaves an Action extension something like..

abstract class LanguageAction extends Zend_Controller_Action {
       public function __construct($request, $response, $args=array()) {
               parent::__construct($request, $response, $args);

               $lang = $this->getRequest()->getParam('lang');
               $this->lang = $lang; //Provide language specific info

               $view = Zend::registry('view');
               $view->lang = $lang;
               $paths = $view->getScriptPaths();
$view->setScriptPath($paths[0] . DIRECTORY_SEPARATOR . $lang);
       }
}

This has an integrated view object, which is of course optional.

Finally templates will end up in

application/views/en/
application/views/fr/

Critiques?

Kevin McArthur


----- Original Message ----- From: "Juri Kühn" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, February 28, 2007 12:28 PM
Subject: Re[2]: [fw-general] Internationalization and the Zend Framework


Thomas Weidner wrote:
And I do not think that you want to have a subdir for all 32 locales within
the english language.

You're right, that really wouldn't be nice :) The point is to map a
language requested by the user to the appropriate language directory.

Philippe Le Van wrote:
Traductions are made in smarty configurations files and a custom
translation system for technical messages (like "wrong email" for
example).

You can use smarty for mails and other stuff too! Strings like the
subject can be easily pulled from configuration files as well:
...
$smarty->config_load("$langdir/$userlang/$conffile", $section);
$mail->setSubject($tpl->get_config_vars('subject'));
$mail->setBodyHtml($smarty->fetch($mailtemplate));
$mail->send();
...
This way you dont need any extra exceptional translation system.

Greetings,
Juri



Reply via email to