Last active
December 12, 2015 00:28
-
-
Save njasm/91209e1278e14051f555 to your computer and use it in GitHub Desktop.
Simple, and first implementation to Yii translation fallback before raise a CMissingTranslationEvent. ex. from 'pt_PT', fallback to 'pt' and only then raise event if not found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function translateMessage($category,$message,$language) | |
{ | |
$key=$language.'.'.$category; | |
if(!isset($this->_messages[$key])) | |
$this->_messages[$key]=$this->loadMessages($category,$language); | |
if(isset($this->_messages[$key][$message]) && $this->_messages[$key][$message]!=='') | |
return $this->_messages[$key][$message]; | |
// testing fallback translation language. ex. 'pt' instead of 'pt_PT' | |
if (strlen($language) === 5) { | |
$key = substr($language, 0, 2) . "." . $category; | |
$this->_messages[$key] = $this->loadMessages($category, substr($language, 0, 2)); | |
if(isset($this->_messages[$key][$message]) && $this->_messages[$key][$message]!=='') | |
return $this->_messages[$key][$message]; | |
} | |
// end of testing | |
elseif($this->hasEventHandler('onMissingTranslation')) | |
{ | |
$event=new CMissingTranslationEvent($this,$category,$message,$language); | |
$this->onMissingTranslation($event); | |
return $event->message; | |
} | |
else | |
return $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code between '//testing ...' and '// end of testing' was only thing added to original method, nothing more was changed.
take in consideration that testing was only conducted agains php files translation, not tested agains DbMessage translations etc etc..