Skip to content

Commit

Permalink
Merge pull request #9579 from nextcloud/bugfix_stable13/noid/fix_forc…
Browse files Browse the repository at this point in the history
…e_language_html_attr

[stable13] make sure force language is reflected in html lang attribute
  • Loading branch information
MorrisJobke authored May 24, 2018
2 parents cef2e19 + 930c11a commit 866568d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public function get($app, $lang = null) {
* @return string language If nothing works it returns 'en'
*/
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)) {
return $this->requestLanguage;
}
Expand Down
50 changes: 43 additions & 7 deletions tests/lib/L10N/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -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
*
Expand Down

0 comments on commit 866568d

Please sign in to comment.