Skip to content

Commit

Permalink
Updates built-in language editor to work with PSR-12 arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Mar 15, 2024
1 parent 64b5560 commit ceb5709
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Sources/Actions/Admin/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1048,14 +1048,23 @@ function ($val1, $val2) {
}

// These are arrays that need breaking out.
if (strpos($entryValue['entry'], 'array(') === 0 && substr($entryValue['entry'], -1) === ')') {
if (
(
str_starts_with($entryValue['entry'], 'array(')
&& str_ends_with($entryValue['entry'], ')')
)
|| (
str_starts_with($entryValue['entry'], '[')
&& str_ends_with($entryValue['entry'], ']')
)
) {
// No, you may not use multidimensional arrays of Lang::$txt strings. Madness stalks that path.
if (isset($entryValue['subkey'])) {
continue;
}

// Trim off the array construct bits.
$entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], 'array(') + 6, -1);
$entryValue['entry'] = substr($entryValue['entry'], str_starts_with($entryValue['entry'], 'array(') ? 6 : 1, -1);

// This crazy regex extracts each array element, even if the value contains commas or escaped quotes
// The keys can be either integers or strings
Expand Down Expand Up @@ -1190,7 +1199,7 @@ function ($val1, $val2) {
// Now create the string!
$final_saves[$entryKey] = [
'find' => $entryValue['full'],
'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n" . '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');' . $entryValue['cruft'],
'replace' => '// ' . implode("\n// ", explode("\n", rtrim($entryValue['full'], "\n"))) . "\n" . '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = [' . implode(', ', $items) . '];' . $entryValue['cruft'],
];
}
}
Expand Down

0 comments on commit ceb5709

Please sign in to comment.