Skip to content

Commit

Permalink
fix #48
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Aug 23, 2016
1 parent 3576ed6 commit 4dc3c18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Commands/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ private function syncKeysFromFiles($translationFiles)
if (isset($allKeysInFiles[$fileName])) {
$missingKeys = array_diff($allKeysInFiles[$fileName], array_keys(array_dot($fileContent)));

foreach ($missingKeys as $i => $missingKey) {
if (Arr::has($fileContent, $missingKey)) {
unset($missingKeys[$i]);
}
}

$this->fillMissingKeys($fileName, $missingKeys, $languageKey);
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/SyncCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,23 @@ public function testCommandOutputForMissingSubKey()
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
}

public function testItDoesntOverrideParentKey()
{
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));

file_put_contents(__DIR__.'/views_temp/user.blade.php', '{{ trans(\'user.name\') }}');

$this->createTempFiles([
'en' => ['user' => "<?php\n return ['name' => ['middle' => 'middle']];"],
]);

$this->artisan('langman:sync');

$userENFile = (array) include $this->app['config']['langman.path'].'/en/user.php';

$this->assertEquals(['middle' => 'middle'], $userENFile['name']);

array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
}
}

0 comments on commit 4dc3c18

Please sign in to comment.