Andreas123
(619forlife)
January 20, 2013, 5:45pm
1
Hi there,
I’m building an app that supports various languages.
File Translation in the context of a "render-call" works well via findLocalizedFile()
The question:
How do I load the main.php for the correct language??
My folder structure is a suggested by Yii:
themes/themeName/views/layouts/main.php
themes/themeName/views/layouts/en/main.php
Thx
Andreas
seenivasan
(Chellamnivas)
January 20, 2013, 6:27pm
2
Dear Friend
You can use the Controller.php in components folder.
Normally all the controllers are derived from it,if you have not changed default things.
components/Controller.php
class Controller extends CController
{
public function init()
{
if(Yii::app()->language=="aa")
Yii::app()->theme="theme1";
if(Yii::app()->language=="ru")
Yii::app()->theme="theme2";
if(Yii::app()->language=="en_us")
Yii::app()->theme="theme3";
}
}
We can also declare them in a function in an application behavior and then you can attach that function to
"onBeginRequest" of the application.
Regards.
Andreas123
(619forlife)
January 20, 2013, 7:07pm
3
Ah ok…
Just found the answer myself.
Actually findLocalizedFile() is called within the render()-method itself.
So no need to worry about file translation at all… its done automatically as long as the correct language is set and the files in the view folders are present.
The only important part is that you stick to this structure:
themes/themeName/views/layouts/main.php
themes/themeName/views/layouts/en/main.php
seenivasan
(Chellamnivas)
January 20, 2013, 7:25pm
4
Sorry Friend!
I misunderstood that you needed different layouts under separate themes for different languages.