Ticket #25631: pomo.diff
File pomo.diff, 10.4 KB (added by , 12 years ago) |
---|
-
trunk/tests/phpunit/tests/pomo/po.php
37 37 } 38 38 39 39 function test_prepend_each_line() { 40 $this->assertEquals('baba_', @PO::prepend_each_line('', 'baba_'));41 $this->assertEquals('baba_dyado', @PO::prepend_each_line('dyado', 'baba_'));42 $this->assertEquals("# baba\n# dyado\n# \n", @PO::prepend_each_line("baba\ndyado\n\n", '# '));40 $this->assertEquals('baba_', PO::prepend_each_line('', 'baba_')); 41 $this->assertEquals('baba_dyado', PO::prepend_each_line('dyado', 'baba_')); 42 $this->assertEquals("# baba\n# dyado\n# \n", PO::prepend_each_line("baba\ndyado\n\n", '# ')); 43 43 } 44 44 45 45 function test_poify() { 46 46 //simple 47 $this->assertEquals('"baba"', @PO::poify('baba'));47 $this->assertEquals('"baba"', PO::poify('baba')); 48 48 //long word 49 $this->assertEquals($this->po_a90, @PO::poify($this->a90));49 $this->assertEquals($this->po_a90, PO::poify($this->a90)); 50 50 // tab 51 $this->assertEquals('"ba\tba"', @PO::poify("ba\tba"));51 $this->assertEquals('"ba\tba"', PO::poify("ba\tba")); 52 52 // do not add leading empty string of one-line string ending on a newline 53 $this->assertEquals('"\\\\a\\\\n\\n"', @PO::poify("\a\\n\n"));53 $this->assertEquals('"\\\\a\\\\n\\n"', PO::poify("\a\\n\n")); 54 54 // backslash 55 $this->assertEquals('"ba\\\\ba"', @PO::poify('ba\\ba'));55 $this->assertEquals('"ba\\\\ba"', PO::poify('ba\\ba')); 56 56 // random wordpress.pot string 57 57 $src = 'Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'; 58 $this->assertEquals("\"Categories can be selectively converted to tags using the <a href=\\\"%s\\\">category to tag converter</a>.\"", @PO::poify($src));58 $this->assertEquals("\"Categories can be selectively converted to tags using the <a href=\\\"%s\\\">category to tag converter</a>.\"", PO::poify($src)); 59 59 60 $this->assertEquals($this->po_mail, @PO::poify($this->mail));60 $this->assertEquals($this->po_mail, PO::poify($this->mail)); 61 61 } 62 62 63 63 function test_unpoify() { 64 $this->assertEquals('baba', @PO::unpoify('"baba"'));65 $this->assertEquals("baba\ngugu", @PO::unpoify('"baba\n"'."\t\t\t\n".'"gugu"'));66 $this->assertEquals($this->a90, @PO::unpoify($this->po_a90));67 $this->assertEquals('\\t\\n', @PO::unpoify('"\\\\t\\\\n"'));64 $this->assertEquals('baba', PO::unpoify('"baba"')); 65 $this->assertEquals("baba\ngugu", PO::unpoify('"baba\n"'."\t\t\t\n".'"gugu"')); 66 $this->assertEquals($this->a90, PO::unpoify($this->po_a90)); 67 $this->assertEquals('\\t\\n', PO::unpoify('"\\\\t\\\\n"')); 68 68 // wordwrapped 69 $this->assertEquals('babadyado', @PO::unpoify("\"\"\n\"baba\"\n\"dyado\""));70 $this->assertEquals($this->mail, @PO::unpoify($this->po_mail));69 $this->assertEquals('babadyado', PO::unpoify("\"\"\n\"baba\"\n\"dyado\"")); 70 $this->assertEquals($this->mail, PO::unpoify($this->po_mail)); 71 71 } 72 72 73 73 function test_export_entry() { 74 74 $entry = new Translation_Entry(array('singular' => 'baba')); 75 $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", @PO::export_entry($entry));75 $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", PO::export_entry($entry)); 76 76 // plural 77 77 $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas')); 78 78 $this->assertEquals('msgid "baba" 79 79 msgid_plural "babas" 80 80 msgstr[0] "" 81 msgstr[1] ""', @PO::export_entry($entry));81 msgstr[1] ""', PO::export_entry($entry)); 82 82 $entry = new Translation_Entry(array('singular' => 'baba', 'translator_comments' => "baba\ndyado")); 83 83 $this->assertEquals('# baba 84 84 # dyado 85 85 msgid "baba" 86 msgstr ""', @PO::export_entry($entry));86 msgstr ""', PO::export_entry($entry)); 87 87 $entry = new Translation_Entry(array('singular' => 'baba', 'extracted_comments' => "baba")); 88 88 $this->assertEquals('#. baba 89 89 msgid "baba" 90 msgstr ""', @PO::export_entry($entry));90 msgstr ""', PO::export_entry($entry)); 91 91 $entry = new Translation_Entry(array( 92 92 'singular' => 'baba', 93 93 'extracted_comments' => "baba", … … 96 96 #: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 97 97 #: 29 98 98 msgid "baba" 99 msgstr ""', @PO::export_entry($entry));99 msgstr ""', PO::export_entry($entry)); 100 100 $entry = new Translation_Entry(array('singular' => 'baba', 'translations' => array())); 101 $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", @PO::export_entry($entry));101 $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", PO::export_entry($entry)); 102 102 103 103 $entry = new Translation_Entry(array('singular' => 'baba', 'translations' => array('куку', 'буку'))); 104 $this->assertEquals("msgid \"baba\"\nmsgstr \"куку\"", @PO::export_entry($entry));104 $this->assertEquals("msgid \"baba\"\nmsgstr \"куку\"", PO::export_entry($entry)); 105 105 106 106 $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку'))); 107 107 $this->assertEquals('msgid "baba" 108 108 msgid_plural "babas" 109 msgstr[0] "кукубуку"', @PO::export_entry($entry));109 msgstr[0] "кукубуку"', PO::export_entry($entry)); 110 110 111 111 $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку', 'кукуруку', 'бабаяга'))); 112 112 $this->assertEquals('msgid "baba" 113 113 msgid_plural "babas" 114 114 msgstr[0] "кукубуку" 115 115 msgstr[1] "кукуруку" 116 msgstr[2] "бабаяга"', @PO::export_entry($entry));116 msgstr[2] "бабаяга"', PO::export_entry($entry)); 117 117 // context 118 118 $entry = new Translation_Entry(array('context' => 'ctxt', 'singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку', 'кукуруку', 'бабаяга'), 'flags' => array('fuzzy', 'php-format'))); 119 119 $this->assertEquals('#, fuzzy, php-format … … 122 122 msgid_plural "babas" 123 123 msgstr[0] "кукубуку" 124 124 msgstr[1] "кукуруку" 125 msgstr[2] "бабаяга"', @PO::export_entry($entry));125 msgstr[2] "бабаяга"', PO::export_entry($entry)); 126 126 } 127 127 128 128 function test_export_entries() { -
trunk/src/wp-includes/pomo/mo.php
2 2 /** 3 3 * Class for working with MO files 4 4 * 5 * @version $Id: mo.php 7 18 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: mo.php 780 2013-06-19 12:12:28Z markoheijnen $ 6 6 * @package pomo 7 7 * @subpackage mo 8 8 */ … … 207 207 $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); 208 208 209 209 if ('' === $original) { 210 $this->set_headers($this->make_headers($translation)); 210 $headers = $this->make_headers($translation); 211 $this->set_headers($headers); 211 212 } else { 212 213 $entry = &$this->make_entry($original, $translation); 213 214 $this->entries[$entry->key()] = &$entry; -
trunk/src/wp-includes/pomo/po.php
2 2 /** 3 3 * Class for working with PO files 4 4 * 5 * @version $Id: po.php 718 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: po.php 812 2013-10-18 17:34:16Z markoheijnen $ 6 6 * @package pomo 7 7 * @subpackage po 8 8 */ … … 97 97 * @param string $string the string to format 98 98 * @return string the poified string 99 99 */ 100 function poify($string) {100 public static function poify($string) { 101 101 $quote = '"'; 102 102 $slash = '\\'; 103 103 $newline = "\n"; … … 128 128 * @param string $string PO-formatted string 129 129 * @return string enascaped string 130 130 */ 131 function unpoify($string) {131 public static function unpoify($string) { 132 132 $escapes = array('t' => "\t", 'n' => "\n", '\\' => '\\'); 133 133 $lines = array_map('trim', explode("\n", $string)); 134 134 $lines = array_map(array('PO', 'trim_quotes'), $lines); … … 160 160 * @param string $string prepend lines in this string 161 161 * @param string $with prepend lines with this string 162 162 */ 163 function prepend_each_line($string, $with) {163 public static function prepend_each_line($string, $with) { 164 164 $php_with = var_export($with, true); 165 165 $lines = explode("\n", $string); 166 166 // do not prepend the string on the last empty line, artefact by explode … … 180 180 * @param string $char character to denote a special PO comment, 181 181 * like :, default is a space 182 182 */ 183 function comment_block($text, $char=' ') {183 public static function comment_block($text, $char=' ') { 184 184 $text = wordwrap($text, PO_MAX_LINE_LEN - 3); 185 185 return PO::prepend_each_line($text, "#$char "); 186 186 } … … 193 193 * @return string|bool PO-style formatted string for the entry or 194 194 * false if the entry is empty 195 195 */ 196 function export_entry(&$entry) {196 public static function export_entry(&$entry) { 197 197 if (is_null($entry->singular)) return false; 198 198 $po = array(); 199 199 if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); … … 223 223 $res = $this->read_entry($f, $lineno); 224 224 if (!$res) break; 225 225 if ($res['entry']->singular == '') { 226 $this->set_headers($this->make_headers($res['entry']->translations[0])); 226 $headers = $this->make_headers($res['entry']->translations[0]); 227 $this->set_headers($headers); 227 228 } else { 228 229 $this->add_entry($res['entry']); 229 230 } … … 274 275 return false; 275 276 } 276 277 // add comment 277 $this->add_comment_to_entry($entry, $line); ;278 $this->add_comment_to_entry($entry, $line); 278 279 } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) { 279 280 if ($is_final($context)) { 280 281 PO::read_line($f, 'put-back'); … … 375 376 } 376 377 } 377 378 378 function trim_quotes($s) {379 public static function trim_quotes($s) { 379 380 if ( substr($s, 0, 1) == '"') $s = substr($s, 1); 380 381 if ( substr($s, -1, 1) == '"') $s = substr($s, 0, -1); 381 382 return $s; 382 383 } 383 384 } 384 endif; 385 endif; 386 No newline at end of file -
trunk/src/wp-includes/pomo/translations.php
2 2 /** 3 3 * Class for a set of entries for translation and their associated headers 4 4 * 5 * @version $Id: translations.php 718 2012-10-31 00:32:02Z nbachiyski$5 * @version $Id: translations.php 811 2013-10-18 17:26:21Z markoheijnen $ 6 6 * @package pomo 7 7 * @subpackage translations 8 8 */