/** * Import language specified in parameter fileName * * @service language import * @param Gpf_Rpc_Params $params * @return Gpf_Rpc_Form */ public function importLanguage(Gpf_Rpc_Params $params) { $form = new Gpf_Rpc_Form($params); //Read metadata of file $file = new Gpf_Io_Csv_Reader($form->getFieldValue("fileName"), ';', '"', array('source', 'translation', 'type', 'module', 'status', 'customer')); $file->setMaxLinesToRead(10); $language = new Gpf_Lang_CsvLanguage(); $language->loadFromCsvFile($file); try { $importer = new Gpf_Lang_ImportLanguageTask($form->getFieldValue("fileName"), $language->getCode(), false); $importer->run(); } catch (Gpf_Tasks_LongTaskInterrupt $e) { $form->addField('progress', 'PROGRESS'); $form->setFieldError('progress', $e->getMessage()); $form->setErrorMessage($e->getMessage()); return $form; } $form->setInfoMessage($this->_('%s (%s) imported', $language->getMetaValue(Gpf_Lang_CsvLanguage::LANG_NAME), $language->getMetaValue(Gpf_Lang_CsvLanguage::LANG_ENG_NAME))); return $form; }
/** * 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(); } }