Basically this was not designed to be an extension but rather a tool for development stage where you do not want to manually add every single language string into the database messages table for each language you need the application to be translated to.
So what this does is basically a class that runs when the onMissingTranslation event raises and it checks if the message being translated exists in the source table, If not it adds it to the source messages table if it is then it skips this stage, The next stage is to check if this message exists in the messages table with the currently used language if it is then nothing is done if not then the message is added to the messages table for translation.
Note: It is highly recommended NOT to use this on a production environment as it run two queries for each message to check if it exists or not, Since i didn't plan this to be optimized and made this as a personal tool i have no plans updating this currently and is only released to help who ever needs such tool.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract the 'MissingMessages.php' file in a directory you have imported.
- Extract the 'SourceMessage.php' & 'Message.php' Model files under your models directory or any other directory your application imports it's contents.
Usage ¶
Just add the following line to the 'messages' component array
'onMissingTranslation' => array('MissingMessages', 'load')
So it looks like this:
'messages' => array(
'onMissingTranslation' => array('MissingMessages', 'load')
),
Change Log ¶
May 2, 2010 ¶
- Initial release.
Works fine
Thanks - very useful for development. Well done.
Infinite loop
I had trouble because my Message and SourceMessage Classes had Yii::t() calls so i get infinite loops calling onMissingTranslation callback.
Solution : Deactivate the event handling inside missingTranslation function, then reactive it at the end of the function.
public static function missingTranslation($event) { // detachement du composant pour éviter boucles infinies,réattaché la fin Yii::app()->messages->detachEventHandler('onMissingTranslation', array('MissingMessages', 'missingTranslation')); ... Yii::app()->messages->attachEventHandler('onMissingTranslation', array('MissingMessages', 'missingTranslation')); }
Thanks for sharing, it was a good base for my needs :)
it occured... nothing...
Does it work for you? I have any message stored in the database, not error message... when few time ago was working. Can be Yii issue?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.