/** * Add parsed message to list of found messages * * @param string $sourceMessage * @param Gpf_Io_File $file * @param $type Type of message (server/client/both) */ private function addMessage($sourceMessage, Gpf_Io_File $file, $type) { if (in_array($file->getExtension(), array('java', 'php'))) { @eval("\$sourceMessage = {$sourceMessage};"); } if (!strlen($sourceMessage)) { throw new Gpf_Exception($this->_('Source message can\'t be empty in file %s', $file->getFileName())); } $translation = new Gpf_Lang_Parser_Translation(); $translation->setSourceMessage($sourceMessage); if (array_key_exists($translation->getId(), $this->sourceTranslations)) { $translation = $this->sourceTranslations[$translation->getId()]; } $translation->setCustomerSpecific(false); $translation->setType($type); $translation->addModule($this->handler->getModule($file)); $this->sourceTranslations[$translation->getId()] = $translation; }
/** * @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; }
/** * If exists language with this code in account directory, load custom translations * * @param $language */ private function loadCustomTranslations(Gpf_Lang_CsvLanguage $language) { $origFileName = Gpf_Lang_CsvLanguage::getAccountCsvFileName($language->getCode()); $file = new Gpf_Io_File($origFileName); if ($file->isExists()) { $file = new Gpf_Io_Csv_Reader($origFileName); foreach ($file as $record) { switch ($record->get('type')) { case 'M': //Metadata - no processing required break; case '': //empty row - no processing required break; default: try { $translation = new Gpf_Lang_Parser_Translation(); $translation->loadFromRecord($record); if (!$language->existTranslation($translation) && $translation->isCustomerSpecific() == Gpf::YES) { //add missing customer translation from current account language $language->addTranslation($translation); } else { //replace custom translation with own text even if it was already in file $existingTranslation = $language->getTranslation($translation); if ($translation->isCustomerSpecific() == Gpf::YES) { //keep custom translation from existing language file ! $existingTranslation->setDestinationMessage($translation->getDestinationMessage()); $existingTranslation->setCustomerSpecific($translation->isCustomerSpecific()); } } } catch (Exception $e) { } break; } } $file->close(); } }
/** * Load language from csv file * * @param Gpf_Io_Csv_Reader $file */ public function loadFromCsvFile(Gpf_Io_Csv_Reader $file, $metaOnly = false) { foreach ($file as $record) { switch ($record->get('type')) { case 'M': //Metadata $this->setMetaData($record->get('source'), $record->get('translation')); break; case '': //empty row break; default: if ($metaOnly) { return; } try { $translation = new Gpf_Lang_Parser_Translation(); $translation->loadFromRecord($record); $this->addTranslation($translation); } catch (Exception $e) { } break; } } }