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

Commit

Permalink
adjust strings in the whole array
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Nov 9, 2015
1 parent 18635f6 commit aac9136
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
22 changes: 16 additions & 6 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,29 @@ private function allocateLocaleArray($path)
if (!$fileinfo->isDot()) {
$noExt = $this->removeExtension($fileinfo->getFilename());
$tmp = include($path . '/' . $fileinfo->getFilename());
$res = [];

foreach ($tmp as $key => $val) {
$res[$key] = $this->adjustString($val);
}

$data[$noExt] = $res;
$data[$noExt] = $this->adjustArray($tmp);
}
}

return $data;
}

private function adjustArray(array $arr)
{
$res = [];

foreach ($arr as $key => $val) {
if (is_string($val)) {
$res[$key] = $this->adjustString($val);
} else {
$res[$key] = $this->adjustArray($val);
}
}

return $res;
}

/**
* Turn Laravel style ":link" into vue-i18n style "{link}"
* @param string $s
Expand Down
18 changes: 7 additions & 11 deletions tests/GenerateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ function testNamed()
'en' => [
'help' => [
'yes' => 'see :link y :lonk',
]
],
'sv' => [
'help' => [
'yes' => 'se :lonk a :link',
'no' => [
'one' => 'see :link',
]
]
]
];
Expand All @@ -109,12 +107,10 @@ function testNamed()
'export default {' . PHP_EOL
. ' "en": {' . PHP_EOL
. ' "help": {' . PHP_EOL
. ' "yes": "see {link} y {lonk}"' . PHP_EOL
. ' }' . PHP_EOL
. ' },' . PHP_EOL
. ' "sv": {' . PHP_EOL
. ' "help": {' . PHP_EOL
. ' "yes": "se {lonk} a {link}"' . PHP_EOL
. ' "yes": "see {link} y {lonk}",' . PHP_EOL
. ' "no": {' . PHP_EOL
. ' "one": "see {link}"' . PHP_EOL
. ' }' . PHP_EOL
. ' }' . PHP_EOL
. ' }' . PHP_EOL
. '}' . PHP_EOL,
Expand Down

0 comments on commit aac9136

Please sign in to comment.