# Yii:generate automatically multilanguage files

Gepost op 12-11-2013 door zwano webdesign in frameworks | 0 Reacties

Lately i have been very busy making programs in yii. Last 7 month about 6 systems which all needed multi - language. Multi language is something that can take a lot of your time. In this small tutorial i will try to explain in a simple way how to generate automatically language files using yii.

A good link to get started would be here: http://stackoverflow.com/questions/11232039/generate-yii-translation-message-files

USAGE yiic message path/to/config/file

DESCRIPTION This command searches for messages to be translated in the specified source files and compiles them into PHP arrays as message source.

PARAMETERS * config-file: required, the path of the configuration file. You can find an example in framework/messages/config.php.

The file can be placed anywhere and must be a valid PHP script which returns an array of name-value pairs. Each name-value pair represents a configuration option.

The following options are available:

• sourcePath: string, root directory of all source files.
• messagePath: string, root directory containing message translations.
• languages: array, list of language codes that the extracted messages should be translated to. For example, array('zh_cn','en_au').
• fileTypes: array, a list of file extensions (e.g. 'php', 'xml'). Only the files whose extension name can be found in this list will be processed. If empty, all files will be processed.
• exclude: array, a list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory 'sourcePath/a/b'.
• translator: the name of the function for translating messages. Defaults to 'Yii::t'. This is used as a mark to find messages to be translated.
• overwrite: if message file must be overwritten with the merged messages.
• removeOld: if message no longer needs translation it will be removed, instead of being enclosed between a pair of '@@' marks.

You should modify (and move) the example config file and you're all set. Be sure to use full paths (ie. C:\path\to\project on Windows or /var/www/your/project on *nix)

How does we get this work we will start with USAGE

TERMINAL / MAC OS php yiic message path/to/config/file DESCRIPTION PARAMETERS /var/www/vhosts/framework/messages/config.php on the command lin

PUTTY yiic message path/to/config/file DESCRIPTION PARAMETERS /var/www/vhosts/framework/messages/config.php on the command line

I am using the terminal of the mac so for me it would be php yiic message

path/to/config/file = use here $_SERVER['DOCUMENT_ROOT'] otherwise it wont work. So whats in the config file and were should we place it? Just create a php file named config.php and place it in config. The Following things should be in here: 'messagePath' => '/var/www/vhosts/partner/protected/messages/' , // the path to your message files 'sourcePath' => '/var/www/vhosts//partner/protected/controllers/', //with things should be looked through // contoller / view / model? 'languages' => array('en', 'nl', 'fr'), // the languages you are using. After this is done put DESCRIPTION this will look for all Yii:t('name file', 'the text comes here'); Then you can change the settings framework/messages/config.php Also the document_root Enjoy this is a very easy way to safe time making language files for your website. Also when you are working with foreign developers this can be very handy. If you find some improvements or things are not clear dont hassitate to contact me. Have a nice Day! Will update later # Yii:generate automatically multilanguage files Gepost op 12-11-2013 door zwano webdesign in frameworks | 0 Reacties Lately i have been very busy making programs in yii. Last 7 month about 6 systems which all needed multi - language. Multi language is something that can take a lot of your time. In this small tutorial i will try to explain in a simple way how to generate automatically language files using yii. A good link to get started would be here: http://stackoverflow.com/questions/11232039/generate-yii-translation-message-files USAGE yiic message path/to/config/file DESCRIPTION This command searches for messages to be translated in the specified source files and compiles them into PHP arrays as message source. PARAMETERS * config-file: required, the path of the configuration file. You can find an example in framework/messages/config.php. The file can be placed anywhere and must be a valid PHP script which returns an array of name-value pairs. Each name-value pair represents a configuration option. The following options are available: • sourcePath: string, root directory of all source files. • messagePath: string, root directory containing message translations. • languages: array, list of language codes that the extracted messages should be translated to. For example, array('zh_cn','en_au'). • fileTypes: array, a list of file extensions (e.g. 'php', 'xml'). Only the files whose extension name can be found in this list will be processed. If empty, all files will be processed. • exclude: array, a list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory 'sourcePath/a/b'. • translator: the name of the function for translating messages. Defaults to 'Yii::t'. This is used as a mark to find messages to be translated. • overwrite: if message file must be overwritten with the merged messages. • removeOld: if message no longer needs translation it will be removed, instead of being enclosed between a pair of '@@' marks. You should modify (and move) the example config file and you're all set. Be sure to use full paths (ie. C:\path\to\project on Windows or /var/www/your/project on *nix) How does we get this work we will start with USAGE TERMINAL / MAC OS php yiic message path/to/config/file DESCRIPTION PARAMETERS /var/www/vhosts/framework/messages/config.php on the command lin PUTTY yiic message path/to/config/file DESCRIPTION PARAMETERS /var/www/vhosts/framework/messages/config.php on the command line I am using the terminal of the mac so for me it would be php yiic message path/to/config/file = use here$_SERVER['DOCUMENT_ROOT'] otherwise it wont work.

So whats in the config file and were should we place it?

Just create a php file named config.php and place it in config.

The Following things should be in here:

'messagePath' => '/var/www/vhosts/partner/protected/messages/' , // the path to your message files
'sourcePath' => '/var/www/vhosts//partner/protected/controllers/', //with things should be looked through // contoller / view / model?
'languages' => array('en', 'nl', 'fr'), // the languages you are using.

After this is done put DESCRIPTION this will look for all Yii:t('name file', 'the text comes here');

Then you can change the settings framework/messages/config.php Also the document_root

Enjoy this is a very easy way to safe time making language files for your website. Also when you are working with foreign developers this can be very handy. If you find some improvements or things are not clear dont hassitate to contact me.

Have a nice Day! Will update later