/**
  * Retrieve data from file
  *
  * @param   string $file
  * @return  array
  */
 protected function _getFileData($file)
 {
     $data = array();
     if (file_exists($file)) {
         $parser = new Varien_File_Csv();
         $parser->setDelimiter(self::CSV_SEPARATOR);
         $data = $parser->getDataPairs($file);
     }
     return $data;
 }
 public function csvAction()
 {
     $dump = Mage::helper('pdfinvoiceplus/localization')->translate('Shipping & Handling');
     zend_debug::dump($dump);
     die;
     $p = 'magestore\\pdfinvoiceplus\\localization\\localization_england.csv';
     $path = str_replace(array('\\', '/'), DS, $p);
     $file = Mage::getBaseDir('media') . DS . $path;
     $csv = new Varien_File_Csv();
     $data = $csv->getDataPairs($file);
     zend_debug::dump($data);
     die;
     //        die($file);
     $csv = scandir($file);
     $data = array();
     foreach ($csv as $file) {
         if (preg_match('/^localization/', $file)) {
             $data[] = $file;
         }
     }
     zend_debug::dump($data);
     die;
     for ($i = 1; $i < count($data); $i++) {
         var_dump($data[$i]);
     }
 }
示例#3
0
 /**
  * Get data from csv file
  *
  * @param string $file
  * @return array
  */
 protected function getFileData($file)
 {
     $parser = new Varien_File_Csv();
     return $parser->getDataPairs($file);
 }
示例#4
0
 /**
  * Do the export.
  */
 public function exportAction()
 {
     Mage::log("TranslationExporter: Export started");
     $translate = Mage::getSingleton('core/translate');
     $locale = $translate->getLocale();
     $baseFolder = $locale . '_base';
     $targetDir = Mage::getBaseDir('var') . DS . 'translations' . DS . $locale;
     $localeDir = Mage::getBaseDir('locale');
     Mage::log("TranslationExporter - target directory: {$targetDir}");
     $dbtrans = $translate->getResource()->getTranslationArray(null, $locale);
     Mage::log("TranslationExporter: " . count($dbtrans) . " translation rows from DB");
     // for each module:
     // - for each CSV file in that module:
     //   1. read it to memory
     //   2. modify it according to DB translation for that module
     //   3. write it back to dest dir
     $parser = new Varien_File_Csv();
     $parser->setDelimiter(Mage_Core_Model_Translate::CSV_SEPARATOR);
     foreach ($translate->getModulesConfig() as $moduleName => $info) {
         $info = $info->asArray();
         Mage::log("TranslationExporter: Exporting module {$moduleName}");
         foreach ($info['files'] as $file) {
             $enData = array();
             $enFilePath = $localeDir . DS . 'en_US' . DS . $file;
             if (file_exists($enFilePath)) {
                 $enData = $parser->getDataPairs($enFilePath);
             }
             $baseData = array();
             $baseFilePath = $localeDir . DS . $baseFolder . DS . $file;
             if (file_exists($baseFilePath)) {
                 $baseData = $parser->getDataPairs($baseFilePath);
             }
             foreach ($baseData as $key => $val) {
                 if (isset($enData[$key]) && $enData[$key] !== $val) {
                     $enData[$key] = $val;
                 }
             }
             $data = array();
             $filePath = $localeDir . DS . $locale . DS . $file;
             Mage::log("TranslationExporter: Reading {$filePath}");
             if (file_exists($filePath)) {
                 $data = $parser->getDataPairs($filePath);
             }
             foreach ($data as $key => $val) {
                 if (isset($enData[$key]) && $enData[$key] !== $val) {
                     $enData[$key] = $val;
                 }
             }
             // 2. MODIFY
             foreach ($enData as $key => $val) {
                 $fullKey = $moduleName . '::' . $key;
                 if (isset($dbtrans[$fullKey])) {
                     $stack[] = $fullKey;
                     Mage::log("TranslationExporter: Rewrite '{$fullKey}' from '{$val}' to '{$dbtrans[$fullKey]}'");
                     $enData[$key] = $dbtrans[$fullKey];
                 }
             }
             // 3. WRITE
             if (!file_exists($targetDir)) {
                 if (!mkdir($targetDir, 0777, true)) {
                     throw new Exception("Cannot create {$targetDir}");
                 }
             }
             $targetFile = $targetDir . '/' . $file;
             $parser = new Varien_File_Csv();
             $csvdata = array();
             foreach ($enData as $key => $val) {
                 $csvdata[] = array($key, $val);
             }
             $parser->saveData($targetFile, $csvdata);
             Mage::log("TranslationExporter: wrote {$targetFile}");
         }
         Mage::log("TranslationExporter: Done.");
     }
     Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('compiler')->__("Translations has been exported to '%s'.", $targetDir));
     $this->_redirect('*/*/');
 }