Merge pull request #32159 from nextcloud/backport/32155/stable24

[stable24] Fx translations with trailing colon
This commit is contained in:
blizzz 2022-05-16 11:50:51 +02:00 committed by GitHub
commit 5b4df735ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -74,10 +74,16 @@ class L10NString implements \JsonSerializable {
return 'Can not use pipe character in translations';
}
$beforeIdentity = $identity;
$identity = str_replace('%n', '%count%', $identity);
$parameters = [];
if ($beforeIdentity !== $identity) {
$parameters = ['%count%' => $this->count];
}
// $count as %count% as per \Symfony\Contracts\Translation\TranslatorInterface
$text = $identityTranslator->trans($identity, ['%count%' => $this->count]);
$text = $identityTranslator->trans($identity, $parameters);
return vsprintf($text, $this->parameters);
}

View file

@ -35,6 +35,13 @@ class L10nTest extends TestCase {
return new Factory($config, $request, $userSession, \OC::$SERVERROOT);
}
public function testSimpleTranslationWithTrailingColon(): void {
$transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json';
$l = new L10N($this->getFactory(), 'test', 'de', 'de_AT', [$transFile]);
$this->assertEquals('Files:', $l->t('Files:'));
}
public function testGermanPluralTranslations() {
$transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json';
$l = new L10N($this->getFactory(), 'test', 'de', 'de_AT', [$transFile]);