1313
1414use CodeIgniter \CLI \BaseCommand ;
1515use CodeIgniter \CLI \CLI ;
16+ use CodeIgniter \Commands \Translation \LocalizationFinder \ArrayHelper ;
1617use Config \App ;
1718use Locale ;
1819use RecursiveDirectoryIterator ;
@@ -57,7 +58,7 @@ public function run(array $params)
5758
5859 if (ENVIRONMENT === 'testing ' ) {
5960 $ currentDir = SUPPORTPATH . 'Services/ ' ;
60- $ this ->languagePath = SUPPORTPATH . 'Language/ ' ;
61+ $ this ->languagePath = SUPPORTPATH . 'Language ' ;
6162 }
6263
6364 if (is_string ($ optionLocale )) {
@@ -112,7 +113,7 @@ private function findTranslationsInFile($file): array
112113 $ fileContent = file_get_contents ($ file ->getRealPath ());
113114 preg_match_all ('/lang\( \'([._a-z0-9\-]+) \'\)/ui ' , $ fileContent , $ matches );
114115
115- if (empty ( $ matches [1 ]) ) {
116+ if ([] === $ matches [1 ]) {
116117 return [];
117118 }
118119
@@ -201,38 +202,6 @@ private function buildMultiArray(array $fromKeys, string $lastArrayValue = ''):
201202 return $ newArray ;
202203 }
203204
204- /**
205- * Compare recursive two arrays and return new array (difference)
206- */
207- private function arrayDiffRecursive (array $ originalArray , array $ compareArray ): array
208- {
209- $ difference = [];
210-
211- if (count ($ compareArray ) < 1 ) {
212- return $ originalArray ;
213- }
214-
215- foreach ($ originalArray as $ originalKey => $ originalValue ) {
216- if (is_array ($ originalValue )) {
217- $ diffArrays = null ;
218-
219- if (isset ($ compareArray [$ originalKey ])) {
220- $ diffArrays = $ this ->arrayDiffRecursive ($ originalValue , $ compareArray [$ originalKey ]);
221- } else {
222- $ difference [$ originalKey ] = $ originalValue ;
223- }
224-
225- if (! empty ($ diffArrays )) {
226- $ difference [$ originalKey ] = $ diffArrays ;
227- }
228- } elseif (is_string ($ originalValue ) && ! array_key_exists ($ originalKey , $ compareArray )) {
229- $ difference [$ originalKey ] = $ originalValue ;
230- }
231- }
232-
233- return $ difference ;
234- }
235-
236205 /**
237206 * Convert multi arrays to specific CLI table rows (flat array)
238207 */
@@ -255,19 +224,6 @@ private function arrayToTableRows(string $langFileName, array $array): array
255224 return $ rows ;
256225 }
257226
258- private function arrayCountRecursive (array $ array , int $ counter = 0 ): int
259- {
260- foreach ($ array as $ value ) {
261- if (! is_array ($ value )) {
262- $ counter ++;
263- } else {
264- $ counter = $ this ->arrayCountRecursive ($ value , $ counter );
265- }
266- }
267-
268- return $ counter ;
269- }
270-
271227 private function languageKeysDump (array $ inputArray ): string
272228 {
273229 return var_export ($ inputArray , true );
@@ -317,8 +273,8 @@ private function process(string $currentDir, string $currentLocale): void
317273 $ languageStoredKeys = require $ languageFilePath ;
318274 }
319275
320- $ languageDiff = $ this -> arrayDiffRecursive ($ foundLanguageKeys [$ langFileName ], $ languageStoredKeys );
321- $ countNewKeys += $ this -> arrayCountRecursive ($ languageDiff );
276+ $ languageDiff = ArrayHelper :: recursiveDiff ($ foundLanguageKeys [$ langFileName ], $ languageStoredKeys );
277+ $ countNewKeys += ArrayHelper :: recursiveCount ($ languageDiff );
322278
323279 if ($ this ->showNew ) {
324280 $ tableRows = array_merge ($ this ->arrayToTableRows ($ langFileName , $ languageDiff ), $ tableRows );
@@ -339,7 +295,7 @@ private function process(string $currentDir, string $currentLocale): void
339295 }
340296 }
341297
342- if ($ this ->showNew && ! empty ( $ tableRows) ) {
298+ if ($ this ->showNew && [] !== $ tableRows ) {
343299 sort ($ tableRows );
344300 CLI ::table ($ tableRows , ['File ' , 'Key ' ]);
345301 }
0 commit comments