From 0dc1b3e741caa3a160aff9c2680e5db024d54a71 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 9 May 2018 12:05:46 +0200 Subject: [PATCH 1/2] make sure force language is reflected in html lang attribute Signed-off-by: Georg Ehrke --- lib/private/L10N/Factory.php | 6 ++++ tests/lib/L10N/FactoryTest.php | 50 +++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 399bebb8189c3..658a8793c6985 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -130,6 +130,12 @@ public function findLanguage($app = null) { return $this->requestLanguage; } + $forceLang = $this->config->getSystemValue('force_language', false); + if (is_string($forceLang) && $this->languageExists($app, $forceLang)) { + $this->requestLanguage = $forceLang; + return $forceLang; + } + /** * At this point Nextcloud might not yet be installed and thus the lookup * in the preferences table might fail. For this reason we need to check diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php index 77a56b5f945de..934dfe08e43b8 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -110,7 +110,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndExistingStoredU ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->once()) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -144,7 +149,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->at(0)) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -167,7 +177,7 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -187,7 +197,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->at(0)) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -210,7 +225,7 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -233,7 +248,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->at(0)) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -256,7 +276,7 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -273,6 +293,22 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor $this->assertSame('en', $factory->findLanguage('MyApp')); } + public function testFindLanguageWithForcedLanguage() { + $factory = $this->getFactory(['languageExists']); + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn('de'); + + $factory->expects($this->once()) + ->method('languageExists') + ->with('MyApp', 'de') + ->willReturn(true); + + $this->assertSame('de', $factory->findLanguage('MyApp')); + } + /** * @dataProvider dataFindAvailableLanguages * From 4b8a9a37d61c00b8d4ff4c816e545c3174969cbb Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 23 May 2018 21:19:46 +0200 Subject: [PATCH 2/2] Always set the request language to the force language Signed-off-by: Roeland Jago Douma --- lib/private/L10N/Factory.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 658a8793c6985..10d6804d74784 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -126,14 +126,13 @@ public function get($app, $lang = null) { * @return string language If nothing works it returns 'en' */ public function findLanguage($app = null) { - if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { - return $this->requestLanguage; - } - $forceLang = $this->config->getSystemValue('force_language', false); - if (is_string($forceLang) && $this->languageExists($app, $forceLang)) { + if (is_string($forceLang)) { $this->requestLanguage = $forceLang; - return $forceLang; + } + + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { + return $this->requestLanguage; } /**