From c1f86924c4cdd48d71f172fb749eeaec5c77cda5 Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Fri, 19 Oct 2018 21:14:51 +0200 Subject: [PATCH] translate parameters, should fix #64 --- src/Generator.php | 1 + tests/GenerateTest.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Generator.php b/src/Generator.php index 002a8fc..9923473 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -234,6 +234,7 @@ private function adjustArray(array $arr) { $res = []; foreach ($arr as $key => $val) { + $key = $this->adjustString($key); if (is_string($val)) { $res[$key] = $this->adjustString($val); diff --git a/tests/GenerateTest.php b/tests/GenerateTest.php index 7c8d13e..c6f50c9 100644 --- a/tests/GenerateTest.php +++ b/tests/GenerateTest.php @@ -86,6 +86,29 @@ function testBasic() $this->destroyLocaleFilesFrom($arr, $root); } + function testBasicWithTranslationString() + { + $arr = [ + 'en' => [ + 'main' => [ + 'hello :name' => 'Hello :name', + ] + ], + ]; + + $root = $this->generateLocaleFilesFrom($arr); + $this->assertEquals( + 'export default {' . PHP_EOL + . ' "en": {' . PHP_EOL + . ' "main": {' . PHP_EOL + . ' "hello {name}": "Hello {name}"' . PHP_EOL + . ' }' . PHP_EOL + . ' }' . PHP_EOL + . '}' . PHP_EOL, + (new Generator([]))->generateFromPath($root)); + $this->destroyLocaleFilesFrom($arr, $root); + } + function testBasicWithVendor() { $arr = [