File tree Expand file tree Collapse file tree
system/Commands/Translation Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -215,12 +215,14 @@ private function templateFile(array $language = []): string
215215 if ($ language !== []) {
216216 $ languageArrayString = var_export ($ language , true );
217217
218- return <<<PHP
218+ $ code = <<<PHP
219219 <?php
220220
221221 return {$ languageArrayString };
222222
223223 PHP ;
224+
225+ return $ this ->replaceArraySyntax ($ code );
224226 }
225227
226228 return <<<'PHP'
@@ -231,6 +233,47 @@ private function templateFile(array $language = []): string
231233 PHP;
232234 }
233235
236+ private function replaceArraySyntax (string $ code ): string
237+ {
238+ $ tokens = token_get_all ($ code );
239+ $ newTokens = $ tokens ;
240+
241+ foreach ($ tokens as $ i => $ token ) {
242+ if (is_array ($ token )) {
243+ [$ tokenId , $ tokenValue ] = $ token ;
244+
245+ // Replace "array ("
246+ if (
247+ $ tokenId === T_ARRAY
248+ && $ tokens [$ i + 1 ][0 ] === T_WHITESPACE
249+ && $ tokens [$ i + 2 ] === '( '
250+ ) {
251+ $ newTokens [$ i ][1 ] = '[ ' ;
252+ $ newTokens [$ i + 1 ][1 ] = '' ;
253+ $ newTokens [$ i + 2 ] = '' ;
254+ }
255+
256+ // Replace indent
257+ if ($ tokenId === T_WHITESPACE ) {
258+ if (preg_match ('/\n([ ]+)/u ' , $ tokenValue , $ matches )) {
259+ $ newTokens [$ i ][1 ] = "\n{$ matches [1 ]}{$ matches [1 ]}" ;
260+ }
261+ }
262+ } // Replace ")"
263+ elseif ($ token === ') ' ) {
264+ $ newTokens [$ i ] = '] ' ;
265+ }
266+ }
267+
268+ $ output = '' ;
269+
270+ foreach ($ newTokens as $ token ) {
271+ $ output .= $ token [1 ] ?? $ token ;
272+ }
273+
274+ return $ output ;
275+ }
276+
234277 /**
235278 * Create multidimensional array from another keys
236279 */
You can’t perform that action at this time.
0 commit comments