Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LanguageHelper.php to handle translated text with embedded new lines. #42456

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Update LanguageHelper.php
Corrections for phpcs errors.
  • Loading branch information
BrainforgeUK authored Dec 26, 2023
commit d2bb72b9b02ea745367fb6882b04b4f299ec8e29
20 changes: 12 additions & 8 deletions libraries/src/Language/LanguageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,22 @@ public static function parseIniFile($fileName, $debug = false)
*
* @since __DEPLOY_VERSION__
*/
protected static function parseMultilineIni($inifileContents) {
protected static function parseMultilineIni($inifileContents)
{
$lines = explode("\n", $inifileContents);

$nameValuePairs = [];

for ($l=0; $l<count($lines); $l++) {
for ($l=0; $l < count($lines); $l++) {
BrainforgeUK marked this conversation as resolved.
Show resolved Hide resolved
$line = trim($lines[$l]);

if (empty($line)) continue;
if (empty($line)) {
continue;
}

if ($line[0] == ';') continue;
if ($line[0] == ';') {
continue;
}

$lineParts = explode('=', $line);
if (count($lineParts) != 2) {
Expand All @@ -492,7 +497,7 @@ protected static function parseMultilineIni($inifileContents) {
$nameValuePairs[$lineParts[0]] = '';
continue;
}
$nameValuePairs[$lineParts[0]] = substr($lineParts[1], 1, strlen($lineParts[1])-2);
$nameValuePairs[$lineParts[0]] = substr($lineParts[1], 1, strlen($lineParts[1]) - 2);

continue;
}
Expand All @@ -501,15 +506,14 @@ protected static function parseMultilineIni($inifileContents) {
// Found a string with embedded new lines
$nameValuePair = $lineParts[1];

while (++$l<count($lines)) {
while (++$l < count($lines)) {
$line = trim($lines[$l]);

$nameValuePair .= "\n" . $line;

if (str_ends_with($line, '"')) {

if (!str_ends_with($line, '\\"')) {
$nameValuePairs[$lineParts[0]] = substr($nameValuePair, 1, strlen($nameValuePair)-1);
$nameValuePairs[$lineParts[0]] = substr($nameValuePair, 1, strlen($nameValuePair) - 1);

continue 2;
}
Expand Down