diff options
author | Joas Schilling <coding@schilljs.com> | 2021-03-31 09:54:23 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-04-20 16:42:05 +0200 |
commit | 5a514a9a419f40800e5dc70c33b9de9f33cf7a76 (patch) | |
tree | 107f7c16df9e7ae8f51c1db5dcda014ace9eca1e /tests | |
parent | 439457d2b4cdc511fbce826764b2b27e30abee50 (diff) | |
download | nextcloud-server-5a514a9a419f40800e5dc70c33b9de9f33cf7a76.tar.gz nextcloud-server-5a514a9a419f40800e5dc70c33b9de9f33cf7a76.zip |
Correctly replace all PHP placeholders with the parameters
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/l10n/de.json | 5 | ||||
-rw-r--r-- | tests/lib/L10N/L10nTest.php | 21 |
2 files changed, 25 insertions, 1 deletions
diff --git a/tests/data/l10n/de.json b/tests/data/l10n/de.json index c2b6f34c081..d9e75d303c5 100644 --- a/tests/data/l10n/de.json +++ b/tests/data/l10n/de.json @@ -1,6 +1,9 @@ { "translations" : { - "_%n file_::_%n files_": ["%n Datei", "%n Dateien"] + "_%n file_::_%n files_": ["%n Datei", "%n Dateien"], + "Ordered placeholders one %s two %s": "Placeholder one %s two %s", + "Reordered placeholders one %s two %s": "Placeholder two %2$s one %1$s", + "Reordered placeholders one %1$s two %2$s": "Placeholder two %2$s one %1$s" }, "pluralForm" : "nplurals=2; plural=(n != 1);" } diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index 0de09386fba..3fb22b3f66e 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -76,6 +76,27 @@ class L10nTest extends TestCase { $this->assertEquals('5 oken', (string)$l->n('%n window', '%n windows', 5)); } + public function dataPlaceholders(): array { + return [ + ['Ordered placeholders one %s two %s', 'Placeholder one 1 two 2'], + ['Reordered placeholders one %s two %s', 'Placeholder two 2 one 1'], + ['Reordered placeholders one %1$s two %2$s', 'Placeholder two 2 one 1'], + ]; + } + + /** + * @dataProvider dataPlaceholders + * + * @param $string + * @param $expected + */ + public function testPlaceholders($string, $expected): void { + $transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json'; + $l = new L10N($this->getFactory(), 'test', 'de', 'de_AT', [$transFile]); + + $this->assertEquals($expected, $l->t($string, ['1', '2'])); + } + public function localizationData() { return [ // timestamp as string |