/**
  * Sets translation in database
  *
  * @param string $codeName the code naeme to add/update/delete
  * @param array $translationList array like array('en' => 'enValue', 'fr' => 'deValue')
  */
 public static function setTranslations($codeName, $translationList)
 {
     if (empty($translationList)) {
         return;
     }
     foreach ($translationList as $language => $translation) {
         // If translation text is null, removes the entry
         if ($translation === NULL) {
             ElementFactory::deleteElementList('Translation', 'translation_text=\'' . $codeName . '\' AND translation_language=\'' . $language . '\'');
             continue;
         }
         try {
             $translationElement = ElementFactory::getElement('Translation', NULL, 'translation_text=\'' . $codeName . '\' AND translation_language=\'' . $language . '\'');
             $translationElement->value = $translation;
             $translationElement->update();
         } catch (ElementNoResultException $e) {
             $translationElement = new Translation();
             $translationElement->language = $language;
             $translationElement->text = $codeName;
             $translationElement->value = $translation;
             $translationElement->add();
         }
     }
 }
예제 #2
0
 function onSubmit($vals)
 {
     $collection = $vals['_collection'];
     $status = $vals['_status'];
     $key = $vals['_key'];
     $lang = $vals['_lang'];
     unset($vals['_collection']);
     unset($vals['_status']);
     unset($vals['_key']);
     unset($vals['_lang']);
     unset($vals['_header']);
     unset($vals['submit_button']);
     foreach ($vals as $k => $v) {
         if (empty($v)) {
             unset($vals[$k]);
         }
     }
     $tr = new Translation($collection, $lang);
     $id = $tr->getID($key);
     if (!$id) {
         $tr->add($key, $status, $vals);
     } else {
         $tr->save($key, $status, $vals);
     }
     page_title(intl_get('Translation Saved'));
     echo '<p><a href="' . site_prefix() . '/index/multilingual-app">' . intl_get('Continue') . '</a></p>';
 }