php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
688 stars 134 forks source link

Wrong removing multi line disabled translations #262

Closed lbfeenix closed 3 years ago

lbfeenix commented 3 years ago

Hi, I found one minor problem but for my usecase its not minor. If I have disabled multiline translations in .po file, so PoLoader can not load it correctly, load only first line of disabled. Will be possible fix PoLoader.php function loadString from line 26 with this or similar code?

        //Multiline
        while (substr($line, -1, 1) === '"'
            && $nextLine !== false
            && (substr(trim($nextLine), 0, 1) === '"' || substr(trim($nextLine), 0, 4) === '#~ "')
        ) {
            if (substr(trim($nextLine), 0, 1) === '"') { // Normal multiline
                $line = substr($line, 0, -1).substr(trim($nextLine), 1);
            }
            if (substr(trim($nextLine), 0, 4) === '#~ "') { // Disabled multiline
                $line = substr($line, 0, -1).substr(trim($nextLine), 4);
            }
            $nextLine = next($lines);
        }
oscarotero commented 3 years ago

Hi, thank you for warning about this. Do you want to work on a PR including test reproducing this error?

lbfeenix commented 3 years ago

Hi, although I'm not new to using git or writing code, I'm using github for the first time, so I try create PR with some comment (I hope it have sense), but do not know how create some test here, or what type of test do you mean.

oscarotero commented 3 years ago

v5.5.2 released including the fix for this issue. Thanks for your contribution!