fix(l10n): do not consider user language when getting the generic one

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
pull/55476/head
Richard Steinmetz 2025-10-01 15:58:05 +07:00 committed by SebastianKrupinski
parent 775d610422
commit ccc0c3c25f
2 changed files with 39 additions and 82 deletions

@ -228,27 +228,7 @@ class Factory implements IFactory {
return $defaultLanguage;
}
// Step 3.1: Check if Nextcloud is already installed before we try to access user info
if (!$this->config->getSystemValueBool('installed', false)) {
return 'en';
}
// Step 3.2: Check the current user (if any) for their preferred language
$user = $this->userSession->getUser();
if ($user !== null) {
$userLang = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
if ($userLang !== null) {
return $userLang;
}
}
// Step 4: Check the request headers
try {
return $this->getLanguageFromRequest($appId);
} catch (LanguageNotFoundException $e) {
// Ignore and continue
}
// Step 5: fall back to English
// Step 3: fall back to English
return 'en';
}

@ -551,8 +551,24 @@ class FactoryTest extends TestCase {
self::assertSame($expected, $lang);
}
public function testFindGenericLanguageByRequestParam(): void {
$factory = $this->getFactory();
$this->request->expects(self::once())
->method('getParam')
->with('forceLanguage')
->willReturn('cz');
$lang = $factory->findGenericLanguage();
self::assertSame('cz', $lang);
}
public function testFindGenericLanguageByEnforcedLanguage(): void {
$factory = $this->getFactory();
$this->request->expects(self::once())
->method('getParam')
->with('forceLanguage')
->willReturn(null);
$this->config->expects(self::once())
->method('getSystemValue')
->with('force_language', false)
@ -565,6 +581,10 @@ class FactoryTest extends TestCase {
public function testFindGenericLanguageByDefaultLanguage(): void {
$factory = $this->getFactory(['languageExists']);
$this->request->expects(self::once())
->method('getParam')
->with('forceLanguage')
->willReturn(null);
$this->config->expects(self::exactly(2))
->method('getSystemValue')
->willReturnMap([
@ -581,83 +601,40 @@ class FactoryTest extends TestCase {
self::assertSame('cz', $lang);
}
public function testFindGenericLanguageByUserLanguage(): void {
$factory = $this->getFactory();
public function testFindGenericLanguageByDefaultLanguageNotExists(): void {
$factory = $this->getFactory(['languageExists']);
$this->request->expects(self::once())
->method('getParam')
->with('forceLanguage')
->willReturn(null);
$this->config->expects(self::exactly(2))
->method('getSystemValue')
->willReturnMap([
['force_language', false, false,],
['default_language', false, false,],
]);
$user = $this->createMock(IUser::class);
$this->userSession->expects(self::once())
->method('getUser')
->willReturn($user);
$user->method('getUID')->willReturn('user123');
$this->config->expects(self::once())
->method('getUserValue')
->with('user123', 'core', 'lang', null)
->willReturn('cz');
$lang = $factory->findGenericLanguage();
self::assertSame('cz', $lang);
}
public function testFindGenericLanguageByRequestLanguage(): void {
$factory = $this->getFactory(['findAvailableLanguages', 'languageExists']);
$this->config->method('getSystemValue')
->willReturnMap([
['force_language', false, false,],
['default_language', false, false,],
['default_language', false, 'cz',],
]);
$user = $this->createMock(IUser::class);
$this->userSession->expects(self::once())
->method('getUser')
->willReturn($user);
$user->method('getUID')->willReturn('user123');
$this->config->expects(self::once())
->method('getUserValue')
->with('user123', 'core', 'lang', null)
->willReturn(null);
$this->request->expects(self::once())
->method('getHeader')
->with('ACCEPT_LANGUAGE')
->willReturn('cz');
$factory->expects(self::once())
->method('findAvailableLanguages')
->with(null)
->willReturn(['cz']);
->method('languageExists')
->with(null, 'cz')
->willReturn(false);
$lang = $factory->findGenericLanguage();
self::assertSame('cz', $lang);
self::assertSame('en', $lang);
}
public function testFindGenericLanguageFallback(): void {
$factory = $this->getFactory(['findAvailableLanguages', 'languageExists']);
$this->config->method('getSystemValue')
$factory = $this->getFactory();
$this->request->expects(self::once())
->method('getParam')
->with('forceLanguage')
->willReturn(null);
$this->config->expects(self::exactly(2))
->method('getSystemValue')
->willReturnMap([
['force_language', false, false,],
['default_language', false, false,],
]);
$user = $this->createMock(IUser::class);
$this->userSession->expects(self::once())
->method('getUser')
->willReturn($user);
$user->method('getUID')->willReturn('user123');
$this->config->expects(self::once())
->method('getUserValue')
->with('user123', 'core', 'lang', null)
->willReturn(null);
$this->request->expects(self::once())
->method('getHeader')
->with('ACCEPT_LANGUAGE')
->willReturn('');
$factory->expects(self::never())
->method('findAvailableLanguages');
$factory->expects(self::never())
->method('languageExists');
$lang = $factory->findGenericLanguage();