Exemple #1
0
 /**
  * Exports headers to a PO entry
  *
  * @return string msgid/msgstr PO entry for this PO file headers, doesn't
  *                contain newline at the end
  */
 public function export_headers()
 {
     $header_string = '';
     foreach ($this->headers as $header => $value) {
         $header_string .= "{$header}: {$value}\n";
     }
     $poified = PO::poify($header_string);
     if ($this->comments_before_headers) {
         $before_headers = PO::prepend_each_line(rtrim($this->comments_before_headers) . "\n", '# ');
     } else {
         $before_headers = '';
     }
     return rtrim("{$before_headers}msgid \"\"\nmsgstr {$poified}");
 }
Exemple #2
0
 function test_poify()
 {
     //simple
     $this->assertEquals('"baba"', PO::poify('baba'));
     //long word
     $this->assertEquals($this->po_a90, PO::poify($this->a90));
     // tab
     $this->assertEquals('"ba\\tba"', PO::poify("ba\tba"));
     // do not add leading empty string of one-line string ending on a newline
     $this->assertEquals('"\\\\a\\\\n\\n"', PO::poify("\\a\\n\n"));
     // backslash
     $this->assertEquals('"ba\\\\ba"', PO::poify('ba\\ba'));
     // random wordpress.pot string
     $src = 'Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.';
     $this->assertEquals("\"Categories can be selectively converted to tags using the <a href=\\\"%s\\\">category to tag converter</a>.\"", PO::poify($src));
     $this->assertEquals($this->po_mail, PO::poify($this->mail));
 }
Exemple #3
0
 /**
  * Builds a string from the entry for inclusion in PO file
  *
  * @static
  * @param object &$entry the entry to convert to po string
  * @return string|bool PO-style formatted string for the entry or
  * 	false if the entry is empty
  */
 function export_entry(&$entry)
 {
     if (is_null($entry->singular)) {
         return false;
     }
     $po = array();
     if (!empty($entry->translator_comments)) {
         $po[] = PO::comment_block($entry->translator_comments);
     }
     if (!empty($entry->extracted_comments)) {
         $po[] = PO::comment_block($entry->extracted_comments, '.');
     }
     if (!empty($entry->references)) {
         $po[] = PO::comment_block(implode(' ', $entry->references), ':');
     }
     if (!empty($entry->flags)) {
         $po[] = PO::comment_block(implode(", ", $entry->flags), ',');
     }
     if (!is_null($entry->context)) {
         $po[] = 'msgctxt ' . PO::poify($entry->context);
     }
     $po[] = 'msgid ' . PO::poify($entry->singular);
     if (!$entry->is_plural) {
         $translation = empty($entry->translations) ? '' : $entry->translations[0];
         $po[] = 'msgstr ' . PO::poify($translation);
     } else {
         $po[] = 'msgid_plural ' . PO::poify($entry->plural);
         $translations = empty($entry->translations) ? array('', '') : $entry->translations;
         foreach ($translations as $i => $translation) {
             $po[] = "msgstr[{$i}] " . PO::poify($translation);
         }
     }
     return implode("\n", $po);
 }
Exemple #4
0
 /**
  * Write an empty POT file containing all strings found
  *
  * @param string $file File to write to
  */
 public function writePot($file)
 {
     $output = "# Copyright (C) " . date("Y") . " Next Buzz" . PHP_EOL . "msgid \"\"" . PHP_EOL . "msgstr \"\"" . PHP_EOL . "\"Project-Id-Version: buzz-seo\\n\"" . PHP_EOL . "\"POT-Creation-Date: " . date("Y-m-d H:i:sO") . "\\n\"" . PHP_EOL . "\"MIME-Version: 1.0\\n\"" . PHP_EOL . "\"Content-Type: text/plain; charset=UTF-8\\n\"" . PHP_EOL . "\"Content-Transfer-Encoding: 8bit\\n\"" . PHP_EOL . "\"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\\n\"" . PHP_EOL . "\"Language-Team: Next Buzz, Bas de Kort <*****@*****.**>\\n\"" . PHP_EOL . PHP_EOL;
     require_once ABSPATH . '/wp-includes/pomo/po.php';
     $poifyString = new \PO();
     foreach ($this->findings as $translatable => $locations) {
         $output .= "#:";
         foreach ($locations as $line => $location) {
             $output .= " " . $location . ":" . $line;
         }
         $output .= PHP_EOL . "msgid " . $poifyString->poify(StringParser::factory($translatable)->trimMultiline()) . PHP_EOL . "msgstr \"\"" . PHP_EOL . PHP_EOL;
     }
     file_put_contents($file, $output);
 }