Skip to content

Commit 3b7ecb5

Browse files
authored
Merge pull request #32160 from nextcloud/backport/32155/stable23
[stable23] Fx translations with trailing colon
2 parents b13950c + 85b517a commit 3b7ecb5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/private/L10N/L10NString.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ public function __toString(): string {
7474
return 'Can not use pipe character in translations';
7575
}
7676

77+
$beforeIdentity = $identity;
7778
$identity = str_replace('%n', '%count%', $identity);
7879

80+
$parameters = [];
81+
if ($beforeIdentity !== $identity) {
82+
$parameters = ['%count%' => $this->count];
83+
}
84+
7985
// $count as %count% as per \Symfony\Contracts\Translation\TranslatorInterface
80-
$text = $identityTranslator->trans($identity, ['%count%' => $this->count]);
86+
$text = $identityTranslator->trans($identity, $parameters);
8187

8288
return vsprintf($text, $this->parameters);
8389
}

tests/lib/L10N/L10nTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ protected function getFactory() {
3535
return new Factory($config, $request, $userSession, \OC::$SERVERROOT);
3636
}
3737

38+
public function testSimpleTranslationWithTrailingColon(): void {
39+
$transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json';
40+
$l = new L10N($this->getFactory(), 'test', 'de', 'de_AT', [$transFile]);
41+
42+
$this->assertEquals('Files:', $l->t('Files:'));
43+
}
44+
3845
public function testGermanPluralTranslations() {
3946
$transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json';
4047
$l = new L10N($this->getFactory(), 'test', 'de', 'de_AT', [$transFile]);

0 commit comments

Comments
 (0)