X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FLanguages.php;h=b9c5d0e8c3cbf627a590516d448ab9c85343a4fb;hb=9d9f6d75b94aab51067bdfbe50b58b66d1194f6d;hp=3eb3388f48f6a01ac87c872c408018c9c574cdec;hpb=40e816e3796d7d4fdf4b442c25f4c2b76f5eebc0;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Languages.php b/application/Languages.php index 3eb3388f..b9c5d0e8 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -92,12 +92,18 @@ class Languages /** * Initialize the translator using php gettext extension (gettext dependency act as a wrapper). */ - protected function initGettextTranslator () + protected function initGettextTranslator() { $this->translator = new GettextTranslator(); $this->translator->setLanguage($this->language); $this->translator->loadDomain(self::DEFAULT_DOMAIN, 'inc/languages'); + // Default extension translation from the current theme + $themeTransFolder = rtrim($this->conf->get('raintpl_tpl'), '/') .'/'. $this->conf->get('theme') .'/language'; + if (is_dir($themeTransFolder)) { + $this->translator->loadDomain($this->conf->get('theme'), $themeTransFolder, false); + } + foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) { if ($domain !== self::DEFAULT_DOMAIN) { $this->translator->loadDomain($domain, $translationPath, false); @@ -116,12 +122,25 @@ class Languages $translations = new Translations(); // Core translations try { - /** @var Translations $translations */ $translations = $translations->addFromPoFile('inc/languages/'. $this->language .'/LC_MESSAGES/shaarli.po'); $translations->setDomain('shaarli'); $this->translator->loadTranslations($translations); - } catch (\InvalidArgumentException $e) {} + } catch (\InvalidArgumentException $e) { + } + // Default extension translation from the current theme + $theme = $this->conf->get('theme'); + $themeTransFolder = rtrim($this->conf->get('raintpl_tpl'), '/') .'/'. $theme .'/language'; + if (is_dir($themeTransFolder)) { + try { + $translations = Translations::fromPoFile( + $themeTransFolder .'/'. $this->language .'/LC_MESSAGES/'. $theme .'.po' + ); + $translations->setDomain($theme); + $this->translator->loadTranslations($translations); + } catch (\InvalidArgumentException $e) { + } + } // Extension translations (plugins, themes, etc.). foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) { @@ -130,11 +149,13 @@ class Languages } try { - /** @var Translations $extension */ - $extension = Translations::fromPoFile($translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po'); + $extension = Translations::fromPoFile( + $translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po' + ); $extension->setDomain($domain); $this->translator->loadTranslations($extension); - } catch (\InvalidArgumentException $e) {} + } catch (\InvalidArgumentException $e) { + } } } @@ -161,6 +182,7 @@ class Languages 'auto' => t('Automatic'), 'en' => t('English'), 'fr' => t('French'), + 'de' => t('German'), ]; } }