Yii Framework Forum: Log not found translations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Log not found translations If a translation could not be found, write it into a log file Rate Topic: -----

#1 User is offline   mintao 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 02-December 09
  • Location:Munich, Germany

Posted 08 May 2010 - 06:10 AM

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 :)
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 08 May 2010 - 07:18 AM

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.
1

#3 User is offline   mintao 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 02-December 09
  • Location:Munich, Germany

Posted 08 May 2010 - 11:37 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users