/**
  * 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();
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
         }
     }
 }