Skip to content

Commit 40a7ef9

Browse files
committed
Also add keys from persistent-string file to translation file
1 parent 7dc77d5 commit 40a7ef9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

config/laravel-translatable-string-exporter.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727
// by original strings (keys).
2828
// It helps navigate a translation file and detect possible duplicates.
2929
'sort-keys' => true,
30+
31+
// Indicates weather keys added to persistent-strings file should be added
32+
// to translation file
33+
'add-persistent-strings' => false,
3034
];

src/Core/Exporter.php

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ 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);
57+
5558
// Merge old an new translations preserving existing translations and persistent strings.
5659
$resulting_strings = $this->mergeStrings($new_strings, $existing_strings, $persistent_strings);
5760

@@ -97,6 +100,21 @@ protected function sortIfEnabled($strings)
97100
return $strings;
98101
}
99102

103+
/**
104+
* Also add keys from persistent-string file to new_string.
105+
*
106+
* @param array $new_strings
107+
* @param array $persistent_strings
108+
* @return array
109+
*/
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));
113+
}
114+
115+
return $new_strings;
116+
}
117+
100118
/**
101119
* Filtering an array by its keys using a callback.
102120
* Supports PHP < 5.6.0. Use array_filter($array, $callback, ARRAY_FILTER_USE_KEY) instead

0 commit comments

Comments
 (0)