aboutsummaryrefslogtreecommitdiffstats
path: root/php-mo.php
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2016-07-26 22:54:46 +0200
committerfilip <filip.komar@gmail.com>2016-07-26 22:54:46 +0200
commit33cf39f3a2b103b6768147ec99b20f4822dc92a6 (patch)
treee1fa01338721ca6878c10aadb28e914238e6d9ef /php-mo.php
parent387d067e53211d538f545ff002227a989c263fa2 (diff)
downloadnav-33cf39f3a2b103b6768147ec99b20f4822dc92a6.tar
nav-33cf39f3a2b103b6768147ec99b20f4822dc92a6.tar.gz
nav-33cf39f3a2b103b6768147ec99b20f4822dc92a6.tar.bz2
nav-33cf39f3a2b103b6768147ec99b20f4822dc92a6.tar.xz
nav-33cf39f3a2b103b6768147ec99b20f4822dc92a6.zip
changed structure of resulting l10n array
Diffstat (limited to 'php-mo.php')
-rw-r--r--php-mo.php78
1 files changed, 36 insertions, 42 deletions
diff --git a/php-mo.php b/php-mo.php
index eedc34d..6c1b901 100644
--- a/php-mo.php
+++ b/php-mo.php
@@ -12,44 +12,47 @@
* removed unedeed phpmo_convert and phpmo_write_mo_file
* more info on https://bugs.mageia.org/show_bug.cgi?id=14899
* added option for passing translation directly as an array
+* changed structure of resulting array
*
* it returns array of translations:
* $dictionary = phpmo_parse_po_file('input.po');
*
* $dictionary = array (
* '' => array (
-* 'msgid' => '',
-* 'msgstr' => array (
-* 0 => 'Project-Id-Version: ...',
+* 0 => array (
+* 0 => 'Project-Id-Version: ...',
* ),
* ),
-* 'string for translation 1' => array (
-* 'msgid' => 'string for translation 1',
-* 'msgstr' => array (
-* 0 => 'translated string 1',
+* 'msgid string for translation 1' => array ( // msgid
+* 0 => array (
+* 0 => 'translated string 1', // msgstr
* ),
* ),
-* 'string for translation 2' => array (
-* 'msgid' => 'string for translation 2',
-* 'msgstr' => array (
-* 0 => 'translated string 2',
-* 1 => 'translated string 2 but different context',
-* 2 => 'another translated string 2 with different context',
+* 'msgid string for translation 2' => array ( // msgid
+* 0 => array (
+* 0 => 'translated string 2', // msgstr
* ),
-* 'msgctxt' => array (
-* 1 => 'context explanation for msgstr[1]',
-* 2 => 'context explanation for msgstr[2]',
+* 'context explanation for msgstr[1]' => array ( // msgctxt
+* 0 => 'translated string 2 but different context', // msgstr
+* ),
+* 'context explanation for msgstr[2]' => array ( // msgctxt
+* 0 => 'another translated string 2 with different context', // msgstr
+* ),
+* ),
+* 'msgid string for translation 3' => array ( // msgid
+* 0 => array (
+* 'msgid_plural' => 'plural string for translation 3', // msgid_plural
+* 0 => 'translated string 3 for nplurals 0', // msgstr[0]
+* 1 => 'translated string 3 for nplurals 1', // msgstr[1]
+* 2 => 'translated string 3 for nplurals 2', // msgstr[2]
* ),
* ),
-* 'string for translation 3' => array (
-* 'msgid' => 'string for translation 3',
-* 'msgid_plural' => 'plural string for translation 3',
-* 'msgstr' => array (
-* 0 => array (
-* 0 => 'translated string 3 for nplurals 0',
-* 1 => 'translated string 3 for nplurals 1',
-* 2 => 'translated string 3 for nplurals 2',
-* ),
+* 'msgid string for translation 4' => array ( // msgid
+* 'context explanation for msgstr[0]' => array ( // msgctxt
+* 'msgid_plural' => 'plural string for translation 4', // msgid_plural
+* 0 => 'translated string 4 for nplurals 0', // msgstr[0]
+* 1 => 'translated string 4 for nplurals 1', // msgstr[1]
+* 2 => 'translated string 4 for nplurals 2', // msgstr[2]
* ),
* ),
* );
@@ -213,6 +216,7 @@ function phpmo_parse_po_file($in, $translation_in_file = true) {
if ($state == 'msgstr')
if (!$fuzzy)
$hash[] = $temp;
+
// Cleanup data, merge multiline entries, reindex hash for ksort
$temp = $hash;
$hash = array ();
@@ -224,24 +228,14 @@ function phpmo_parse_po_file($in, $translation_in_file = true) {
return FALSE;
}
}
- // if there's already same msgid we need to store it there
- if (array_key_exists($entry['msgid'], $hash)) {
- $index = count($hash[$entry['msgid']]['msgstr']);
- $hash[$entry['msgid']]['msgstr'][$index] = $entry['msgstr'][0];
- // is different msgctxt present also?
- if (array_key_exists('msgctxt', $entry)) {
- $hash[$entry['msgid']]['msgctxt'][$index] = $entry['msgctxt'][0];
- }
- } else {
- // if msgid_plural exists we need to store msgstr to subarray for proper counting of l10n completion
- if (array_key_exists('msgid_plural', $entry)) {
- $msgstr_plural = $entry['msgstr'];
- $entry['msgstr'] = array();
- $entry['msgstr'][] = $msgstr_plural;
- }
- $hash[$entry['msgid']] = $entry;
+
+ // add msgctxt if present
+ $msgctxt = (array_key_exists('msgctxt', $entry) ? $entry['msgctxt'][0] : 0);
+ // and also msgid_plural
+ if (array_key_exists('msgid_plural', $entry)) {
+ $entry['msgstr']['msgid_plural'] = $entry['msgid_plural'];
}
+ $hash[$entry['msgid']][$msgctxt] = $entry['msgstr'];
}
-
return $hash;
}