Ejemplo n.º 1
0
 public function setOptions($options)
 {
     if (!is_array($options)) {
         throw new \Exception('Invalid options');
     }
     if (!isset($options['locale'])) {
         throw new \Exception('Parameter "locale" is required');
     }
     if (strpos($options['locale'], '..') !== false) {
         throw new \Exception('Locale has dangerous characters');
     }
     if (!isset($options['domains'])) {
         throw new \Exception('domains must be specified and it must be an array.');
     }
     if (isset($options['compileAlways']) && $options['compileAlways'] === true) {
         $compiler = new Compiler();
         $compiler->compileLocale(['locale' => $options['locale'], 'domains' => $options['domains'], 'localeDir' => $options['localeDir'], 'localeCacheDir' => $options['localeCacheDir']]);
     }
     $codeset = 'UTF-8';
     putenv('LANG=' . $options['locale'] . '.' . $codeset);
     putenv('LANGUAGE=' . $options['locale'] . '.' . $codeset);
     setlocale(LC_ALL, $options['locale'] . '.' . $codeset);
     foreach ($options['domains'] as $domain) {
         bindtextdomain($domain, $options['localeCacheDir']);
         bind_textdomain_codeset($domain, $codeset);
     }
     $this->domains = $options['domains'];
     $this->defaultDomain = reset($options['domains']);
     textdomain($this->defaultDomain);
 }
Ejemplo n.º 2
0
 /**
  *
  */
 private function compileLocales()
 {
     $supported = $this->getDI()->getLocale()->getSupportedLocales();
     $distDir = $this->config->dev->path->distDir;
     $localeCacheDir = $distDir . 'cache-static/locale/';
     foreach ($supported as $locale => $true) {
         try {
             $compiler = new LocaleCompiler();
             $success = $compiler->compileLocale(['locale' => $locale, 'domains' => $this->config->locale->domains, 'localeDir' => $this->config->path->localeDir, 'localeCacheDir' => $localeCacheDir]);
         } catch (LocaleCompilerException $e) {
             error_log($e->getMessage());
             exit(1);
         }
     }
 }