From ed15b85ed167a5461f96b84e92ce0e2abf866879 Mon Sep 17 00:00:00 2001 From: Filip Komar Date: Sun, 20 Apr 2014 16:53:30 +0000 Subject: fix for conversion of mognase to gettext --- langs/en.pot | 99 +++++++++++++++++++++++++++++++++++ langs/php-mo.php | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib.php | 1 + 3 files changed, 254 insertions(+) create mode 100644 langs/en.pot create mode 100644 langs/php-mo.php diff --git a/langs/en.pot b/langs/en.pot new file mode 100644 index 0000000..3069756 --- /dev/null +++ b/langs/en.pot @@ -0,0 +1,99 @@ +# gettext catalog for mognase web page(s) +# Copyright (C) 2014 - 2014 Mageia +# This file is distributed under the same license as +# the content of the corresponding web page(s). +# +# Generated by extract2gettext.php +# Domain: mognase +# +# include translation strings from: +# _nav/lib.php +# +msgid "" +msgstr "" +"Project-Id-Version: mognase\n" +"Report-Msgid-Bugs-To: mageia-i18n@mageia.org\n" +"POT-Creation-Date: 2014-03-31 16:22:46+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: "/web/_nav/lib.php +232" +msgid "Go to mageia.org site map." +msgstr "" + +#: "/web/_nav/lib.php +233" +msgid "About us" +msgstr "" + +#: "/web/_nav/lib.php +233" +msgid "Learn more about Mageia." +msgstr "" + +#: "/web/_nav/lib.php +234" +msgid "Downloads" +msgstr "" + +#: "/web/_nav/lib.php +234" +msgid "Download Mageia ISO and updates." +msgstr "" + +#: "/web/_nav/lib.php +235" +msgid "Support" +msgstr "" + +#: "/web/_nav/lib.php +235" +msgid "Get support from Mageia community." +msgstr "" + +#: "/web/_nav/lib.php +236" +msgid "Wiki" +msgstr "" + +#: "/web/_nav/lib.php +236" +msgid "Wiki of the Mageia Community" +msgstr "" + +#: "/web/_nav/lib.php +237" +msgid "Docs" +msgstr "" + +#: "/web/_nav/lib.php +237" +msgid "Documentations of Mageia" +msgstr "" + +#: "/web/_nav/lib.php +238" +msgid "Community" +msgstr "" + +#: "/web/_nav/lib.php +239" +msgid "Contribute" +msgstr "" + +#: "/web/_nav/lib.php +239" +msgid "You too can build Mageia with us!" +msgstr "" + +#: "/web/_nav/lib.php +240" +msgid "Donate" +msgstr "" + +#: "/web/_nav/lib.php +241" +msgid "You" +msgstr "" + +#: "/web/_nav/lib.php +241" +msgid "Your Mageia online account." +msgstr "" + +#: "/web/_nav/lib.php +242" +msgid "Contact" +msgstr "" + +#: "/web/_nav/lib.php +242" +msgid "Contact Us" +msgstr "" diff --git a/langs/php-mo.php b/langs/php-mo.php new file mode 100644 index 0000000..470ce80 --- /dev/null +++ b/langs/php-mo.php @@ -0,0 +1,154 @@ + + * + * NB: + * - If no $output_file specified, output filename is same as $input_file (but .mo) + * - Returns true/false for success/failure + * - No warranty, but if it breaks, please let me know + * + * More info: + * https://github.com/josscrowcroft/php.mo + * + * Based on php-msgfmt by Matthias Bauer (Copyright © 2007), a command-line PHP tool + * for converting .po files to .mo. + * (http://wordpress-soc-2007.googlecode.com/svn/trunk/moeffju/php-msgfmt/msgfmt.php) + * + * License: GPL v3 http://www.opensource.org/licenses/gpl-3.0.html + */ + +function phpmo_clean_helper($x) { + if (is_array($x)) { + foreach ($x as $k => $v) { + $x[$k] = phpmo_clean_helper($v); + } + } else { + if ($x[0] == '"') + $x = substr($x, 1, -1); + $x = str_replace("\"\n\"", '', $x); + $x = str_replace('$', '\\$', $x); + } + return $x; +} + +/* Parse gettext .po files. */ +/* @link http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files */ +function phpmo_parse_po_file($in) { + // read .po file + $fh = @fopen($in, 'r'); + if ($fh === false) { + // Could not open file resource + return false; + } + + // results array + $hash = array (); + // temporary array + $temp = array (); + // state + $state = null; + $fuzzy = false; + + // iterate over lines + while(($line = fgets($fh, 65536)) !== false) { + $line = trim($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; + } + continue; + } + $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] : ''); + + switch ($key) { + case '#,' : // flag... + $fuzzy = in_array('fuzzy', preg_split('/,\s*/', $data)); + case '#' : // translator-comments + case '#.' : // extracted-comments + case '#:' : // reference... + case '#|' : // msgid previous-untranslated-string + break; + case '#~' : // commented-unused-string + $temp = array (); + $state = null; + $fuzzy = false; + break; + case 'msgctxt' : + // context + case 'msgid' : + // untranslated-string + case 'msgid_plural' : + // untranslated-string-plural + $state = $key; + $temp[$state] = $data; + break; + case 'msgstr' : + // translated-string + $state = 'msgstr'; + $temp[$state][] = $data; + break; + default : + if (strpos($key, 'msgstr[') !== FALSE) { + // translated-string-case-n + $state = 'msgstr'; + $temp[$state][] = $data; + } else { + // continued lines + switch ($state) { + case 'msgctxt' : + case 'msgid' : + case 'msgid_plural' : + $temp[$state] .= "\n" . $line; + break; + case 'msgstr' : + $temp[$state][sizeof($temp[$state]) - 1] .= "\n" . $line; + break; + default : + // parse error + fclose($fh); + return FALSE; + } + } + break; + } + } + fclose($fh); + + // add final entry + if ($state == 'msgstr') + $hash[] = $temp; + + // Cleanup data, merge multiline entries, reindex hash for ksort + $temp = $hash; + $hash = array (); + foreach ($temp as $entry) { + foreach ($entry as & $v) { + $v = phpmo_clean_helper($v); + if ($v === FALSE) { + // parse error + return FALSE; + } + } + $hash[$entry['msgid']] = $entry; + } + + return $hash; +} + +?> \ No newline at end of file diff --git a/lib.php b/lib.php index f18d468..d300b03 100644 --- a/lib.php +++ b/lib.php @@ -154,6 +154,7 @@ class l10n } if (file_exists($po_file)) { + require_once('langs/php-mo.php'); $dictionary = phpmo_parse_po_file($po_file); foreach ($dictionary as $key => $value) { -- cgit v1.2.1