Generate Yii Translation Message Files

hi every body

i need how can i generate all messages into function translate ie( Yii("app","Hello World"); to file "messages/en/app.php" );

can you help me for this

You can use ‘yiic message’ command. :)

Try "yiic message" in the console, then the detailed descriptions will tell you what to do.

(Or, you can read it in the top lines of framework\cli\commands\MessageCommand.php)

thanks that is done

but my files into messages like that

messages/en/hr/employee/app.php

how can i pass this path into YII::t("What path here","Hello World");

??

There’s no need to change Yii::t(“app”, “Hello World”) in the source.

All you have to do to translate "Hello World" into some other language (for instance "ja") is just to make messages/ja/app.php file.

“messages/en/hr/employee/app.php” seems strange. You may have configuration error in your config.php file, probably ‘messagePath’ is wrong.

This is a sample of config.php




<?php

/**

 * This is the configuration for generating message translations

 * for the Yii framework. It is used by the 'yiic message' command.

 */

return array(

	'sourcePath'=>'path/to/your/application/', // eg. '/projects/myproject/protected'

	'messagePath'=>'path/to/your/application/messages', // '/projects/myproject/protected/messages'

	'languages'=>array('en','fr','zh_cn','ja'), // according to your translation needs

	'fileTypes'=>array('php'),

	'overwrite'=>false,

	'removeOld'=>true,

	'sort'=>true,

	'exclude'=>array(

		'.svn',

		'.gitignore',

		'yiilite.php',

		'yiit.php',

		'/i18n/data',

		'/messages',

		'/vendors',

		'/web/js',

		'UserModule.php', // if you are using yii-user ... 

	),

);




I understand you but i need every module in site in file translate ie( i have to module into site employee , inventory) i need the folder message like that messages/en/employee/app.php but now the folder messages like that

messages/en/app.php .

how can i pass the words in module employee in yii::t("what path here","hello world") ?

It should be something like this:




Yii::t("EmployeeModule.app", "hello world");



And the translation file should be stored as 'protected/modules/employee/messages/en/app.php.

http://www.yiiframework.com/doc/guide/1.1/en/topics.i18n

http://www.yiiframework.com/doc/guide/1.1/en/topics.i18n#c380

You may define another category other than "app".

thanks , Can i manage the messages folder "nested folder in folder messages" ie(protected/modules/employee/messages/en/modelname/app.php)

I’m not very sure, but probably you can’t.

very thanks , i use giix to create my curd and that is fine , giix are added all attributes from table into file app.php

can over ride this

i need every model have file translation alone ? how can i do that

regards

You can define different categories for each and every models …




category 'foo' for model Foo

category 'bar' for model Bar

...



… though I don’t think it’s very effective. :)

thanks that is goood :)

Dear softark,

I’m trying to store my translation messages inside modules/messages.

I call a translation method like this:


Yii::t('ChecklistsModule.certificates', 'New certificate');

Then I run yiic message to collect my messages. I would expect to get my module messages inside a module, but they get into a common message directory instead.

Here’s my config for yiic message:




return array(

    'sourceLanguage'=>'ru',

	'sourcePath'=>dirname(__FILE__).'/../',

	'messagePath'=>dirname(__FILE__).'/../messages',

	'languages'=>array('ru','en'),

	'fileTypes'=>array('php'),

	'overwrite'=>true,

	'exclude'=>array(

		'.svn',

		'.gitignore',

		'yiilite.php',

		'yiit.php',

		'/i18n/data',

		'/messages',

		'/vendors',

		'/web/js',

		'/yii',

		'/extensions',

		'/migrations',

	),

	'removeOld' => true,

	'sort' => true,

);



What am I doing wrong? How to collect the module translation message inside a module directory?

Hi Versus, welcome to the forum.

Where do you put your config file for yiic message command? I think it should be under your module directory.

One example here: https://github.com/janisto/yii-ycm/tree/master/messages

Usage:




$ cd path/to/protected/modules/ycm

$ php ../../yiic message messages/config.php



Well, I put it in /protected/config directory as a global config for translations.

If I get you right, then I should have a separate config for each module AND the main/commong config must include /modules?

I thought there should be a better way to do this with one config for all source files: common sources AND modules.

So that yiic would automatically put module translations into modules/messages

Thanks for the example, which I understand.

But again, then you do "yiic message" for each module separately AND for all other sources also separately?

Yes.

As janistro has said, we will have a separate config file for each and every module and the main program, and have to repeat "yiic message" command, because we can specify only one place for output per config file.

You can write a batch command if you want. :)