Esempio n. 1
0
 protected function _loadTranslationData($data = null, $locale, array $options = array())
 {
     $list = new Translation_Website_List();
     $list->load();
     foreach ($list->getTranslations() as $translation) {
         if ($translation instanceof Translation_Abstract) {
             foreach ($translation->getTranslations() as $language => $text) {
                 $this->_translate[$language][$translation->getKey()] = Pimcore_Tool_Text::removeLineBreaks($text);
             }
         }
     }
     $availableLanguages = (array) Pimcore_Tool::getValidLanguages();
     foreach ($availableLanguages as $language) {
         if (!array_key_exists($language, $this->_translate) || empty($this->_translate[$language])) {
             $this->_translate[$language] = array("__pimcore_dummy" => "only_a_dummy");
         }
     }
     return $this->_translate;
 }
Esempio n. 2
0
 public function translationsAction()
 {
     $admin = $this->_getParam("admin");
     if ($this->getUser()->isAllowed("translations")) {
         // clear translation cache
         Pimcore_Model_Cache::clearTags(array("translator", "translate"));
         if ($this->_getParam("data")) {
             if ($this->_getParam("xaction") == "destroy") {
                 $key = Zend_Json::decode($this->_getParam("data"));
                 if ($admin) {
                     $t = Translation_Admin::getByKey($key);
                 } else {
                     $t = Translation_Website::getByKey($key);
                 }
                 $t->delete();
                 $this->_helper->json(array("success" => true, "data" => array()));
             } else {
                 if ($this->_getParam("xaction") == "update") {
                     $data = Zend_Json::decode($this->_getParam("data"));
                     if ($admin) {
                         $t = Translation_Admin::getByKey($data["key"]);
                     } else {
                         $t = Translation_Website::getByKey($data["key"]);
                     }
                     foreach ($data as $key => $value) {
                         if ($key != "key") {
                             $t->addTranslation($key, $value);
                         }
                     }
                     if ($data["key"]) {
                         $t->setKey($data["key"]);
                     }
                     $t->save();
                     $return = array_merge(array("key" => $t->getKey(), "date" => $t->getDate()), $t->getTranslations());
                     $this->_helper->json(array("data" => $return, "success" => true));
                 } else {
                     if ($this->_getParam("xaction") == "create") {
                         $data = Zend_Json::decode($this->_getParam("data"));
                         if ($admin) {
                             $t = new Translation_Admin();
                         } else {
                             $t = new Translation_Website();
                         }
                         $t->setKey($data["key"]);
                         $t->setDate(time());
                         foreach ($data as $key => $value) {
                             if ($key != "key" && $key != "date") {
                                 $t->addTranslation($key, $value);
                             }
                         }
                         $t->save();
                         $return = array_merge(array("key" => $t->getKey(), "date" => $t->getDate()), $t->getTranslations());
                         $this->_helper->json(array("data" => $return, "success" => true));
                     }
                 }
             }
         } else {
             // get list of types
             if ($admin) {
                 $list = new Translation_Admin_List();
             } else {
                 $list = new Translation_Website_List();
             }
             $list->setOrder("asc");
             $list->setOrderKey("key");
             if ($this->_getParam("dir")) {
                 $list->setOrder($this->_getParam("dir"));
             }
             if ($this->_getParam("sort")) {
                 $list->setOrderKey($this->_getParam("sort"));
             }
             $list->setLimit($this->_getParam("limit"));
             $list->setOffset($this->_getParam("start"));
             if ($this->_getParam("filter")) {
                 $filterTerm = $list->quote("%" . strtolower($this->_getParam("filter")) . "%");
                 $list->setCondition("lower(`key`) LIKE " . $filterTerm . " OR `text` LIKE " . $filterTerm);
             }
             $list->load();
             $translations = array();
             foreach ($list->getTranslations() as $t) {
                 $translations[] = array_merge(array("key" => $t->getKey(), "date" => $t->getDate()), $t->getTranslations());
             }
             $this->_helper->json(array("data" => $translations, "success" => true, "total" => $list->getTotalCount()));
         }
     } else {
         Logger::err("user [" . $this->getUser()->getId() . "] attempted to access translations, but has no permission to do so.");
     }
     $this->_helper->json(false);
 }