From 258330d64da6124083864c6484ecdb52732421fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 10 Sep 2018 10:19:49 +0200 Subject: [PATCH 1/6] Use user locale as default in the template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/L10N/Factory.php | 20 ++++++++++++++++++++ lib/private/TemplateLayout.php | 7 +++++-- lib/public/L10N/IFactory.php | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index cc2de17450..1a7fff4322 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -244,6 +244,26 @@ class Factory implements IFactory { return 'en_US'; } + /** + * find the matching lang from the locale + * + * @param string $app + * @param string $locale + * @return null|string + */ + public function findLanguageFromLocale($app = 'core', $locale = null) { + if ($this->languageExists($app, $locale)) { + return $locale; + } + + // Try to split e.g: fr_FR => fr + $locale = explode('_', $locale)[0]; + if ($this->languageExists($app, $locale)) { + return $locale; + } + + } + /** * Find all available languages for an app * diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 0bd57c4139..a710ee856e 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -139,9 +139,12 @@ class TemplateLayout extends \OC_Template { } // Send the language and the locale to our layouts $lang = \OC::$server->getL10NFactory()->findLanguage(); + $locale = \OC::$server->getL10NFactory()->findLocale($lang); + $localeLang = \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale); + $lang = str_replace('_', '-', $lang); $this->assign('language', $lang); - $this->assign('locale', \OC::$server->getL10NFactory()->findLocale($lang)); + $this->assign('locale', $locale); if(\OC::$server->getSystemConfig()->getValue('installed', false)) { if (empty(self::$versionHash)) { @@ -159,7 +162,7 @@ class TemplateLayout extends \OC_Template { if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { $jsConfigHelper = new JSConfigHelper( - \OC::$server->getL10N('lib'), + \OC::$server->getL10N('lib', $localeLang), \OC::$server->query(Defaults::class), \OC::$server->getAppManager(), \OC::$server->getSession(), diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 1bc231e4e2..31276b1289 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -53,6 +53,14 @@ interface IFactory { */ public function findLocale($lang = null); + /** + * find the matching lang from the locale + * + * @param string $locale + * @return null|string + */ + public function findLanguageFromLocale($locale = null); + /** * Find all available languages for an app * From 19350c4b95f0c8c599230dbe70652ebcf570dcf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 10 Sep 2018 10:45:18 +0200 Subject: [PATCH 2/6] Fix public l10n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/public/L10N/IFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 31276b1289..4f42e498ed 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -56,10 +56,11 @@ interface IFactory { /** * find the matching lang from the locale * + * @param string $app * @param string $locale * @return null|string */ - public function findLanguageFromLocale($locale = null); + public function findLanguageFromLocale($app = 'core', $locale = null); /** * Find all available languages for an app From ccb8838854569d78e879b422ce155ebd4d877101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 10 Sep 2018 10:48:53 +0200 Subject: [PATCH 3/6] Since requirement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/public/L10N/IFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 4f42e498ed..49dab86947 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -59,6 +59,7 @@ interface IFactory { * @param string $app * @param string $locale * @return null|string + * @since 15.0.0 */ public function findLanguageFromLocale($app = 'core', $locale = null); From d69ddd94def2436d695e4f1c56fc0252ef77c4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 10 Sep 2018 11:17:03 +0200 Subject: [PATCH 4/6] Typehint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/L10N/Factory.php | 3 +-- lib/public/L10N/IFactory.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 1a7fff4322..1c56949c40 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -251,7 +251,7 @@ class Factory implements IFactory { * @param string $locale * @return null|string */ - public function findLanguageFromLocale($app = 'core', $locale = null) { + public function findLanguageFromLocale(string $app = 'core', string $locale = null) { if ($this->languageExists($app, $locale)) { return $locale; } @@ -261,7 +261,6 @@ class Factory implements IFactory { if ($this->languageExists($app, $locale)) { return $locale; } - } /** diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 49dab86947..810e916ef6 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -61,7 +61,7 @@ interface IFactory { * @return null|string * @since 15.0.0 */ - public function findLanguageFromLocale($app = 'core', $locale = null); + public function findLanguageFromLocale(string $app = 'core', string $locale = null); /** * Find all available languages for an app From efbd98183dc52c85df46d3cc64954af0f83665f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 13 Sep 2018 11:30:57 +0200 Subject: [PATCH 5/6] Fallback to $lang if no $locale match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/TemplateLayout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index a710ee856e..316e122e2c 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -162,7 +162,7 @@ class TemplateLayout extends \OC_Template { if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { $jsConfigHelper = new JSConfigHelper( - \OC::$server->getL10N('lib', $localeLang), + \OC::$server->getL10N('lib', $localeLang ?: $lang), \OC::$server->query(Defaults::class), \OC::$server->getAppManager(), \OC::$server->getSession(), From fcda1f71241f0978b127e4b63339beb3532b737d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 19 Sep 2018 16:02:09 +0200 Subject: [PATCH 6/6] Fix since tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/public/L10N/IFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 810e916ef6..a11977f8c0 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -59,7 +59,7 @@ interface IFactory { * @param string $app * @param string $locale * @return null|string - * @since 15.0.0 + * @since 14.0.1 */ public function findLanguageFromLocale(string $app = 'core', string $locale = null);