Yii Framework Forum: Load Language Dependent Main.php ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Load Language Dependent Main.php ? Rate Topic: -----

#1 User is offline   Andreas123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 11-March 11
  • Location:$3RdF

Posted 20 January 2013 - 12:45 PM

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
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 20 January 2013 - 01:27 PM

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.
0

#3 User is offline   Andreas123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 11-March 11
  • Location:$3RdF

Posted 20 January 2013 - 02:07 PM

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

0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 20 January 2013 - 02:25 PM

Sorry Friend!

I misunderstood that you needed different layouts under separate themes for different languages.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users