Jyxo\Gettext\Parser::parse PHP Method

parse() protected method

Walks through the file, splits it on empty lines and tries to parse each fragment using the defined parser class ({@link \Jyxo\Gettext\Parser\Item} by default). Does not work with the file header.
See also: Jyxo\Gettext\Parser::$items
See also: Jyxo\Gettext\Parser\Item
protected parse ( string $file )
$file string Path to the PO file
    protected function parse(string $file)
    {
        $linenumber = 0;
        $chunks = [];
        $file = file($file);
        foreach ($file as $line) {
            if ($line == "\n" || $line == "\r\n") {
                ++$linenumber;
            } else {
                if (!array_key_exists($linenumber, $chunks)) {
                    $chunks[$linenumber] = '';
                }
                $chunks[$linenumber] .= $line;
            }
        }
        $header = array_shift($chunks);
        $this->header = new $this->headerClass($header);
        foreach ($chunks as $chunk) {
            try {
                $this->items[] = new $this->itemClass($chunk);
            } catch (\Jyxo\Gettext\Parser\Exception $e) {
                // Do nothing, msgid is empty
            }
        }
    }