public function loadModel($category, $message, $language = null)
 {
     $model = YumTranslation::model()->find('category = :category and message = :message and language = :language', array(':category' => $category, ':message' => $message, ':language' => $language));
     if ($model === null) {
         $translation = new YumTranslation();
         $translation->category = $category;
         $translation->message = $message;
         $translation->language = $language;
         return $translation;
     }
     return $model;
 }
Пример #2
0
	/** Fetch the translation string from db and cache when necessary */
	public static function t($string, $params = array(), $category = 'yum')
	{
		$language = Yii::app()->language;

		$cache_id = sprintf('yum_translations_%s_%s', $language, $category);

		$messages = false;
		if(Yii::app()->cache)
			$messages = Yii::app()->cache->get($cache_id);

		if($messages===false) {
			if(Yum::module()->avoidSql) {
				$translations = YumTranslation::model()->findAll('category = :category and language = :language', array(
							'category' =>  $category,
							'language' =>  $language,
							));
				$messages=array();
				foreach($translations as $row)
					$messages[$row['message']]=$row->translation;
			} else {
				$translationTable = Yum::module()->translationTable;
				$sql = "select message, translation from {$translationTable} where language = :language and category = :category";

				$command=Yii::app()->db->createCommand($sql);
				$command->bindValue(':category',$category);
				$command->bindValue(':language',$language); 

				$messages=array();
				foreach($command->queryAll() as $row)
					$messages[$row['message']]=$row['translation'];
			}

			if(Yii::app()->cache)
				Yii::app()->cache->set($cache_id, $messages);
		}

		if(isset($messages[$string]))
			return strtr($messages[$string], $params);
		else 
			return strtr($string, $params);
	}