Mageia Bugzilla – Attachment 4216 Details for
Bug 10424
License for Mageia on web site
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
Diff to implementation php-mo.php by Joss Crowcroft
diff2php.mo (text/plain), 4.96 KB, created by
Filip Komar
on 2013-07-22 13:59:55 CEST
(
hide
)
Description:
Diff to implementation php-mo.php by Joss Crowcroft
Filename:
MIME Type:
Creator:
Filip Komar
Created:
2013-07-22 13:59:55 CEST
Size:
4.96 KB
patch
obsolete
>3c3,6 >< * php.mo 0.1 by Joss Crowcroft (http://www.josscrowcroft.com) >--- >> * based on php.mo 0.1 by Joss Crowcroft (http://www.josscrowcroft.com) >> * added case for commented unused string >> * fixed "fuzzy flag first line" bug which didn't saved previous proper string at all >> * removed unedeed phpmo_convert and phpmo_write_mo_file >25,40d27 >< /** >< * The main .po to .mo function >< */ >< function phpmo_convert($input, $output = false) { >< if ( !$output ) >< $output = str_replace( '.po', '.mo', $input ); >< >< $hash = phpmo_parse_po_file( $input ); >< if ( $hash === false ) { >< return false; >< } else { >< phpmo_write_mo_file( $hash, $output ); >< return true; >< } >< } >< >59c46 >< $fh = fopen($in, 'r'); >--- >> $fh = @fopen($in, 'r'); >76c63,72 >< if ($line === '') >--- >> if ($line === '') { >> // save stored entry on empty line >> // block moved to fix "fuzzy flag first line" bug which didn't saved previous proper string at all >> if (sizeof($temp) && array_key_exists('msgid', $temp) && array_key_exists('msgstr', $temp)) { >> if (!$fuzzy) >> $hash[] = $temp; >> $temp = array (); >> $state = null; >> $fuzzy = false; >> } >78,79c74,77 >< >< list ($key, $data) = preg_split('/\s/', $line, 2); >--- >> } >> $array_of_splited_string = preg_split('/\s/', $line, 2); >> $key = $array_of_splited_string[0]; >> $data = (isset($array_of_splited_string[1]) ? $array_of_splited_string[1] : ''); >88,95c86,90 >< // start a new entry >< if (sizeof($temp) && array_key_exists('msgid', $temp) && array_key_exists('msgstr', $temp)) { >< if (!$fuzzy) >< $hash[] = $temp; >< $temp = array (); >< $state = null; >< $fuzzy = false; >< } >--- >> break; >> case '#~' : // commented-unused-string >> $temp = array (); >> $state = null; >> $fuzzy = false; >159,224d153 >< /* Write a GNU gettext style machine object. */ >< /* @link http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files */ >< function phpmo_write_mo_file($hash, $out) { >< // sort by msgid >< ksort($hash, SORT_STRING); >< // our mo file data >< $mo = ''; >< // header data >< $offsets = array (); >< $ids = ''; >< $strings = ''; >< >< foreach ($hash as $entry) { >< $id = $entry['msgid']; >< if (isset ($entry['msgid_plural'])) >< $id .= "\x00" . $entry['msgid_plural']; >< // context is merged into id, separated by EOT (\x04) >< if (array_key_exists('msgctxt', $entry)) >< $id = $entry['msgctxt'] . "\x04" . $id; >< // plural msgstrs are NUL-separated >< $str = implode("\x00", $entry['msgstr']); >< // keep track of offsets >< $offsets[] = array ( >< strlen($ids >< ), strlen($id), strlen($strings), strlen($str)); >< // plural msgids are not stored (?) >< $ids .= $id . "\x00"; >< $strings .= $str . "\x00"; >< } >< >< // keys start after the header (7 words) + index tables ($#hash * 4 words) >< $key_start = 7 * 4 + sizeof($hash) * 4 * 4; >< // values start right after the keys >< $value_start = $key_start +strlen($ids); >< // first all key offsets, then all value offsets >< $key_offsets = array (); >< $value_offsets = array (); >< // calculate >< foreach ($offsets as $v) { >< list ($o1, $l1, $o2, $l2) = $v; >< $key_offsets[] = $l1; >< $key_offsets[] = $o1 + $key_start; >< $value_offsets[] = $l2; >< $value_offsets[] = $o2 + $value_start; >< } >< $offsets = array_merge($key_offsets, $value_offsets); >< >< // write header >< $mo .= pack('Iiiiiii', 0x950412de, // magic number >< 0, // version >< sizeof($hash), // number of entries in the catalog >< 7 * 4, // key index offset >< 7 * 4 + sizeof($hash) * 8, // value index offset, >< 0, // hashtable size (unused, thus 0) >< $key_start // hashtable offset >< ); >< // offsets >< foreach ($offsets as $offset) >< $mo .= pack('i', $offset); >< // ids >< $mo .= $ids; >< // strings >< $mo .= $strings; >< >< file_put_contents($out, $mo); >< }
3c3,6 < * php.mo 0.1 by Joss Crowcroft (http://www.josscrowcroft.com) --- > * based on php.mo 0.1 by Joss Crowcroft (http://www.josscrowcroft.com) > * added case for commented unused string > * fixed "fuzzy flag first line" bug which didn't saved previous proper string at all > * removed unedeed phpmo_convert and phpmo_write_mo_file 25,40d27 < /** < * The main .po to .mo function < */ < function phpmo_convert($input, $output = false) { < if ( !$output ) < $output = str_replace( '.po', '.mo', $input ); < < $hash = phpmo_parse_po_file( $input ); < if ( $hash === false ) { < return false; < } else { < phpmo_write_mo_file( $hash, $output ); < return true; < } < } < 59c46 < $fh = fopen($in, 'r'); --- > $fh = @fopen($in, 'r'); 76c63,72 < if ($line === '') --- > if ($line === '') { > // save stored entry on empty line > // block moved to fix "fuzzy flag first line" bug which didn't saved previous proper string at all > if (sizeof($temp) && array_key_exists('msgid', $temp) && array_key_exists('msgstr', $temp)) { > if (!$fuzzy) > $hash[] = $temp; > $temp = array (); > $state = null; > $fuzzy = false; > } 78,79c74,77 < < list ($key, $data) = preg_split('/\s/', $line, 2); --- > } > $array_of_splited_string = preg_split('/\s/', $line, 2); > $key = $array_of_splited_string[0]; > $data = (isset($array_of_splited_string[1]) ? $array_of_splited_string[1] : ''); 88,95c86,90 < // start a new entry < if (sizeof($temp) && array_key_exists('msgid', $temp) && array_key_exists('msgstr', $temp)) { < if (!$fuzzy) < $hash[] = $temp; < $temp = array (); < $state = null; < $fuzzy = false; < } --- > break; > case '#~' : // commented-unused-string > $temp = array (); > $state = null; > $fuzzy = false; 159,224d153 < /* Write a GNU gettext style machine object. */ < /* @link http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files */ < function phpmo_write_mo_file($hash, $out) { < // sort by msgid < ksort($hash, SORT_STRING); < // our mo file data < $mo = ''; < // header data < $offsets = array (); < $ids = ''; < $strings = ''; < < foreach ($hash as $entry) { < $id = $entry['msgid']; < if (isset ($entry['msgid_plural'])) < $id .= "\x00" . $entry['msgid_plural']; < // context is merged into id, separated by EOT (\x04) < if (array_key_exists('msgctxt', $entry)) < $id = $entry['msgctxt'] . "\x04" . $id; < // plural msgstrs are NUL-separated < $str = implode("\x00", $entry['msgstr']); < // keep track of offsets < $offsets[] = array ( < strlen($ids < ), strlen($id), strlen($strings), strlen($str)); < // plural msgids are not stored (?) < $ids .= $id . "\x00"; < $strings .= $str . "\x00"; < } < < // keys start after the header (7 words) + index tables ($#hash * 4 words) < $key_start = 7 * 4 + sizeof($hash) * 4 * 4; < // values start right after the keys < $value_start = $key_start +strlen($ids); < // first all key offsets, then all value offsets < $key_offsets = array (); < $value_offsets = array (); < // calculate < foreach ($offsets as $v) { < list ($o1, $l1, $o2, $l2) = $v; < $key_offsets[] = $l1; < $key_offsets[] = $o1 + $key_start; < $value_offsets[] = $l2; < $value_offsets[] = $o2 + $value_start; < } < $offsets = array_merge($key_offsets, $value_offsets); < < // write header < $mo .= pack('Iiiiiii', 0x950412de, // magic number < 0, // version < sizeof($hash), // number of entries in the catalog < 7 * 4, // key index offset < 7 * 4 + sizeof($hash) * 8, // value index offset, < 0, // hashtable size (unused, thus 0) < $key_start // hashtable offset < ); < // offsets < foreach ($offsets as $offset) < $mo .= pack('i', $offset); < // ids < $mo .= $ids; < // strings < $mo .= $strings; < < file_put_contents($out, $mo); < }
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 10424
: 4216