Exemple #1
0
 public function testGetTranslations_shouldReturnEmptyArray()
 {
     $root = vfsStream::setup('root');
     $root->addChild(new vfsStreamFile('language.php'));
     $obj = new Language_File(vfsStream::url('root/language.php'));
     $this->assertEquals(array(), $obj->getTranslations());
 }
Exemple #2
0
 /**
  * Update language.php file with new strings.
  * 
  * @param array $strings English strings collected from source files
  * @param bool $outputFiles whether file paths were string was found should be included or not in the output
  * @return null
  */
 public function writeStringsToFile(array $strings, $outputFiles = false)
 {
     if (empty($strings)) {
         return false;
     }
     // backup original language file
     copy($this->filePath, $this->filePath . '.old');
     $this->translations = $this->parseFile->getTranslations();
     $entries = $this->mergeStringsWithTranslations($strings, $this->translations);
     $handle = fopen($this->tmpFilePath, 'w');
     if ($handle) {
         fwrite($handle, "<?php\n");
         fwrite($handle, $this->fileHeader());
         fwrite($handle, "\$lang = array(\n");
         foreach ($entries as $entry) {
             fwrite($handle, $this->formatString($entry, $outputFiles));
         }
         fwrite($handle, ");\n");
         fclose($handle);
     }
     rename($this->tmpFilePath, $this->filePath);
 }