Skip to content

Commit

Permalink
use formal version of German by default, if not explicitely defined d…
Browse files Browse the repository at this point in the history
…ifferently

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
  • Loading branch information
schiessle committed Nov 30, 2017
1 parent 49ec86a commit 0be9cb5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function findLanguage($app = null) {
try {
// Try to get the language from the Request
$lang = $this->getLanguageFromRequest($app);
// use formal version of german ("Sie" instead of "Du") by default
$lang = strtolower($lang) === 'de' ? 'de_DE' : $lang;
if ($userId !== null && $app === null && !$userLang) {
$this->config->setUserValue($userId, 'core', 'lang', $lang);
}
Expand Down
44 changes: 41 additions & 3 deletions tests/lib/L10N/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ public function dataFindLanguage() {
// Not logged in
[false, [], 'en'],
[false, ['fr'], 'fr'],
[false, ['de', 'fr'], 'de'],
[false, ['nl', 'de', 'fr'], 'de'],
[false, ['de', 'fr', 'de_DE'], 'de_DE'],
[false, ['nl', 'de', 'fr', 'de_DE'], 'de_DE'],

[true, [], 'en'],
[true, ['fr'], 'fr'],
[true, ['de', 'fr'], 'de'],
[true, ['de', 'fr', 'de_DE'], 'de_DE'],
[true, ['nl', 'de', 'fr'], 'nl'],
];
}
Expand Down Expand Up @@ -513,4 +513,42 @@ public function testFindLanguage($loggedIn, $availableLang, $expected) {
$this->assertSame($expected, $lang);

}

/**
* test if we keep non-formal german ('Du' instead of 'Sie') if it is set explicitly
*/
public function testFindLanguageGerman() {
$availableLang = ['de'];
$expected = 'de';
$userLang = 'de';

$this->config->expects($this->any())
->method('getSystemValue')->with('installed', false)->willReturn(true);

$user = $this->getMockBuilder(IUser::class)
->getMock();
$user->expects($this->any())
->method('getUID')
->willReturn('MyUserUid');
$this->userSession
->expects($this->any())
->method('getUser')
->willReturn($user);
$this->config->expects($this->any())
->method('getUserValue')
->with('MyUserUid', 'core', 'lang', null)
->willReturn($userLang);

$factory = $this->getFactory(['languageExists', 'findAvailableLanguages']);

$factory->expects($this->any())
->method('languageExists')
->will($this->returnCallback(function ($app, $lang) use ($availableLang) {
return in_array($lang, $availableLang);
}));

$lang = $factory->findLanguage(null);
$this->assertSame($expected, $lang);

}
}

0 comments on commit 0be9cb5

Please sign in to comment.