Module Language

Ok, en_us then, but I’m still not convinced (even if I do understand your points).

‘en_us’ Maybe the best option, but what is sure, is that english is far from being mastered by everyone (including myself). I definitly prefer a good source code in native language that will be translated later in other languages by people who feel confortable, than some strange, approximative, low quality english-like dialect that noone (including the author after 6 month) will be able to understand and less to translate.

But ok, en_us then… and thank for participating to this discussion ;)

ciao

B)

Don’t worry, Mike. I’m not offended.

I would rather want to be too verbose than to be too concise, in order to say what I want. But I agree, the shorter the better in general.

anyway Softark, your explanation was very intresting and complete … it did help me a lot. Thanks

8)

Dear Raoul

I hope you remember me, Since I have given a PM to you when you initially made this post.

That time I just downloaded some user management modules(or extensions) and istalled them.

Some of them have intrinsic message translation files for very few languages.

What all I needed was just to add one line in CWebModule::init method.




Yii::app()->language='de';



After that tranlation messages all over the application in German.

I felt that since these extensions strictly adhered to the modular architecture of YII,once language setting

changed they started to look into the message files available inside the module itself.

What can we do when modules or extensions failed in localizing the message files?.

How we can we force the a module to look into a particular messages folder that may reside in the other module?.

Let us have a module with an id sunlight.

Now when this module is instantiated, we are going to change the language to fr.

modules/sunlight/SunlightModule.php




class SunlightModule extends CWebModule

{

	public function init()

	{

		$this->setImport(array(

			'sunlight.models.*',

			'sunlight.components.*',

		));


		Yii::app()->language="fr";//SETTING THE LANGUAGE

	}

.............................



Now we can create the folder messages in sunlight folder.

Inside the sunlight folder we can create the folder fr.

Let me have translation file inside the fr.

modules/sunlight/messages/fr/greeting.php




?php

return array(

	'hello!, good morning!'=>'bonjour!',

	'hello!, good evening!'=>'bonsoir!',

	'have a good day!'=>'bonne journée!',

	'have a good evening!'=>'bonne soirée!',

	'good luck!'=>'bon courage!'

);

?>



Now we can instruct YII to look at these files.

We have to declare messages component inside the main.php.




'components'=>array(

    'messages'=>array(

			'class'=>'CPhpMessageSource',

			'extensionPaths'=>array(

				'sunlight'=>'application.modules.sunlight.messages',

			),

		),

...........................................



By setting the extensionPaths property, we can literally map the message files situated in various extensions or

modules.

Have a look at the API.

CPhpMessageSource::extensionPaths

Now we can translate a message into french in a view inside the Module.




echo Yii::t('sunlight.greeting','have a good evening!'); //ouputs bonne soirée! 



Note that the first parameter should be in the format of classId.catagoryName.

The same things can be easily achieved withoUt declaring messages component.

For that we can add one more line to CWebModule::init method.




public function init()

	{

		$this->setImport(array(

			'sunlight.models.*',

			'sunlight.components.*',

		));

		Yii::app()->language="fr";

		Yii::app()->messages->basePath=Yii::getPathOfAlias('application.modules.sunlight.messages');

//You can have your messages files wherever you want.

//We can instruct YII to look into those files.

	}



Now we can translate a message into french in a view inside the Module.




echo Yii::t('greeting','have a good evening!'); //ouputs bonne soirée!. no need to call sunlight.greeting



I hope I helped a bit.

Regards.

Hi seenivasan,

yes I remember your PM and the explanation you give here is very intresting to me. In particular the fact that extensionPaths is now an array (since 1.1.13) and not a string anymore. I didn’t noticed that change.

Just one question : in your example, what is the sourceLanguage of the webapp your module is pluged in ?

B)

ciao

Friend

that is en_us.

Hi seenivasan,

I think that the problem with your solution is that you assume that after module initialization no component outside of the module will output a string …

I have a webapp that is able to provide widgets that can be used by plugged-in modules. A module can use its own widget, or use the ones provided by the web app it is plugged into. In this scenario, your solution doesn’t always work (in particular if the source language is not ‘en_us’).

for example :

  • webapp : sourceLanguage = ‘fr’ (french)
  • plugged-in module :[list]
  • sourceLanguage = ‘ja’ (japaneese)
  • translation provided for fr

[/list]I want pages to be displayed in french, so I’m suppose to write language = ‘fr’… but in this case :


Yii::app()->sourceLanguage == Yii::app()->language; 

…is TRUE : no tranlsation will be performed. Strings from the module will be displayed in Japaneese.

[i]It seems very much to me that parameter sourceLanguage is useless.

B)

[/i]

Dear Raoul

Yes that is a problem.

But that is happening when you are setting the basepath of component messages explicitely in CWebModule::init method.

If you are configuring messages component in main configuration files with extensionPaths, that is not at all issue.

You can easily test that by putting some messages files in protected/messages(which is basepath for main application) ,creating some widgets using translation and calling them in the module.

But anyway one has to declare the language in CWebModule::init method.


Yii::app()->language="fr";

Regarding sourceLanguage, my conviction is that it is like declaring the version id of application.

If I am correct the only purpose it serves is that when language is not defined, it points to sourceLanguage.

So by declaring the different sourceLanguage,we are not going to do any magic.

If someone writes a module in Japanese language and if he intends to give a multilingual support then he has to

ensure that messages files should return array with array index written in japanese and array value in other languages.

Regards.