The usual command line
protected/yiic message protected/messages/config.php
produces .php files whereas computer-aided translation systems such as Lokalize or PoEdit use gettext files, so I made this converter between .po and .php and added a custum extraction process to fit my needs.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.1.5 or above
Installation ¶
- Extract the release file under
protected/commands
Usage ¶
Getting help ~~~ protected/yiic emessage ~~~
Retrieving translation strings ~~~ protected/yiic emessage message ~~~
Convert .php to .po ~~~ protected/yiic emessage php ~~~ (beware of the header and specially the nplural formula)
Convert .po to .php ~~~ protected/yiic emessage po ~~~
checks the evaluation expression in the plural message. A misformed expression can raise a 500 error, depending on php.ini. ~~~ protected/yiic emessage check ~~~
Extract the credits from the string translator-credits
, added by Launchpad.
~~~
protected/yiic emessage credits
~~~
Finding duplicates ~~~ protected/yiic emessage duplicates ~~~
Finding duplicates without considering the case ~~~ protected/yiic emessage duplicates --caseSensitive=false ~~~
Removing the files (.php and .po) which are untranslated. ~~~ protected/yiic emessage removeEmptyFiles ~~~
Getting translation statistics ~~~ protected/yiic emessage statistics ~~~
You can specify the path of the configuration file (default: protected/messages/config.php
).
The file 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 must be specified:
- 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').
- autoMerge: boolean, overwrite the .php files with the new extracted messages. Default: false.
- launchpad: boolean, if the .po files must be stored as protected/messages/launchpad/template/lang.po or in the same directory of the converted .php file. Default: false.
- skipUnused: boolean, do not mark unused string with '@@' and skip them. Default: false.
- 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.
For example, my current configuration file contains:
return array(
'sourcePath'=>dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..',
'messagePath'=>dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages',
'languages'=>array('da', 'de', 'eo', 'fr', 'it', 'nl', 'pl'),
'autoMerge'=>true,
'launchpad'=>true,
'skipUnused'=>true,
'fileTypes'=>array('php'),
'exclude'=>array(
'.svn',
'.bzr',
'/messages',
'/protected/vendors/'
),
);
Change Log ¶
May 23, 2009 ¶
- Initial release.
May 12, 2010 ¶
- Second release (renamed to EMessage) with 2 more commands: message and statistics
November 10, 2010 ¶
- Third release with more options, among them : creation of the .po files in a launchpad directory.
December 14, 2011 ¶
- Patch on sorting the string by Attila N.
January 4, 2012 ¶
- Add the caseSensitive option to the
duplicates
action.
June 4, 2012 ¶
- Add
check
action to check the plural forms. - Add
removeEmptyFiles
action to delete the untranslated files. - Corrections by Motin.
usage?
Convert .php to .po
protected/yiic pophp php protected/messages/config.php
should be:
protected/yiic php pophp protected/messages/config.php
if not, why the cmd same to "Convert .po to .php"??
POEdit does everything you need
If properly configured poedit can scan all files in configured paths and detect all t() strings by itself.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.