/** * Load default language for this account * * @return Gpf_Db_Language */ public function getDefaultLanguage() { if ($this->defaultLanguage == null) { $this->defaultLanguage = new Gpf_Db_Language(); $this->defaultLanguage->setIsDefault(true); $this->defaultLanguage->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId()); $this->defaultLanguage->loadFromData(array(Gpf_Db_Table_Accounts::ID, self::IS_DEFAULT)); } return $this->defaultLanguage; }
public function regenerateLanguageCacheFiles() { //load langage $dbLang = new Gpf_Db_Language(); $dbLang->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId()); $dbLang->setCode($this->languageCode); $dbLang->setId($dbLang->generateId()); $dbLang->load(); $lang = new Gpf_Lang_CsvLanguage(); $lang->loadFromCsvFile(new Gpf_Io_Csv_Reader(Gpf_Lang_CsvLanguage::getAccountCsvFileName($this->languageCode))); $lang->exportAccountCache(); }
/** * * @return Gpf_Db_Language */ private function loadLanguage() { $lang = new Gpf_Db_Language(); $lang->setCode($this->langcode); $lang->setAccountId(Gpf_Application::getInstance()->getAccountId()); $lang->setId($lang->generateId()); try { $lang->load(); } catch (Exception $e) { } return $lang; }
/** * Create new language * * @service language add * @return Gpf_Rpc_Form */ public function add(Gpf_Rpc_Params $params) { $form = new Gpf_Rpc_Form($params); $lang = new Gpf_Db_Language(); $lang->setCode($form->getFieldValue(Gpf_Db_Table_Languages::CODE)); $lang->setAccountId(Gpf_Application::getInstance()->getAccountId()); $lang->setId($lang->generateId()); try { //Load should fail, otherwise it is error - language already exists $lang->load(); $form->setErrorMessage($this->_('Language code %s is already used in your installation', $form->getFieldValue(Gpf_Db_Table_Languages::CODE))); return $form; } catch (Exception $e) { } try { //Load language from default csv file $fileNameDefault = Gpf_Paths::getInstance()->getLanguageInstallDirectory() . Gpf_Application::getInstance()->getCode() . '_' . Gpf_Lang_CsvHandler::DEFAULT_LANGUAGE . '.csv'; $file = new Gpf_Io_Csv_Reader($fileNameDefault, ';', '"', array('source', 'translation', 'type', 'module', 'status', 'customer')); $csvLanguage = new Gpf_Lang_CsvLanguage(); $csvLanguage->loadFromCsvFile($file); $form->fill($lang); $lang->setAccountId(Gpf_Application::getInstance()->getAccountId()); $lang->setId($lang->generateId()); $lang->setActive(true); $lang->setTranslatedPercentage(0); $lang->insert(); //update metadata $csvLanguage->copyMetadataFromDbLanguage($lang); foreach ($csvLanguage->getTranslations() as $translation) { $translation->setStatus(Gpf_Lang_Parser_Translation::STATUS_NOT_TRANSLATED); } //export cache $csvLanguage->exportAccountCache(); } catch (Exception $e) { $form->setErrorMessage($this->_('Failed to create new language: %s', $e->getMessage())); return $form; } $form->setInfoMessage($this->_('New language with code %s created', $form->getFieldValue(Gpf_Db_Table_Languages::CODE))); return $form; }