Skip to content

Commit

Permalink
Merge pull request #8138 from Sesquipedalian/lang_editor_update
Browse files Browse the repository at this point in the history
Updates built-in language editor for SMF 3.0
  • Loading branch information
Sesquipedalian authored Mar 16, 2024
2 parents 64b5560 + d270cf3 commit 5ad2a26
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 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 Expand Up @@ -1677,6 +1686,10 @@ protected function cleanLangString(string $string, bool $to_display = true): str
$in_string = 0;
$is_escape = false;

// Present ' entity as a character.
// We'll revert it back to an entity when saving.
$string = str_replace(''', "\\'", $string);

for ($i = 0; $i < strlen($string); $i++) {
// Handle escapes first.
if ($string[$i] == '\\') {
Expand Down Expand Up @@ -1847,8 +1860,10 @@ protected function cleanLangString(string $string, bool $to_display = true): str
}
// A single quote?
elseif ($string[$i] == '\'') {
// Must be in a string so escape it.
$new_string .= '\\';
// Replace with an entity.
$new_string .= '&apos;';

continue;
}

// Finally add the character to the string!
Expand Down

0 comments on commit 5ad2a26

Please sign in to comment.