Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit aac9136

Browse files
committed
adjust strings in the whole array
1 parent 18635f6 commit aac9136

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/Generator.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,29 @@ private function allocateLocaleArray($path)
4545
if (!$fileinfo->isDot()) {
4646
$noExt = $this->removeExtension($fileinfo->getFilename());
4747
$tmp = include($path . '/' . $fileinfo->getFilename());
48-
$res = [];
4948

50-
foreach ($tmp as $key => $val) {
51-
$res[$key] = $this->adjustString($val);
52-
}
53-
54-
$data[$noExt] = $res;
49+
$data[$noExt] = $this->adjustArray($tmp);
5550
}
5651
}
5752

5853
return $data;
5954
}
6055

56+
private function adjustArray(array $arr)
57+
{
58+
$res = [];
59+
60+
foreach ($arr as $key => $val) {
61+
if (is_string($val)) {
62+
$res[$key] = $this->adjustString($val);
63+
} else {
64+
$res[$key] = $this->adjustArray($val);
65+
}
66+
}
67+
68+
return $res;
69+
}
70+
6171
/**
6272
* Turn Laravel style ":link" into vue-i18n style "{link}"
6373
* @param string $s

tests/GenerateTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ function testNamed()
9494
'en' => [
9595
'help' => [
9696
'yes' => 'see :link y :lonk',
97-
]
98-
],
99-
'sv' => [
100-
'help' => [
101-
'yes' => 'se :lonk a :link',
97+
'no' => [
98+
'one' => 'see :link',
99+
]
102100
]
103101
]
104102
];
@@ -109,12 +107,10 @@ function testNamed()
109107
'export default {' . PHP_EOL
110108
. ' "en": {' . PHP_EOL
111109
. ' "help": {' . PHP_EOL
112-
. ' "yes": "see {link} y {lonk}"' . PHP_EOL
113-
. ' }' . PHP_EOL
114-
. ' },' . PHP_EOL
115-
. ' "sv": {' . PHP_EOL
116-
. ' "help": {' . PHP_EOL
117-
. ' "yes": "se {lonk} a {link}"' . PHP_EOL
110+
. ' "yes": "see {link} y {lonk}",' . PHP_EOL
111+
. ' "no": {' . PHP_EOL
112+
. ' "one": "see {link}"' . PHP_EOL
113+
. ' }' . PHP_EOL
118114
. ' }' . PHP_EOL
119115
. ' }' . PHP_EOL
120116
. '}' . PHP_EOL,

0 commit comments

Comments
 (0)