diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-04-26 13:38:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 13:38:15 +0200 |
commit | dffbddcca6fa0221b8f2ac138732cf01154a5187 (patch) | |
tree | 4fa1d31580f9fd12e7ffb176b18614721428ece8 | |
parent | 7ab1fcf3c43992f3f27f1884eb6d912a79cfbb61 (diff) | |
parent | 26882a4b59e947fafc1abe869c34b644e21d499e (diff) | |
download | nextcloud-server-dffbddcca6fa0221b8f2ac138732cf01154a5187.tar.gz nextcloud-server-dffbddcca6fa0221b8f2ac138732cf01154a5187.zip |
Merge pull request #32155 from nextcloud/bugfix/noid/fix-translations-with-trailing-colon
Fx translations with trailing colon
-rw-r--r-- | lib/private/L10N/L10NString.php | 8 | ||||
-rw-r--r-- | tests/lib/L10N/L10nTest.php | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/private/L10N/L10NString.php b/lib/private/L10N/L10NString.php index de4bc38d744..472a80a5b75 100644 --- a/lib/private/L10N/L10NString.php +++ b/lib/private/L10N/L10NString.php @@ -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); } diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index 9f6337ba804..f410c523c05 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -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]); |