I'm reading about how internationalization and localization are handled in 
CakePHP. On this page...

http://book.cakephp.org/view/1229/Internationalizing-Your-Application

...the book explains how to use gettext and the __() function to localize 
strings, but also says that if I want to translate longer passages or entire 
pages of text, I should use a different solution, like writing individual 
language-specific templates and loading them using code like this in 
app_controller.php:


function beforeFilter() {
    $locale = Configure::read('Config.language');
    if ($locale && file_exists(VIEWS . $locale . DS . $this->viewPath)) {
        // e.g. use /app/views/fre/pages/tos.ctp instead of 
/app/views/pages/tos.ctp
        $this->viewPath = $locale . DS . $this->viewPath;
    }
}


My initial reading of this code suggested to me that it would look for a 
localized template, and if none was found, it would fall back to a 
non-localized one. This is what I want. But I was thrown off by the call to the 
file_exists() function. In fact, $this->viewPath is not a file; it's a 
directory. It's only checking if the localized directory name exists, and if 
so, tries to access the views inside it. This means *all* of a given 
controller's views must either be localized with individual files, or none of 
them can be. This is not what I want. I want, for example, my terms and 
conditions page (served by the pages controller) to be localized in individual 
language-specific files, but I want my admin main page (also served by the 
pages controller) to be localized using gettext.

How can I accomplish this? I've tried to rewrite this beforeFilter to check the 
name of the template file, but I don't know how where the template filename is 
stored, or how to construct it if it's not stored anywhere. The pages 
controller, for example, puts it together itself. I tried using beforeRender() 
instead, but was surprised the path to the template that will be rendered isn't 
available to beforeRender() anywhere either, that I can see. (No arguments seem 
to be passed to beforeRender().)


Alternately, should I not serve my admin main page using the pages controller 
at all, and instead create an admin controller whose only purpose will be to 
show the admin main page? and only use the pages controller for pages with long 
text blocks that will be translated with individual templates?




Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to