Skip to content

Commit 304489e

Browse files
committed
Merge branch 'master' into 5.3-initial
2 parents 85a16e4 + 984f441 commit 304489e

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/Commands/SyncCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ private function syncKeysFromFiles($translationFiles)
7979
if (isset($allKeysInFiles[$fileName])) {
8080
$missingKeys = array_diff($allKeysInFiles[$fileName], array_keys(array_dot($fileContent)));
8181

82+
foreach ($missingKeys as $i => $missingKey) {
83+
if (Arr::has($fileContent, $missingKey)) {
84+
unset($missingKeys[$i]);
85+
}
86+
}
87+
8288
$this->fillMissingKeys($fileName, $missingKeys, $languageKey);
8389
}
8490
}

src/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function stringLineMaker($array, $prepend = '')
226226

227227
$output .= "\n{$prepend} '{$key}' => [{$value}\n{$prepend} ],";
228228
} else {
229-
$value = addslashes($value);
229+
$value = str_replace('\"', '"', addslashes($value));
230230

231231
$output .= "\n{$prepend} '{$key}' => '{$value}',";
232232
}

tests/ManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function testWriteFile()
8383
$values = [
8484
'name' => ['first' => 'first', 'last' => ['last1' => '1', 'last2' => 2]],
8585
'age' => 'age',
86+
'double_quotes' => '"with quotes"',
87+
'quotes' => "With some ' quotes",
8688
];
8789

8890
$manager->writeFile($filePath, $values);

tests/SyncCommandTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,23 @@ public function testCommandOutputForMissingSubKey()
6969
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
7070
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
7171
}
72+
73+
public function testItDoesntOverrideParentKey()
74+
{
75+
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
76+
77+
file_put_contents(__DIR__.'/views_temp/user.blade.php', '{{ trans(\'user.name\') }}');
78+
79+
$this->createTempFiles([
80+
'en' => ['user' => "<?php\n return ['name' => ['middle' => 'middle']];"],
81+
]);
82+
83+
$this->artisan('langman:sync');
84+
85+
$userENFile = (array) include $this->app['config']['langman.path'].'/en/user.php';
86+
87+
$this->assertEquals(['middle' => 'middle'], $userENFile['name']);
88+
89+
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
90+
}
7291
}

0 commit comments

Comments
 (0)