Esempio n. 1
0
 /**
  * (non-PHPdoc)
  *
  * @see \PhraseApp\Synchronize::synchronize()
  */
 public function synchronize()
 {
     $this->read();
     parent::synchronize();
     $this->write();
     return $this;
 }
 /**
  * (non-PHPdoc)
  *
  * @see \PhraseApp\Synchronize\Files\Writer::write()
  */
 public function write(Synchronize $synchronize)
 {
     $translations = $synchronize->getTranslations();
     foreach ($translations as $locale => $translationsLocale) {
         // convert to files
         $translationsByFile = [];
         foreach ($translationsLocale as $key => $content) {
             // split file and key into pices
             $keyParts = array_reverse(array_map('strrev', explode('.', strrev($key), 2)));
             if (count($keyParts) !== 2) {
                 continue;
             }
             // this is our translation key
             $translationKey = $keyParts[1];
             // this is the translation file with path part
             $file = $this->getPath() . $locale . '/' . $keyParts[0] . '.' . $this->getFileExtension();
             // is file in map?
             if (array_key_exists($file, $translationsByFile) === false) {
                 // create map
                 $translationsByFile[$file] = [];
             }
             // store key and content in map
             $translationsByFile[$file][$translationKey] = $content;
         }
         // save to files
         foreach ($translationsByFile as $file => $translationsFile) {
             $path = dirname($file);
             // create path of file
             if (is_dir($path) === false && @mkdir($path, 0777, true) === false) {
                 throw new FailureCreateLocalePath($path, $locale);
             }
             $this->writeFile($file, $translationsFile);
         }
     }
     return true;
 }