From 68c6afc56f3758154cfb96cba6fd48a6b5535590 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 26 Feb 2018 22:53:00 +0100 Subject: Load theme translations files automatically Fixes #1077 Take a look at the docs update to see how it works --- application/Languages.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'application/Languages.php') diff --git a/application/Languages.php b/application/Languages.php index 3eb3388f..db4b84ae 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -98,6 +98,12 @@ class Languages $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,23 @@ 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) {} + // 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,7 +147,6 @@ class Languages } try { - /** @var Translations $extension */ $extension = Translations::fromPoFile($translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po'); $extension->setDomain($domain); $this->translator->loadTranslations($extension); -- cgit v1.2.3 From 7ca124079e6bd414b096fcec9789cef1216dff8f Mon Sep 17 00:00:00 2001 From: Buster One <37770318+buster-one@users.noreply.github.com> Date: Sun, 15 Apr 2018 14:53:09 +0200 Subject: German language created (#1114) * Added german language selection * German language file created * typo * extra space removed and typo corrected * lines 1314 through 1408 removed as suggested --- application/Languages.php | 1 + 1 file changed, 1 insertion(+) (limited to 'application/Languages.php') diff --git a/application/Languages.php b/application/Languages.php index db4b84ae..4fa32426 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -177,6 +177,7 @@ class Languages 'auto' => t('Automatic'), 'en' => t('English'), 'fr' => t('French'), + 'de' => t('German'), ]; } } -- cgit v1.2.3 From f211e417bf637b8a83988175c29ee072c69f7642 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 13 Oct 2018 00:19:03 +0200 Subject: lint: apply phpcbf to application/ Signed-off-by: VirtualTam --- application/Languages.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'application/Languages.php') diff --git a/application/Languages.php b/application/Languages.php index 4fa32426..6a6247c7 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -92,7 +92,7 @@ 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); @@ -125,7 +125,8 @@ class Languages $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'); @@ -137,7 +138,8 @@ class Languages ); $translations->setDomain($theme); $this->translator->loadTranslations($translations); - } catch (\InvalidArgumentException $e) {} + } catch (\InvalidArgumentException $e) { + } } // Extension translations (plugins, themes, etc.). @@ -150,7 +152,8 @@ class Languages $extension = Translations::fromPoFile($translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po'); $extension->setDomain($domain); $this->translator->loadTranslations($extension); - } catch (\InvalidArgumentException $e) {} + } catch (\InvalidArgumentException $e) { + } } } -- cgit v1.2.3 From 9d9f6d75b94aab51067bdfbe50b58b66d1194f6d Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 13 Oct 2018 01:40:04 +0200 Subject: lint: fix line-length warnings Signed-off-by: VirtualTam --- application/Languages.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'application/Languages.php') diff --git a/application/Languages.php b/application/Languages.php index 6a6247c7..b9c5d0e8 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -149,7 +149,9 @@ class Languages } try { - $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) { -- cgit v1.2.3