diff options
author | Georg Ehrke <developer@georgehrke.com> | 2018-05-09 12:05:46 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2018-05-24 13:07:54 +0200 |
commit | 0493d0e3fbe5c88acd2d3233e51f053202b30eb6 (patch) | |
tree | aed10296a2bf210a5bad11c0c54278ed714d2c62 | |
parent | 5bd9087cb73af5e1a1dfea33e53028c17ba03ce5 (diff) | |
download | nextcloud-server-0493d0e3fbe5c88acd2d3233e51f053202b30eb6.tar.gz nextcloud-server-0493d0e3fbe5c88acd2d3233e51f053202b30eb6.zip |
make sure force language is reflected in html lang attribute
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
-rw-r--r-- | lib/private/L10N/Factory.php | 6 | ||||
-rw-r--r-- | 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 e277a00e653..86dca2be280 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 602967b1626..38d52d7763b 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -110,7 +110,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); @@ -144,7 +149,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); @@ -167,7 +177,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'); @@ -187,7 +197,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); @@ -210,7 +225,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'); @@ -233,7 +248,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); @@ -256,7 +276,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'); @@ -273,6 +293,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 * |