Exemplo n.º 1
0
 /**
  * Load translation
  *
  * @param Plugin $plugin
  * @param string $langCode
  * @throws \Exception
  * @return bool whether the translation was found and loaded
  */
 private function loadTranslation($plugin, $langCode)
 {
     // we are in Tracker mode if Loader is not (yet) loaded
     if (SettingsServer::isTrackerApiRequest()) {
         return false;
     }
     if (is_string($plugin)) {
         $pluginName = $plugin;
     } else {
         $pluginName = $plugin->getPluginName();
     }
     $path = self::getPluginsDirectory() . $pluginName . '/lang/%s.json';
     $defaultLangPath = sprintf($path, $langCode);
     $defaultEnglishLangPath = sprintf($path, 'en');
     $translationsLoaded = false;
     // merge in english translations as default first
     if (file_exists($defaultEnglishLangPath)) {
         $translations = $this->getTranslationsFromFile($defaultEnglishLangPath);
         $translationsLoaded = true;
         if (isset($translations[$pluginName])) {
             // only merge translations of plugin - prevents overwritten strings
             Translate::mergeTranslationArray(array($pluginName => $translations[$pluginName]));
         }
     }
     // merge in specific language translations (to overwrite english defaults)
     if (!empty($langCode) && $defaultEnglishLangPath != $defaultLangPath && file_exists($defaultLangPath)) {
         $translations = $this->getTranslationsFromFile($defaultLangPath);
         $translationsLoaded = true;
         if (isset($translations[$pluginName])) {
             // only merge translations of plugin - prevents overwritten strings
             Translate::mergeTranslationArray(array($pluginName => $translations[$pluginName]));
         }
     }
     return $translationsLoaded;
 }