Generate Yii translation message files

前端 未结 3 1742
温柔的废话
温柔的废话 2021-01-31 21:37

I am interested to know is there a script or otherway available to collect and generate Yii translation messages in a controller/project

Eg. If I have the following code

3条回答
  •  攒了一身酷
    2021-01-31 21:53

    I could give you input how to start and you can write your own script. I found this good for me for now :)

    Create component components/Translation.php

    public function missing($messageEvent) {        
        Yii::log(
            "'".$messageEvent->message."' => '',",
            'translation',
            $messageEvent->category.'.'.$messageEvent->language
        );
    }
    

    }

    Edit configuration file config/main.php

    'components' => array(
          //...
          'log' => array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'translation',
                    'logFile'=>'translations.log',
                ),
                //...                
          ),
    
           'messages' => array(
                //'class' => 'CDbMessageSource',
                'onMissingTranslation' => array('Translation', 'missing'),
                //'sourceMessageTable' => 'source_message',
                //'translatedMessageTable' => 'message'
           ),
    )
    

    Result

    You will end up with translation.php file in your log file directory and file contents will be something like:

     2012/06/28 09:45:00 [translation] [Site.lv] 'MyStringInSource' => '',
     ....
    

    depending on your configuration. So you can copy 'MyStringInSource' => '', part and put in corresponding translation file.

    This is helpful in development process because it will grow translation.log file with missing translation (repeatedly) until you translate these.

    Hope it gives you idea.

提交回复
热议问题