Cakephp understanding Localization..?

I guess for most of you this might be a "dumb" question, but I just don't get it.

As I am a beginner, I tried many tutorials I found on google, but none of them is working for me.

I have Cakephp 2.2 running and I'm trying to get the localization working. I followed the book ( http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html )

What I did so far:

//In my bootstrap.php I added 
Configure::write('Config.language', 'deu');


// In my AppController.php I added
public function beforeFilter() {
    $locale = Configure::read('Config.language');
    if ($locale && file_exists(VIEWS . $locale . DS . $this->viewPath)) {
        $this->viewPath = $locale . DS . $this->viewPath;
    }
}

From my understanding, the visitor should now be redirected to /ger/ . But nothing is happening...?

Could you please please point me in the right direction..?

Sorry again for the question, but as I'm a beginner I'm stuck now. :(

Thanks for your help in advance


All this code will do is edit the $this->viewPath variable.

This will make CakePHP look in a different directory from the standard when calling render() . This is normally done if you intend to create different folders, each of which contains the View files for a specific localisation.

If your View folder currently looks like this:

View
    - Elements
    - Emails
    - Errors
    - Helper
    - ...

It should, instead, look like this:

View
    - deu
        - Elements
        - Emails
        - Errors
        - Helper
        - ...
    - Elements
    - Emails
    - Errors
    - Helper
    - ...

In this way, you can specify entirely different View files for lots of different localisations. The folders in the root directory should be the default localisation.

The reason it currently isn't doing anything is because it can't find the relevant view files when it makes the file_exists() check. Once you have restructured as necessary it should work fine.

链接地址: http://www.djcxy.com/p/58828.html

上一篇: 如何在通过CakePHP 3.0中的表链接模型时检索信息?

下一篇: CakePHP了解本地化..?