protected function execute()
 {
     $lang = $this->loadLanguage();
     $file = new Gpf_Io_Csv_Reader($this->fileName, ';', '"', array('source', 'translation', 'type', 'module', 'status', 'customer'));
     $this->language = new Gpf_Lang_CsvLanguage();
     $this->language->loadFromCsvFile($file);
     $pendingMessage = $this->_('Importing language dictionary %s (%s)', $this->language->getMetaValue(Gpf_Lang_CsvLanguage::LANG_NAME), $this->language->getMetaValue(Gpf_Lang_CsvLanguage::LANG_ENG_NAME));
     if ($this->saveMetadata) {
         if ($this->isPending('saveMetadata', $pendingMessage)) {
             $this->saveLanguageMetadata($lang);
             $this->setDone();
         }
     }
     if ($this->isPending('loadCustomTranslations', $pendingMessage)) {
         $this->loadCustomTranslations($this->language);
         $this->setDone();
     }
     if ($this->isPending('backupOriginalTranslation', $pendingMessage)) {
         $this->backupOriginalTranslation($this->language);
         $this->setDone();
     }
     if ($this->isPending('exportCache', $this->_('Exporting dictionary cache.'))) {
         $this->language->exportAccountCache();
         $this->setDone();
     }
 }
 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();
 }
 /**
  * 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;
 }
 /**
  * @service language write
  * @return Gpf_Rpc_Action
  */
 public function saveFields(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     $action->setErrorMessage($this->_('Failed to save %s field(s)'));
     $action->setInfoMessage($this->_('%s field(s) successfully saved'));
     $language = new Gpf_Db_Language();
     $language->setId($action->getParam(Gpf_Db_Table_Languages::ID));
     $language->load();
     $csvFile = new Gpf_Io_Csv_Reader(Gpf_Lang_CsvLanguage::getAccountCsvFileName($language->getCode()));
     $csvLanguage = new Gpf_Lang_CsvLanguage();
     $csvLanguage->loadFromCsvFile($csvFile);
     $fields = new Gpf_Data_RecordSet();
     $fields->loadFromArray($action->getParam("fields"));
     foreach ($fields as $field) {
         $translation = new Gpf_Lang_Parser_Translation();
         $translation->setSourceMessage($field->get('id'));
         if ($csvLanguage->existTranslation($translation)) {
             $existingTranslation = $csvLanguage->getTranslation($translation);
             if ($existingTranslation->getStatus() == Gpf_Lang_Parser_Translation::STATUS_NOT_TRANSLATED) {
                 $existingTranslation->setStatus(Gpf_Lang_Parser_Translation::STATUS_TRANSLATED);
                 $csvLanguage->incrementTranslatedCount();
             }
             $existingTranslation->set($field->get("name"), $this->sourceCodeSpecialChars($field->get("value")));
         }
         $action->addOk();
     }
     $csvLanguage->exportAccountCache();
     $language->setTranslatedPercentage($csvLanguage->getTranslationPercentage());
     $language->save();
     return $action;
 }
 /**
  * Rebuild cache for language defined by id
  *
  * @param $languageId
  */
 public static function rebuildLanguageCache($languageId)
 {
     $lang = new Gpf_Db_Language();
     $lang->setId($languageId);
     $lang->load();
     $fileName = Gpf_Lang_CsvLanguage::getAccountCsvFileName($lang->getCode());
     $csvLang = new Gpf_Lang_CsvLanguage();
     $csvLang->loadFromCsvFile(new Gpf_Io_Csv_Reader($fileName));
     $csvLang->copyMetadataFromDbLanguage($lang);
     $csvLang->exportAccountCache();
 }