Skip to content

Commit 4dc3c18

Browse files
committed
fix #48
1 parent 3576ed6 commit 4dc3c18

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
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
}

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)