コード例 #1
0
ファイル: modulehelper.class.php プロジェクト: rudenyl/kcms
 /**
 	Get custom (html/text) module translations
 		@private
 	**/
 private static function __translate(&$item, $section = 'custom', $skip_enable_checking = false)
 {
     if (empty($item)) {
         return false;
     }
     $params = json_decode($item->params);
     $serialized = $params !== null;
     if (!$serialized) {
         $params = new Parameter(@$item->params);
     }
     // get active lang
     $active_lang = I18N::getCurrentLanguage();
     if (!$skip_enable_checking) {
         $translation_opt = $serialized ? @$params->translation : @json_decode($params->get('translation'));
         // check enabled
         $lang_enabled = isset($translation_opt->{"{$active_lang}"}) ? $translation_opt->{$active_lang}->enabled : false;
         if ($lang_enabled && isset($translation_opt->{$active_lang})) {
             foreach (get_object_vars($translation_opt->{$active_lang}) as $k => $v) {
                 if (strpos($k, 'params__') !== false && isset($item->params)) {
                     $k = str_replace('params__', '', $k);
                     if ($serialized) {
                         $params->{$k} = $v;
                     } else {
                         $params->set($k, $v);
                     }
                 } else {
                     $item->{$k} = $v;
                 }
             }
             /**/
             $item->params = $serialized ? json_encode($params) : $params->toString();
         }
     } else {
         $lang_enabled = true;
     }
     if ($lang_enabled) {
         $lang_map = array();
         $active_lang = empty($active_lang) ? I18N::getDefaultLanguage() : $active_lang;
         // get translation map
         $map_data = I18N::getTranslationMapKeyValuePair(array('section' => 'default.modules.' . $section, 'id' => $item->id), 'lang_code');
         if (isset($map_data[$active_lang])) {
             $lang_map = $map_data[$active_lang];
         }
         if ($lang_map) {
             // translate
             foreach ($lang_map as $k => $v) {
                 if (isset($item->{$k}) && !empty($v)) {
                     $item->{$k} = $v;
                 }
             }
         }
     }
 }