aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Languages.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-02-26 22:53:00 +0100
committerArthurHoaro <arthur@hoa.ro>2018-03-26 19:20:25 +0200
commit68c6afc56f3758154cfb96cba6fd48a6b5535590 (patch)
treebabc499a94679e8897f70d3024d7b2c359f387e4 /application/Languages.php
parentddd3c19f4336495bbc8927fd552db0c4d9fe6662 (diff)
downloadShaarli-68c6afc56f3758154cfb96cba6fd48a6b5535590.tar.gz
Shaarli-68c6afc56f3758154cfb96cba6fd48a6b5535590.tar.zst
Shaarli-68c6afc56f3758154cfb96cba6fd48a6b5535590.zip
Load theme translations files automatically
Fixes #1077 Take a look at the docs update to see how it works
Diffstat (limited to 'application/Languages.php')
-rw-r--r--application/Languages.php20
1 files changed, 18 insertions, 2 deletions
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
98 $this->translator->setLanguage($this->language); 98 $this->translator->setLanguage($this->language);
99 $this->translator->loadDomain(self::DEFAULT_DOMAIN, 'inc/languages'); 99 $this->translator->loadDomain(self::DEFAULT_DOMAIN, 'inc/languages');
100 100
101 // Default extension translation from the current theme
102 $themeTransFolder = rtrim($this->conf->get('raintpl_tpl'), '/') .'/'. $this->conf->get('theme') .'/language';
103 if (is_dir($themeTransFolder)) {
104 $this->translator->loadDomain($this->conf->get('theme'), $themeTransFolder, false);
105 }
106
101 foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) { 107 foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) {
102 if ($domain !== self::DEFAULT_DOMAIN) { 108 if ($domain !== self::DEFAULT_DOMAIN) {
103 $this->translator->loadDomain($domain, $translationPath, false); 109 $this->translator->loadDomain($domain, $translationPath, false);
@@ -116,12 +122,23 @@ class Languages
116 $translations = new Translations(); 122 $translations = new Translations();
117 // Core translations 123 // Core translations
118 try { 124 try {
119 /** @var Translations $translations */
120 $translations = $translations->addFromPoFile('inc/languages/'. $this->language .'/LC_MESSAGES/shaarli.po'); 125 $translations = $translations->addFromPoFile('inc/languages/'. $this->language .'/LC_MESSAGES/shaarli.po');
121 $translations->setDomain('shaarli'); 126 $translations->setDomain('shaarli');
122 $this->translator->loadTranslations($translations); 127 $this->translator->loadTranslations($translations);
123 } catch (\InvalidArgumentException $e) {} 128 } catch (\InvalidArgumentException $e) {}
124 129
130 // Default extension translation from the current theme
131 $theme = $this->conf->get('theme');
132 $themeTransFolder = rtrim($this->conf->get('raintpl_tpl'), '/') .'/'. $theme .'/language';
133 if (is_dir($themeTransFolder)) {
134 try {
135 $translations = Translations::fromPoFile(
136 $themeTransFolder .'/'. $this->language .'/LC_MESSAGES/'. $theme .'.po'
137 );
138 $translations->setDomain($theme);
139 $this->translator->loadTranslations($translations);
140 } catch (\InvalidArgumentException $e) {}
141 }
125 142
126 // Extension translations (plugins, themes, etc.). 143 // Extension translations (plugins, themes, etc.).
127 foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) { 144 foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) {
@@ -130,7 +147,6 @@ class Languages
130 } 147 }
131 148
132 try { 149 try {
133 /** @var Translations $extension */
134 $extension = Translations::fromPoFile($translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po'); 150 $extension = Translations::fromPoFile($translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po');
135 $extension->setDomain($domain); 151 $extension->setDomain($domain);
136 $this->translator->loadTranslations($extension); 152 $this->translator->loadTranslations($extension);