cake-php@googlegroups.com
[Top] [All Lists]

Re: Localize only some of a controller's pages

Subject: Re: Localize only some of a controller's pages
From: cricket
Date: Sat, 11 Dec 2010 11:58:51 -0500
On Thu, Dec 9, 2010 at 9:27 PM, Ryan Schmidt <google-2010@xxxxxxxxxxxxxx> wrote:
> 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.

You could extend the test to check which page is being requested. Or,
whether $this->params['admin'] is set, etc.

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 cake-php@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
cake-php+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

<Prev in Thread] Current Thread [Next in Thread>