Merge pull request #39032 from nextcloud/backport/38917/stable25

[stable25] fix(l10n): Fix plural issue with different locale and language
This commit is contained in:
Arthur Schiwon 2023-07-10 17:27:46 +02:00 committed by GitHub
commit 6b79c81b34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -216,7 +216,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;

View file

@ -83,6 +83,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'],