diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-06-22 09:17:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 09:17:48 +0200 |
commit | a3fe1adb03ad5814298e4f18d14d98f85096fe7c (patch) | |
tree | 89bc2fc9b397e21cd427deca14152178bd310314 | |
parent | e9d8dbf53c76670e84bee1c74630e09aca5d7d77 (diff) | |
parent | ab8205fd35a3815673fc17fa78adc5bc770cfdc7 (diff) | |
download | nextcloud-server-a3fe1adb03ad5814298e4f18d14d98f85096fe7c.tar.gz nextcloud-server-a3fe1adb03ad5814298e4f18d14d98f85096fe7c.zip |
Merge pull request #38917 from nextcloud/bugfix/talk-9558/plural-issue-with-some-language-locale-combinations
fix(l10n): Fix plural issue with different locale and language
-rw-r--r-- | lib/private/L10N/L10N.php | 7 | ||||
-rw-r--r-- | tests/lib/L10N/L10nTest.php | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index d0794c9c9c0..ea4aa0527bb 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -215,7 +215,12 @@ class L10N implements IL10N { public function getIdentityTranslator(): IdentityTranslator { if (\is_null($this->identityTranslator)) { $this->identityTranslator = new IdentityTranslator(); - $this->identityTranslator->setLocale($this->getLocaleCode()); + // We need to use the language code here instead of the locale, + // because Symfony does not distinguish between the two and would + // otherwise e.g. with locale "Czech" and language "German" try to + // pick a non-existing plural rule, because Czech has 4 plural forms + // and German only 2. + $this->identityTranslator->setLocale($this->getLanguageCode()); } return $this->identityTranslator; diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index f224592432c..67ad5843546 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -85,6 +85,15 @@ class L10nTest extends TestCase { $this->assertEquals('5 oken', (string)$l->n('%n window', '%n windows', 5)); } + public function testGermanPluralWithCzechLocaleTranslations() { + $transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json'; + $l = new L10N($this->getFactory(), 'test', 'de', 'cs_CZ', [$transFile]); + + $this->assertEquals('1 Datei', (string) $l->n('%n file', '%n files', 1)); + $this->assertEquals('2 Dateien', (string) $l->n('%n file', '%n files', 2)); + $this->assertEquals('5 Dateien', (string) $l->n('%n file', '%n files', 5)); + } + public function dataPlaceholders(): array { return [ ['Ordered placeholders one %s two %s', 'Placeholder one 1 two 2'], |