aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Languages.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-03-26 20:26:10 +0200
committerGitHub <noreply@github.com>2018-03-26 20:26:10 +0200
commit9b2bd66fb60ffd5a833480bf329062c7d57bc8c4 (patch)
treed0a99bd7b366a9bdd6c92ab9e95db6dce4de1d3c /application/Languages.php
parent838ef8a6ec140bd21124258e584be220be55048f (diff)
parent68c6afc56f3758154cfb96cba6fd48a6b5535590 (diff)
downloadShaarli-9b2bd66fb60ffd5a833480bf329062c7d57bc8c4.tar.gz
Shaarli-9b2bd66fb60ffd5a833480bf329062c7d57bc8c4.tar.zst
Shaarli-9b2bd66fb60ffd5a833480bf329062c7d57bc8c4.zip
Merge pull request #1093 from ArthurHoaro/feature/theme-translation
Load theme translations files automatically
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);