Пример #1
0
 /**
  * loadAllFromPath
  *
  * @param   string $path
  * @param   string $format
  * @param   string $package
  */
 public static function loadAllFromPath($path, $format, $package = null)
 {
     $config = Ioc::getConfig();
     $locale = $config['language.locale'] ?: 'en-GB';
     $default = $config['language.default'] ?: 'en-GB';
     $locale = LanguageNormalize::toLanguageTag($locale);
     $default = LanguageNormalize::toLanguageTag($default);
     $localePath = $path . '/' . $locale;
     $files = array();
     if (is_dir($localePath)) {
         $files = array_merge($files, (array) Folder::files($localePath, false, Folder::PATH_BASENAME));
     }
     $defaultPath = $path . '/' . $default;
     if (is_dir($defaultPath)) {
         $files = array_merge($files, (array) Folder::files($defaultPath, false, Folder::PATH_BASENAME));
     }
     foreach ($files as $file) {
         $ext = File::getExtension($file);
         if (strcasecmp($ext, $format) !== 0) {
             continue;
         }
         Translator::loadFile(File::stripExtension($file), strtolower($format), $package);
     }
 }
Пример #2
0
 /**
  * Method to test toLanguageKey().
  *
  * @param string $origin
  * @param string $expected
  *
  * @return void
  *
  * @covers Windwalker\Language\LanguageNormalize::toLanguageKey
  *
  * @dataProvider getToTagCases
  */
 public function testToLanguageKey($origin, $expected)
 {
     $this->assertEquals($expected, LanguageNormalize::toLanguageKey($origin));
 }
Пример #3
0
 /**
  * getLocalise
  *
  * @param string $locale
  *
  * @return  LocaliseInterface
  */
 protected function getLocalise($locale = 'en-GB')
 {
     $locale = LanguageNormalize::toLanguageTag($locale);
     if (empty($this->localises[$locale]) || !$this->localises[$locale] instanceof LocaliseInterface) {
         $tag = LanguageNormalize::getLocaliseClassPrefix($this->locale);
         $class = sprintf('Windwalker\\Language\\Localise\\%sLocalise', $tag);
         if (!class_exists($class)) {
             $class = 'Windwalker\\Language\\Localise\\NullLocalise';
         }
         $this->localises[$locale] = new $class();
     }
     return $this->localises[$locale];
 }