Reusability of yii.cli.commands.MessageCommand

At our company, we need to create a GUI translator module for yii that helps users change translation strings on their browser.

First part of this, would be to extract messages from source files. In yii.cli.commands.MessageCommand, there is a function named extractMessages() which does the exact thing.

I thought for the sake of code reusability, we should create a class called CMessageFinder. then, both our module and MessageCommand would use it to extract messages.

Now, second part of the job is generating the message files. MessageCommand, has a method named generateMessageFile().

MessageCommand::generateMessageFile() does generate a PHP file. it doesnt support PO files (which we actually use)

So i thought we could add a generateFile() method to CMessagesource (and its subclasses). so we extract messages using CMessageFinder::extract() and to save them, pass the array to CMessageSource::generateFile().

There are two issues with this approach. First one is that CMessageSource (and derived classes) are explicitly for ‘translating’. generating files doesnt fall into their job.

Second issue is that CDbMessageSource doesnt support such feature.

Now, my questions.

  1. Do you have better ideas about reusing the codes without the mentioned issues or a better API?

  2. Will this change be accepted and merged into yii for next versions?

Thanks.

There is an extension which extracts the messages in po files… I haven’t tried it but it’s worth a shot before build it yourself ;)

Hi

The only related extension i found is pophpcommand which is a command to convert php lang files to po ones. This gives us a little bit of extra complexity.

The way i mentioned would also make it really easy to add po support to yiic message command and make the mentioned extension obsolote.

Hi,

I’m intrested in your web based solution.

Until now I’m using a batch file + MyMessageCommand.php (an extention of MessageCommand Class) + PoPHPCommand.php extention.

Batch File:




call yiic pophp po messages\config.php

call yiic mymessage messages\config.php

for /R messages\ %%i in (*.php_merged) do call move %%i %%~ni.php

call yiic pophp php messages\config.php