Do I have to trigger the appropriate layout in the rendering method of the controler myself or is there some locale dependant automatic? I mean like the apache who distiguishes the pages by the locale ending for example.
yeah, that paragraph may not explain very clearly.
Basically, for layout or views (either controller view or widget view), you can just create a subdirectory named as the language ID, and put the localized view versions under that directory.
When you use one of the render methods to render the view, it will automatically pick up the view which is corresponding to the current application language.
I'm also a little confused - Allow me to quote the documentation:
Quote
File translation is mainly used when rendering a view. When calling one of the render methods in a controller or widget, the view files will be translated. For example, if the target language is zh_cn while the source language is en_us, rendering a view named edit would resulting in searching for the view file protected/views/ControllerID/zh_cn/edit.php. If the file is found, this translated version will be used for rendering; otherwise, the file protected/views/ControllerID/edit.php will be rendered instead.
I understand the above like this: If a file exists in a LocalId folder then the file(view) is used
e.g
protected
views
site
da
index.php
en_us
index.php
Then I would expect the da version to be used for Danish users etc. , but… that does not work.
I'm pretty sure that it's due to the fact that I need to set something up or do I need to call CApplication::findLocalizedFile() on each call to a render method ?
Until now we discussed how to set the locale explicit as I understood. Where can I react on the CHttpRequest::preferredLanguage setting of the user request? Or is this done automatically?
What has the priority when the users preference settings differ from the language he chose on the website or is it switchable to choose the language either from the users browser settings or a fixed language the user choose so that I can give the user the possibility to override the preferences set in his browser by clicking on the 'en' switch for example?
There is no automatic mechanism in Yii to set language based on user's preference. The application code has to do this explicitly using whatever policy it likes.
So if you want your application to use a language preferred by user, you may set the language property of application before you use any i18n feature. For example, you can do so in controller constructors, or in onbeginRequest event handler to the application.
Just started with Yii, and see a great framework here. i18n is there too, cool. To get some grip on things, I'm planning to port a small webapp to Yii (now CI), but for SEO reasons I would like to add a language ID to the url, except for the default language.
The language the user will see the first time can be determined by the preferred language. To avoid messing with controllers for each language, it probably needs to be done before any routing is done (extending CUrlManager), but perhaps there are other possibilities in Yii.
With this rule, the language id would be a GET parameter.
Then you can define a base controller class, which checks in its constructor to see if 'lang' GET parameter is specified. If not, use Yii::app()->request->preferredLanguage to guess the user's preferred language. If yes, check if the language is supported, and if so, set the application's language property.
All your controllers should extend this base controller class. And you will get the needed i18n support automatically.