Example #1
0
 /**
  * Test method.
  *
  * @return void
  */
 public function testDottedExtensionPath()
 {
     $this->assertThat(ExtensionHelper::getExtensionPath('foo.bar'), $this->equalTo('foo'));
 }
Example #2
0
 /**
  * Tears down the fixture, for example, close a network connection.
  * This method is called after a test is executed.
  *
  * @return void
  */
 protected function tearDown()
 {
     ExtensionHelper::cleanCache();
 }
Example #3
0
File: G11n.php Project: elkuku/g11n
 /**
  * Clean the cache directory.
  *
  * @deprecated Use ExtensionHelper::cleanCache()
  *
  * @since  2.1
  * @return void
  */
 public static function cleanCache()
 {
     ExtensionHelper::cleanCache();
 }
Example #4
0
File: Php.php Project: elkuku/g11n
 /**
  * Stores the strings into a storage.
  *
  * @param   string  $lang       E.g. de-DE, es-ES etc.
  * @param   string  $extension  E.g. joomla, com_weblinks, com_easycreator etc.
  * @param   string  $domain     Must be 'admin' or 'site'.
  *
  * @throws G11nException
  * @return string  The path where the language file has been found / empty if it is read from cache.
  */
 public function store($lang, $extension, $domain = '')
 {
     $ext = $this->parser->getExt();
     /*
      * Parse language files
      */
     $fileName = ExtensionHelper::findLanguageFile($lang, $extension, $domain, $ext);
     $fileInfo = $this->parser->parse($fileName);
     $this->fileInfo = $fileInfo;
     /*
      * "Normal" strings
      */
     $stringsArray = array();
     $value = '';
     foreach ($fileInfo->strings as $key => $value) {
         $key = md5($key);
         $value = base64_encode($value->string);
         $stringsArray[] = "'" . $key . "'=>'" . $value . "'";
     }
     /*
      * Plural strings
      */
     $pluralsArray = array();
     foreach ($fileInfo->stringsPlural as $key => $plurals) {
         $key = md5($key);
         $ps = array();
         foreach ($plurals->forms as $keyP => $plural) {
             $value = base64_encode($plural);
             $ps[] = "'" . $keyP . "'=>'" . $value . "'";
         }
         $value = base64_encode($value);
         $pluralsArray[] = "'" . $key . "'=> array(" . implode(',', $ps) . ")";
     }
     /*
      * JavaScript strings
      */
     $jsArray = array();
     $jsPluralsArray = array();
     try {
         $jsFileName = ExtensionHelper::findLanguageFile($lang, $extension, $domain, 'js.' . $ext);
         $jsInfo = $this->parser->parse($jsFileName);
         foreach ($jsInfo->strings as $key => $value) {
             $key = md5($key);
             $value = base64_encode($value->string);
             $jsArray[] = "'" . $key . "'=>'" . $value . "'";
         }
         $jsPluralsArray = array();
         foreach ($jsInfo->stringsPlural as $key => $plurals) {
             $key = md5($key);
             $ps = array();
             foreach ($plurals as $keyP => $plural) {
                 $value = base64_encode($plural);
                 $ps[] = "'" . $keyP . "'=>'" . $value . "'";
             }
             $value = base64_encode($value);
             $jsPluralsArray[] = "'" . $key . "'=> array(" . implode(',', $ps) . ")";
         }
     } catch (\Exception $e) {
         // We did not found the javascript files...
         // Do nothing - for now..@todo do something :P
         echo '';
     }
     /*
      * Process the results - Construct an ""array string""
      * Result:
      * '<?php $strings = array('a'=>'b', ...); ?>'
      */
     $resultString = '<?php ' . '$info=array(' . "'mode'=>'" . $fileInfo->mode . "'" . ",'pluralForms'=>'" . $this->translatePluralForms($fileInfo->pluralForms) . "'" . ");" . ' $strings=array(' . implode(',', $stringsArray) . ');' . ' $stringsPlural=array(' . implode(',', $pluralsArray) . ');' . ' $stringsJs=array(' . implode(',', $jsArray) . ');' . ' $stringsJsPlural=array(' . implode(',', $jsPluralsArray) . ');';
     $storePath = $this->getPath($lang, $extension, $domain) . $this->ext;
     if (false == is_dir(dirname($storePath))) {
         $tmp = umask(0);
         $result = mkdir(dirname($storePath), 0777, true);
         umask($tmp);
         if (false == $result) {
             throw new G11nException('Can not create the cache directory');
         }
     }
     if (!file_put_contents($storePath, $resultString)) {
         throw new G11nException('Unable to write language storage file to ' . $storePath);
     }
     return $fileName;
 }
Example #5
0
 /**
  * Get the language template path.
  *
  * @param   string  $extension  Extension name.
  * @param   string  $scope      Extension scope
  *
  * @return string
  */
 public static function getTemplatePath($extension, $scope)
 {
     static $templates = array();
     if (array_key_exists($extension, $templates) && array_key_exists($scope, $templates[$extension])) {
         return $templates[$extension][$scope];
     }
     $base = ExtensionHelper::getDomainPath($scope);
     $fileName = $extension . '.pot';
     $extensionDir = ExtensionHelper::getExtensionPath($extension);
     return "{$base}/{$extensionDir}/" . ExtensionHelper::$langDirName . "/templates/{$fileName}";
 }