Kdyby\Translation\Extractors\LatteExtractor::extractFile PHP Method

extractFile() public method

Extracts translation messages from a file to the catalogue.
public extractFile ( string $file, Symfony\Component\Translation\MessageCatalogue $catalogue )
$file string The path to look into
$catalogue Symfony\Component\Translation\MessageCatalogue The catalogue
    public function extractFile($file, MessageCatalogue $catalogue)
    {
        $buffer = NULL;
        $parser = new Parser();
        $parser->shortNoEscape = TRUE;
        foreach ($tokens = $parser->parse(file_get_contents($file)) as $token) {
            if ($token->type !== $token::MACRO_TAG || !in_array($token->name, ['_', '/_'], TRUE)) {
                if ($buffer !== NULL) {
                    $buffer .= $token->text;
                }
                continue;
            }
            if ($token->name === '/_' || $token->name === '_' && $token->closing === TRUE) {
                $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $buffer, $buffer);
                $buffer = NULL;
            } elseif ($token->name === '_' && empty($token->value)) {
                $buffer = '';
            } else {
                $args = new MacroTokens($token->value);
                $writer = new PhpWriter($args, $token->modifiers);
                $message = $writer->write('%node.word');
                if (in_array(substr(trim($message), 0, 1), ['"', '\''], TRUE)) {
                    $message = substr(trim($message), 1, -1);
                }
                $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $message, $message);
            }
        }
    }