• 1
name Punditsdkoslkdosdkoskdo

Generate Yii translation message files

I am interested to know is there a script or otherway available to collect and generate Yii translation messages in a controller/project

Eg. If I have the following codes in a controller

Yii::t('blog', 'Your name');
Yii::t('category', 'Category name');

It should generate English translation message files as blog.php and category.php with above strings in messages directory. Please let me know if somebody knows a way. Thanks

There's no need to reinvent the wheel. You can use yiic for that (if you go to the framework folder and type in yiic help message you will get all the info to need about it's usage). For convenience, I'm going to paste it here.

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 oproject on Windows or /var/www/your/project on *nix)

  • 0
Reply Report