Log not found translations

I’ve already read about raising events, but to be honest, I have my difficulties understanding the set up process. As I’m developing a multilingual website, I’d like to know if I’ve forgotten a translation.

A few months ago, I already wrote a little helper tool which analyses the differences between all translation files. But if a translation is non existent in any of the files, this tool doesn’t recognize it.

So could you please write a short example for me how and where to listen to the missing translation event?

Thank you very much :)

You should attach a event handler before the event ist raised. Since ‘messages’ is an application component, you can configure that e.g. in the main.php config:


    'components'=>array(

        'messages'=>array(

            'onMissingTranslation'=>array('MyClass','mymethod'),

        ),



Now if you supply MyClass somewhere, MyClass::mymethod() will get called, when the event is raised. There are different ways you can specify the event handler, see API for CComponent.

Works perfectly, thanks, Mike!

Due to a lack of creativity I used MyClass and mymethod ;) Now every missing translation is thrown into a table:

Table structure:

  • language (CHAR 2)

  • category (VARCHAR(64)

  • message (TEXT)




<?php

class MyClass

{

    public function mymethod(CMissingTranslationEvent $event)

    {

        $db = new ListMissingTranslation;

        $db->attributes = (array) $event;

        $db->save(false);

    }

}



Later versions may translate it automatically via google’s translate api.