示例#1
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     $this->addModule('system_messages', 'SharedSystemMessages');
     $this->setLayout('i18n/status.tpl');
     // Instance navigation.
     $current_instance_inheritance = \Sifo\Domains::getInstance()->getInstanceInheritance();
     $this->assign('current_instance_inheritance', $current_instance_inheritance);
     // Get instance name.
     $params = $this->getParams();
     $instance = $this->instance;
     if (isset($params['params'][0])) {
         $instance = $params['params'][0];
     }
     // Get selected instance inheritance.
     $instance_domains = $this->getConfig('domains', $instance);
     $instance_inheritance = array();
     if (isset($instance_domains['instance_inheritance'])) {
         $instance_inheritance = $instance_domains['instance_inheritance'];
     }
     $is_parent_instance = false;
     if (empty($instance_inheritance) || count($instance_inheritance) == 1 && $instance_inheritance[0] == 'common') {
         $is_parent_instance = true;
     }
     $translator = new I18nTranslatorModel();
     $different_languages = $translator->getStats($instance, $is_parent_instance);
     $current_lang = $this->getCurrentLang();
     $translations = false;
     $this->assign('langs', $different_languages);
     // The languages are defined with 5 chars. E.g: es_ES
     if ($current_lang && 5 == strlen($current_lang)) {
         $translations = $translator->getTranslations($current_lang, $instance, $is_parent_instance);
     }
     $this->assign('instance', $instance);
     $this->assign('instance_inheritance', $instance_inheritance);
     $this->assign('is_parent_instance', $is_parent_instance);
     $this->assign('different_languages', $different_languages);
     $this->assign('translations', $translations);
     $this->assign('curr_lang', $current_lang);
     $this->assign('can_edit', $this->canEdit());
     $this->assign('isAdmin', $this->isAdmin());
 }
示例#2
0
 /**
  * Customize translation.
  * @return mixed
  */
 protected function customizeTranslation()
 {
     $message = \Sifo\FilterPost::getInstance()->getString('msgid');
     $id_message = null;
     if (is_numeric($message)) {
         $id_message = $message;
     }
     $instance = $this->getParsedParam('instance');
     $translator_model = new I18nTranslatorModel();
     $id_message = $translator_model->getTranslation($message, $id_message);
     $result = array('status' => 'KO', 'msg' => 'This Message or ID doesn\'t exist.');
     if ($id_message) {
         $result = array('status' => 'OK', 'msg' => 'Message successfully customized.');
         if (!$translator_model->customizeTranslation($id_message, $instance)) {
             $result = array('status' => 'KO', 'msg' => 'This message is already customized in this instance.');
         }
     }
     return $result;
 }
示例#3
0
 public function build()
 {
     if (!\Sifo\Domains::getInstance()->getDevMode()) {
         throw new \Sifo\Exception_404('Translation only available while in devel mode');
     }
     $translator = new I18nTranslatorModel();
     // Get instance name.
     $params = $this->getParams();
     $instance = $this->instance;
     if (isset($params['params'][0])) {
         $instance = $params['params'][0];
     }
     // Get selected instance inheritance.
     $instance_domains = $this->getConfig('domains', $instance);
     $instance_inheritance = array();
     if (isset($instance_domains['instance_inheritance'])) {
         $instance_inheritance = $instance_domains['instance_inheritance'];
     }
     $is_parent_instance = false;
     if (empty($instance_inheritance) || count($instance_inheritance) == 1 && $instance_inheritance[0] == 'common') {
         $is_parent_instance = true;
     }
     // Get languages.
     $langs_in_DB = $translator->getDifferentLanguages();
     foreach ($langs_in_DB as $l) {
         $language_list[] = $l['l10n'];
     }
     foreach ($language_list as $language) {
         $language_str = $translator->getTranslations($language, $instance, $is_parent_instance);
         foreach ($language_str as $str) {
             $msgid = $str['message'];
             $msgstr = $str['translation'] == null ? '' : $str['translation'];
             $translations[$msgid][$language] = $msgstr;
         }
         unset($language_str);
     }
     ksort($translations);
     $failed = array();
     $result = true;
     foreach ($language_list as $language) {
         $buffer = '';
         $empty_strings_buffer = '';
         $empty[$language] = 0;
         foreach ($translations as $msgid => $msgstr) {
             $msgstr[$language] = isset($msgstr[$language]) ? trim($msgstr[$language]) : null;
             if (!empty($msgstr[$language])) {
                 $item = $this->buildItem($msgid, $msgstr[$language]);
                 $buffer .= $item;
             } else {
                 $item = $this->buildItem($msgid, $msgid);
                 $empty[$language]++;
                 $empty_strings_buffer .= $item;
             }
         }
         // Get instance inheritance.
         $include_parent_instance = $this->getIncludeInheritance($instance, $language);
         $buffer = "<?php\n{$include_parent_instance}\n\n\n// Translations file, lang='{$language}'\n// Empty strings: {$empty[$language]}\n{$empty_strings_buffer}\n// Completed strings:\n{$buffer}\n?>";
         $path = ROOT_PATH . '/instances/' . $instance . '/locale/messages_' . $language . '.php';
         $write = @file_put_contents($path, $buffer);
         if (!$write) {
             $failed[] = $language;
         }
         $result = $result && $write;
     }
     if ($result) {
         return array('status' => 'OK', 'msg' => 'Successfully saved');
     }
     return array('status' => 'KO', 'msg' => 'Failed to save the translation:' . implode("\n", $failed));
 }