Merge pull request #9580 from nextcloud/bugfix_stable12/noid/fix_force_language_html_attr

[stable12] make sure force language is reflected in html lang attribute
This commit is contained in:
Morris Jobke 2018-05-24 18:00:39 +02:00 committed by GitHub
commit e10c13271c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 7 deletions

View File

@ -126,6 +126,11 @@ class Factory implements IFactory {
* @return string language If nothing works it returns 'en' * @return string language If nothing works it returns 'en'
*/ */
public function findLanguage($app = null) { public function findLanguage($app = null) {
$forceLang = $this->config->getSystemValue('force_language', false);
if (is_string($forceLang)) {
$this->requestLanguage = $forceLang;
}
if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) {
return $this->requestLanguage; return $this->requestLanguage;
} }

View File

@ -110,7 +110,12 @@ class FactoryTest extends TestCase {
->with('MyApp', 'de') ->with('MyApp', 'de')
->willReturn(false); ->willReturn(false);
$this->config $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') ->method('getSystemValue')
->with('installed', false) ->with('installed', false)
->willReturn(true); ->willReturn(true);
@ -144,7 +149,12 @@ class FactoryTest extends TestCase {
->with('MyApp', 'de') ->with('MyApp', 'de')
->willReturn(false); ->willReturn(false);
$this->config $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') ->method('getSystemValue')
->with('installed', false) ->with('installed', false)
->willReturn(true); ->willReturn(true);
@ -167,7 +177,7 @@ class FactoryTest extends TestCase {
->with('MyApp', 'jp') ->with('MyApp', 'jp')
->willReturn(false); ->willReturn(false);
$this->config $this->config
->expects($this->at(2)) ->expects($this->at(3))
->method('getSystemValue') ->method('getSystemValue')
->with('default_language', false) ->with('default_language', false)
->willReturn('es'); ->willReturn('es');
@ -187,7 +197,12 @@ class FactoryTest extends TestCase {
->with('MyApp', 'de') ->with('MyApp', 'de')
->willReturn(false); ->willReturn(false);
$this->config $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') ->method('getSystemValue')
->with('installed', false) ->with('installed', false)
->willReturn(true); ->willReturn(true);
@ -210,7 +225,7 @@ class FactoryTest extends TestCase {
->with('MyApp', 'jp') ->with('MyApp', 'jp')
->willReturn(false); ->willReturn(false);
$this->config $this->config
->expects($this->at(2)) ->expects($this->at(3))
->method('getSystemValue') ->method('getSystemValue')
->with('default_language', false) ->with('default_language', false)
->willReturn('es'); ->willReturn('es');
@ -233,7 +248,12 @@ class FactoryTest extends TestCase {
->with('MyApp', 'de') ->with('MyApp', 'de')
->willReturn(false); ->willReturn(false);
$this->config $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') ->method('getSystemValue')
->with('installed', false) ->with('installed', false)
->willReturn(true); ->willReturn(true);
@ -256,7 +276,7 @@ class FactoryTest extends TestCase {
->with('MyApp', 'jp') ->with('MyApp', 'jp')
->willReturn(false); ->willReturn(false);
$this->config $this->config
->expects($this->at(2)) ->expects($this->at(3))
->method('getSystemValue') ->method('getSystemValue')
->with('default_language', false) ->with('default_language', false)
->willReturn('es'); ->willReturn('es');
@ -273,6 +293,22 @@ class FactoryTest extends TestCase {
$this->assertSame('en', $factory->findLanguage('MyApp')); $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 * @dataProvider dataFindAvailableLanguages
* *