/
TranslateModule.php
52 lines (51 loc) · 1.43 KB
/
TranslateModule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class TranslateModule extends CWebModule
{
/**
* the name of the translate component
* change this in case you dont use the default name
* */
static $translateComponentId='translate';
/**
* TranslateModule::init()
*
* @return
*/
public function init(){
$this->defaultController='Translate';
$this->setImport(array(
'translate.models.*',
'translate.controllers.*',
'translate.components.*',
));
return parent::init();
}
/**
* get the translate component
*
* @return MPTranslate
*/
static function translator(){
$component=Yii::app()->getComponent(self::$translateComponentId);
if($component===null)
throw new CException('Translate component must be defined');
return $component;
}
static function __callStatic($method,$args){
return call_user_func_array(array(self::getTranslateComponent(),$method),$args);
}
static function missingTranslation($event){
return self::translator()->missingTranslation($event);
}
/**
* translate some message using the module configuration
*
* @param string $message
* @param array $params
* @return string translated message
*/
static function t($message,$params=array()){
$translator=self::translator();
return Yii::t($translator::ID,$message,$params,'en','en');
}
}