Skip to content

Commit bdc0f16

Browse files
committed
Merge with upstream
2 parents 25a944f + 33cb90f commit bdc0f16

File tree

7 files changed

+46
-9
lines changed

7 files changed

+46
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: php
22

33
php:
4-
- 5.5.9
54
- 5.6
65
- 7.0
6+
- 7.1
77

88
sudo: true
99

ISSUE_TEMPLATE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- Laravel Version: #.#.#
2+
- PHP Version:
3+
- Database Driver & Version:
4+
5+
### Description:
6+
7+
8+
### Steps to reproduce:

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
],
1414
"require": {
1515
"php": "^5.5.9 || ^7.0",
16-
"illuminate/support": "5.1.* || 5.2.*",
17-
"illuminate/console": "5.1.* || 5.2.*",
18-
"illuminate/filesystem": "5.1.* || 5.2.*",
16+
"illuminate/support": "5.1.* || 5.2.* || 5.3.*",
17+
"illuminate/console": "5.1.* || 5.2.* || 5.3.*",
18+
"illuminate/filesystem": "5.1.* || 5.2.* || 5.3.*",
1919
"phpoffice/phpexcel": "^1.8"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit" : "^4.8 || ^5.0",
23-
"orchestra/testbench": "^3.2",
23+
"orchestra/testbench": "3.3.x-dev",
24+
"orchestra/database": "3.3.x-dev",
2425
"mockery/mockery": "~0.9.4"
2526
},
2627
"autoload": {

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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private function stringLineMaker($array, $prepend = '')
232232

233233
$output .= "\n{$prepend} '{$key}' => [{$value}\n{$prepend} ],";
234234
} else {
235-
$value = addslashes($value);
235+
$value = str_replace('\"', '"', addslashes($value));
236236

237237
$output .= "\n{$prepend} '{$key}' => '{$value}',";
238238
}
@@ -315,8 +315,9 @@ public function getAllViewFilesWithTranslations()
315315
$functions = ['trans', 'trans_choice', 'Lang::get', 'Lang::choice', 'Lang::trans', 'Lang::transChoice', '@lang', '@choice'];
316316

317317
$pattern =
318-
// See https://regex101.com/r/jS5fX0/2
319-
'[^\w|>]'. // Must not start with any alphanum or _ or >
318+
// See https://regex101.com/r/jS5fX0/3
319+
'[^\w]'. // Must not start with any alphanum or _
320+
'(?<!->)'. // Must not start with ->
320321
'('.implode('|', $functions).')'.// Must start with one of the functions
321322
"\(".// Match opening parentheses
322323
"[\'\"]".// Match " or '
@@ -381,7 +382,7 @@ public function getKeysExistingInALanguageButNotTheOther($values)
381382
}
382383

383384
foreach ($this->languages() as $languageName) {
384-
if (! Arr::has($values, "{$fileName}.{$languageName}.{$key}")) {
385+
if (! Arr::has($values, "{$fileName}.{$languageName}.{$key}") && ! array_key_exists("{$fileName}.{$languageName}.{$key}", $values)) {
385386
$missing[] = "{$fileName}.{$key}:{$languageName}";
386387
}
387388
}

tests/ManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function testWriteFile()
9191
$values = [
9292
'name' => ['first' => 'first', 'last' => ['last1' => '1', 'last2' => 2]],
9393
'age' => 'age',
94+
'double_quotes' => '"with quotes"',
95+
'quotes' => "With some ' quotes",
9496
];
9597

9698
$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.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.blade.php'));
90+
}
7291
}

0 commit comments

Comments
 (0)