Question

I am developing a project in Yii multi language and i done setting up the language files , now i need to fetch english message if any translation is missing in current language file. my file structure is :

-> protected

 -> messages

    ->en -> main.php

    ->nl -> main.php etc...
Was it helpful?

Solution

Try this

Add this in your config/main.php in components array.

'messages' => array(
        'onMissingTranslation' => array('MessageHelper', 'textMissingTranslation'),
    ),

Create a file MessageHelper.php in components and add the below code in it

class MessageHelper
{
  public static function textMissingTranslation($event)
   {
     $var = include( Yii::getPathOfAlias( 'application.messages.en.main').'.php' );        
     return $event->message = $var[$event->message];
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top