diff --git a/php-templates/translations.php b/php-templates/translations.php index a26f5e71..a7e7e55c 100644 --- a/php-templates/translations.php +++ b/php-templates/translations.php @@ -169,10 +169,11 @@ protected function linesFromPhpFile($file) $arrayDepth = -1; $depthKeys = []; - foreach ($tokens as $token) { + foreach ($tokens as $index => $token) { if (!is_array($token)) { if ($token === '[') { $inArrayKey = true; + $currentIndex = 0; $arrayDepth++; } @@ -190,6 +191,15 @@ protected function linesFromPhpFile($file) } if ($inArrayKey && $token[0] === T_CONSTANT_ENCAPSED_STRING) { + $nextToken = isset($tokens[$index + 1]) ? $tokens[$index + 1] : null; + $nextValue = isset($nextToken[1]) ? $nextToken[1] : $nextToken; + + if ($nextValue === ',' || str_contains($nextValue, "\n")) { + $token[1] = $currentIndex; + + $currentIndex++; + } + $depthKeys[$arrayDepth] = trim($token[1], '"\''); \Illuminate\Support\Arr::set($found, implode('.', $depthKeys), $token[2]); diff --git a/src/templates/translations.ts b/src/templates/translations.ts index a8ebd7cd..a234f2e8 100644 --- a/src/templates/translations.ts +++ b/src/templates/translations.ts @@ -169,10 +169,11 @@ $translator = new class $arrayDepth = -1; $depthKeys = []; - foreach ($tokens as $token) { + foreach ($tokens as $index => $token) { if (!is_array($token)) { if ($token === '[') { $inArrayKey = true; + $currentIndex = 0; $arrayDepth++; } @@ -190,6 +191,15 @@ $translator = new class } if ($inArrayKey && $token[0] === T_CONSTANT_ENCAPSED_STRING) { + $nextToken = isset($tokens[$index + 1]) ? $tokens[$index + 1] : null; + $nextValue = isset($nextToken[1]) ? $nextToken[1] : $nextToken; + + if ($nextValue === ',' || str_contains($nextValue, "\\n")) { + $token[1] = $currentIndex; + + $currentIndex++; + } + $depthKeys[$arrayDepth] = trim($token[1], '"\\''); \\Illuminate\\Support\\Arr::set($found, implode('.', $depthKeys), $token[2]);