Sepia\PoParser::setEntry PHP Method

setEntry() public method

If entry not found returns false. If $createNew is true, a new entry will be created. $entry is an array that can contain following indexes: - msgid: String Array. Required. - msgstr: String Array. Required. - reference: String Array. - msgctxt: String. Disambiguating context. - tcomment: String Array. Translator comments. - ccomment: String Array. Source comments. - msgid_plural: String Array. - flags: Array. List of entry flags. Example: array('fuzzy','php-format') - previous: Array: Contains previous untranslated strings in a sub array with msgid and msgstr.
public setEntry ( String $msgid, Array $entry, boolean $createNew = true )
$msgid String Id of entry. Be aware that some entries have a multiline msgid. In that case \n must be replaced by the value of 'multiline-glue' option (by default "<##EOL##>").
$entry Array Array with all entry data. Fields not setted will be removed.
$createNew boolean If msgid not found, it will create a new entry. By default true. You want to set this to false if need to change the msgid of an entry.
    public function setEntry($msgid, $entry, $createNew = true)
    {
        // In case of new entry
        if (!isset($this->entries[$msgid])) {
            if ($createNew == false) {
                return;
            }
            $this->entries[$msgid] = $entry;
        } else {
            // Be able to change msgid.
            if ($msgid !== $entry['msgid']) {
                unset($this->entries[$msgid]);
                $new_msgid = is_array($entry['msgid']) ? implode($this->options['multiline-glue'], $entry['msgid']) : $entry['msgid'];
                $this->entries[$new_msgid] = $entry;
            } else {
                $this->entries[$msgid] = $entry;
            }
        }
    }

Usage Example

Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $inFile = new FileHandler($input->getArgument('from'));
     $outFileLocation = $input->getArgument('to');
     $poParser = new PoParser($inFile);
     $messages = $poParser->parse($inFile);
     foreach ($messages as $msgid => $message) {
         $message = $this->translateMessage($message);
         $poParser->setEntry($msgid, $message, false);
     }
     $poParser->writeFile($outFileLocation);
 }