aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Languages.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2019-07-27 12:34:30 +0200
committerArthurHoaro <arthur@hoa.ro>2019-07-27 12:34:30 +0200
commit38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch)
treedae4c7c47532380eac3ae641db99122fc77c93dc /application/Languages.php
parent83faedadff76c5bdca036f39f13943f63b27e164 (diff)
parent1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff)
downloadShaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.gz
Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.zst
Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.zip
Merge tag 'v0.10.4' into stable
Release v0.10.4
Diffstat (limited to 'application/Languages.php')
-rw-r--r--application/Languages.php34
1 files changed, 28 insertions, 6 deletions
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
92 /** 92 /**
93 * Initialize the translator using php gettext extension (gettext dependency act as a wrapper). 93 * Initialize the translator using php gettext extension (gettext dependency act as a wrapper).
94 */ 94 */
95 protected function initGettextTranslator () 95 protected function initGettextTranslator()
96 { 96 {
97 $this->translator = new GettextTranslator(); 97 $this->translator = new GettextTranslator();
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,25 @@ 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) {
129 }
124 130
131 // Default extension translation from the current theme
132 $theme = $this->conf->get('theme');
133 $themeTransFolder = rtrim($this->conf->get('raintpl_tpl'), '/') .'/'. $theme .'/language';
134 if (is_dir($themeTransFolder)) {
135 try {
136 $translations = Translations::fromPoFile(
137 $themeTransFolder .'/'. $this->language .'/LC_MESSAGES/'. $theme .'.po'
138 );
139 $translations->setDomain($theme);
140 $this->translator->loadTranslations($translations);
141 } catch (\InvalidArgumentException $e) {
142 }
143 }
125 144
126 // Extension translations (plugins, themes, etc.). 145 // Extension translations (plugins, themes, etc.).
127 foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) { 146 foreach ($this->conf->get('translation.extensions', []) as $domain => $translationPath) {
@@ -130,11 +149,13 @@ class Languages
130 } 149 }
131 150
132 try { 151 try {
133 /** @var Translations $extension */ 152 $extension = Translations::fromPoFile(
134 $extension = Translations::fromPoFile($translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po'); 153 $translationPath . $this->language .'/LC_MESSAGES/'. $domain .'.po'
154 );
135 $extension->setDomain($domain); 155 $extension->setDomain($domain);
136 $this->translator->loadTranslations($extension); 156 $this->translator->loadTranslations($extension);
137 } catch (\InvalidArgumentException $e) {} 157 } catch (\InvalidArgumentException $e) {
158 }
138 } 159 }
139 } 160 }
140 161
@@ -161,6 +182,7 @@ class Languages
161 'auto' => t('Automatic'), 182 'auto' => t('Automatic'),
162 'en' => t('English'), 183 'en' => t('English'),
163 'fr' => t('French'), 184 'fr' => t('French'),
185 'de' => t('German'),
164 ]; 186 ];
165 } 187 }
166} 188}