public static function getEntries($locale, $refresh = true)
 {
     if (empty($refresh) && ($cache = self::getCache($locale))) {
         return $cache;
     }
     $entries = clone self::scan();
     if (is_file($file = self::getFile($locale) . 'mo')) {
         $entries->mergeWith(Extractors\Mo::fromFile($file));
     }
     return $entries;
 }
示例#2
0
 public static function UpdateAll($refresh = true)
 {
     if (empty($refresh) && ($cache = self::getCache(self::$locale))) {
         return $cache;
     }
     $entries = clone self::scan();
     $file = self::getFile(self::$locale);
     if (is_file(base_path() . "/" . $file . 'mo')) {
         $entries->mergeWith(Extractors\Mo::fromFile(base_path() . "/" . $file . 'mo'));
         $entries->mergeWith(Extractors\Po::fromFile(base_path() . "/" . $file . 'po'));
     }
     self::setTranslationObject($entries);
     self::UpdateFiles();
 }
示例#3
0
 public function mergeTranslationsWithPackages(Section $section, Translations $translations)
 {
     foreach (PackageList::get()->getPackages() as $package) {
         /* @var $package \Concrete\Core\Package\Package */
         $baseDir = $package->getPackagePath() . '/' . DIRNAME_LANGUAGES . '/' . $section->getLocale() . '/LC_MESSAGES';
         $poFile = $baseDir . '/messages.po';
         $moFile = $baseDir . '/messages.mo';
         $packageTranslations = null;
         if (is_file($poFile)) {
             $packageTranslations = PoExtractor::fromFile($poFile);
         } elseif (is_file($moFile)) {
             $packageTranslations = MoExtractor::fromFile($moFile);
         }
         if (isset($packageTranslations)) {
             foreach ($translations as $translation) {
                 /* @var $translation \Gettext\Translation */
                 if (!$translation->hasTranslation()) {
                     $packageTranslation = $packageTranslations->find($translation);
                     if ($packageTranslation && $packageTranslation->hasTranslation()) {
                         $translation->mergeWith($packageTranslation);
                     }
                 }
             }
         }
     }
 }
 private function handleLocalizationNIS()
 {
     if (isset($_GET['lang'])) {
         $_SESSION['lang'] = filter_var($_GET['lang'], FILTER_SANITIZE_STRING);
     } elseif (!isset($_SESSION['lang'])) {
         $_SESSION['lang'] = $this->applicationFlags['default_language'];
     }
     /* to avoid potential language injections from other applications that do not applies here */
     if (!in_array($_SESSION['lang'], array_keys($this->applicationFlags['available_languages']))) {
         $_SESSION['lang'] = $this->applicationFlags['default_language'];
     }
     $localizationFile = 'locale/' . $_SESSION['lang'] . '/LC_MESSAGES/' . self::LOCALE_DOMAIN . '.mo';
     $translations = \Gettext\Extractors\Mo::fromFile($localizationFile);
     $this->tApp = new \Gettext\Translator();
     $this->tApp->loadTranslations($translations);
 }