Skip to content

Commit 1ded62f

Browse files
committed
Improved the name of the config variable for adding persistent strings to translation files. Improved some formatting. Fixed some typos.
1 parent 8e6b46d commit 1ded62f

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

config/laravel-translatable-string-exporter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'*.js',
1313
],
1414

15-
// Indicates weather new lines are allowed in translations.
15+
// Indicates whether new lines are allowed in translations.
1616
'allow-newlines' => false,
1717

1818
// Translation function names.
@@ -23,12 +23,12 @@
2323
'@lang',
2424
],
2525

26-
// Indicates weather you need to sort the translations alphabetically
26+
// Indicates whether you need to sort the translations alphabetically
2727
// by original strings (keys).
2828
// It helps navigate a translation file and detect possible duplicates.
2929
'sort-keys' => true,
3030

31-
// Indicates weather keys added to persistent-strings file should be added
32-
// to translation file
33-
'add-persistent-strings' => false,
31+
// Indicates whether keys from the persistent-strings file should be also added
32+
// to translation files automatically on export if they don't yet exist there.
33+
'add-persistent-strings-to-translations' => false,
3434
];

src/Core/Exporter.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public function export($base_path, $language)
5252
IO::languageFilePath($base_path, self::PERSISTENT_STRINGS_FILENAME_WO_EXT);
5353
$persistent_strings = IO::readTranslationFile($persistent_strings_path);
5454

55-
//if enabled import persistent string to translation file
56-
$new_strings = $this->addPersistentStringIfEnabled($new_strings, $persistent_strings);
55+
// Add persistent strings to the export if enabled.
56+
$new_strings = $this->addPersistentStringsIfEnabled($new_strings, $persistent_strings);
5757

5858
// Merge old an new translations preserving existing translations and persistent strings.
5959
$resulting_strings = $this->mergeStrings($new_strings, $existing_strings, $persistent_strings);
@@ -101,15 +101,18 @@ protected function sortIfEnabled($strings)
101101
}
102102

103103
/**
104-
* Also add keys from persistent-string file to new_string.
104+
* Add keys from the persistent-strings file to new strings array.
105105
*
106106
* @param array $new_strings
107107
* @param array $persistent_strings
108108
* @return array
109109
*/
110-
protected function addPersistentStringIfEnabled($new_strings, $persistent_strings) {
111-
if (config('laravel-translatable-string-exporter.add-persistent-strings', false)) {
112-
$new_strings = array_merge($new_strings, array_combine($persistent_strings, $persistent_strings));
110+
protected function addPersistentStringsIfEnabled($new_strings, $persistent_strings) {
111+
if (config('laravel-translatable-string-exporter.add-persistent-strings-to-translations', false)) {
112+
$new_strings = array_merge(
113+
array_combine($persistent_strings, $persistent_strings),
114+
$new_strings
115+
);
113116
}
114117

115118
return $new_strings;

tests/ExporterTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,12 @@ public function testPersistentTranslations()
256256
$this->assertEquals($expected, $actual);
257257
}
258258

259-
public function testAlsoAddPersistentTranslations()
259+
public function testAddingPersistentStringsToExport()
260260
{
261-
$this->app['config']->set('laravel-translatable-string-exporter.add-persistent-strings', true);
261+
$this->app['config']->set(
262+
'laravel-translatable-string-exporter.add-persistent-strings-to-translations',
263+
true
264+
);
262265

263266
$this->cleanLangsFolder();
264267

@@ -274,12 +277,13 @@ public function testAlsoAddPersistentTranslations()
274277

275278
$this->writeToTranslationFile('es', $content);
276279

277-
// 2. Create a file with the keys of any strings which should persist and added to export file even if they are not contained in the views.
280+
// 2. Create a file with the keys of any strings which should persist
281+
// even if they are not contained in the views.
278282

279283
$persistentContent = json_encode(['name3_en', 'name5_en']);
280284
$this->writeToTranslationFile(Exporter::PERSISTENT_STRINGS_FILENAME_WO_EXT, $persistentContent);
281285

282-
// 3. Create a test view only containing a new string and a string that also in persistent.
286+
// 3. Create a test view only containing a new string and a string that is also in persistent strings.
283287

284288
$this->createTestView("{{ __('name1_en') . __('name2_en') . __('name3_en') . __('name4_en') }}");
285289

@@ -289,17 +293,13 @@ public function testAlsoAddPersistentTranslations()
289293

290294
$actual = $this->getTranslationFileContent('es');
291295

292-
// The new and persistent, strings should be added. The rest should remain.
296+
// The new and persistent strings should be added. The rest should remain.
293297

294-
$expected = [
295-
'name1_en' => 'name1_es',
296-
'name2_en' => 'name2_es',
297-
'name3_en' => 'name3_es',
298+
$expected = array_merge($existing_translations, [
298299
'name4_en' => 'name4_en',
299300
'name5_en' => 'name5_en',
300-
];
301+
]);
301302

302303
$this->assertEquals($expected, $actual);
303-
304304
}
305305
}

0 commit comments

Comments
 (0)