From 2a21471c74dc5a5e5e9859000316b385007d4d56 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 a7ffb401b7..74cea7aa84 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -130,6 +130,12 @@ class Factory implements IFactory { 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 1e5c2ef542..3008e0a239 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -117,7 +117,12 @@ class FactoryTest extends TestCase { ->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); @@ -151,7 +156,12 @@ class FactoryTest extends TestCase { ->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); @@ -174,7 +184,7 @@ class FactoryTest extends TestCase { ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -194,7 +204,12 @@ class FactoryTest extends TestCase { ->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); @@ -217,7 +232,7 @@ class FactoryTest extends TestCase { ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -240,7 +255,12 @@ class FactoryTest extends TestCase { ->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); @@ -263,7 +283,7 @@ class FactoryTest extends TestCase { ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -280,6 +300,22 @@ class FactoryTest extends TestCase { $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 4286e17777433caac06859c744ff3f3fbbf95e8b 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 74cea7aa84..4f63adce57 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -126,14 +126,13 @@ class Factory implements IFactory { * @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->requestLanguage = $forceLang; } - $forceLang = $this->config->getSystemValue('force_language', false); - if (is_string($forceLang) && $this->languageExists($app, $forceLang)) { - $this->requestLanguage = $forceLang; - return $forceLang; + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { + return $this->requestLanguage; } /**