Skip to content

Gettext\Extractors\Mo parsing plural messages. #25

@acgrid

Description

@acgrid

Hi,
The procedure in Gettext\Extractors\Mo seems to extract basic string without split singular/plural strings delimited by NULL character.

From https://github.com/oscarotero/Gettext/blob/master/Gettext/Extractors/Mo.php#L52

        for ($i = 0; $i < $total; $i++) {
            $stream->seekto($table_originals[$i * 2 + 2]);
            $original = $stream->read($table_originals[$i * 2 + 1]);

            if ($original) {
                $stream->seekto($table_translations[$i * 2 + 2]);
                $entries->insert(null, $original)->setTranslation($stream->read($table_translations[$i * 2 + 1]));
            }
        }

This my workaround, while it looks a bit ugly and not very safe.

if ($original) {
    $stream->seekto($table_translations[$i * 2 + 2]);
    $original = explode("\000",$original);
    $translated = explode("\000",$stream->read($table_translations[$i * 2 + 1]));
    $singular = $original[0];
    $plural = isset($original[1]) ? $original[1] : '';
    $translation = $entries->insert(null, $original[0], $plural);
    $translation->setTranslation($translated[0]);
    if($plural) $translation->setPluralTranslation(isset($translated[1]) ? $translated[1] : $translated[0]);
}

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions