aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2018-07-29 18:00:56 -0700
committerzotlabs <mike@macgirvin.com>2018-07-29 18:00:56 -0700
commit32614e4074758d6112993d71169664a3c29e90b2 (patch)
tree6de47408110062e1c6a3f18dfaf0dc183c459c9a /util
parent9dc5a3bfc9152f04b9e39d61e90310d660029108 (diff)
parente4a1286aae411023210628d3be306420f7844d22 (diff)
downloadvolse-hubzilla-32614e4074758d6112993d71169664a3c29e90b2.tar.gz
volse-hubzilla-32614e4074758d6112993d71169664a3c29e90b2.tar.bz2
volse-hubzilla-32614e4074758d6112993d71169664a3c29e90b2.zip
Merge branch 'dev' of https://framagit.org/hubzilla/core into xdev_merge
Diffstat (limited to 'util')
-rw-r--r--util/php2po.php127
1 files changed, 68 insertions, 59 deletions
diff --git a/util/php2po.php b/util/php2po.php
index c165006a1..99578a12d 100644
--- a/util/php2po.php
+++ b/util/php2po.php
@@ -7,65 +7,74 @@
}
}
- if ($argc!=2) {
- print "Usage: ".$argv[0]." <hstrings.php>\n\n";
- return;
- }
-
- $phpfile = $argv[1];
- $pofile = dirname($phpfile)."/hmessages.po";
+ if ($argc!=2) {
+ print "Usage: ".$argv[0]." <hstrings.php>\n\n";
+ return;
+ }
+
+ $phpfile = $argv[1];
+ $pofile = dirname($phpfile)."/hmessages.po";
+
+ if (!file_exists($phpfile)){
+ print "Unable to find '$phpfile'\n";
+ return;
+ }
+
+ include_once($phpfile);
+
+ print "Out to '$pofile'\n";
- if (!file_exists($phpfile)){
- print "Unable to find '$phpfile'\n";
- return;
- }
+ $out = "";
+ $infile = file($pofile);
+ $k="";
+ $ink = False;
+ foreach ($infile as $l) {
- include_once($phpfile);
+ if (!preg_match("/^msgstr\[[1-9]/",$l)) {
+ if ($k!="" && (substr($l,0,7)=="msgstr " || substr($l,0,8)=="msgstr[0")){
+ $ink = False;
+ $k = str_replace('\"','"',$k);
+ $v = "";
+ if (isset(App::$strings[$k])) {
+ $v = App::$strings[$k];
+ } else {
+ $k = "__ctx:".$c."__ ".$k;
+ if (isset(App::$strings[$k]))
+ $v = App::$strings[$k];
+ }
+ if (!empty($v)) {
+ if (is_array($v)) {
+ $l = "";
+ $n = 0;
+ foreach ($v as &$value) {
+ $l .= "msgstr[".$n."] \"".str_replace('"','\"',$value)."\"\n";
+ $n++;
+ }
+ } else {
+ $l = "msgstr \"".str_replace('"','\"',$v)."\"\n";
+ }
+ }
+ }
- print "Out to '$pofile'\n";
-
- $out = "";
- $infile = file($pofile);
- $k="";
- $ink = False;
- foreach ($infile as $l) {
-
- if ($k!="" && substr($l,0,7)=="msgstr "){
- $ink = False;
- $v = '';
- //echo "DBG: k:'$k'\n";
- if (isset(App::$strings[$k])) {
- $v= App::$strings[$k];
- //echo "DBG\n";
- //var_dump($k, $v, App::$strings[$k], $v);
- //echo "/DBG\n";
-
- }
- //echo "DBG: v:'$v'\n";
- $l = "msgstr \"".str_replace('"','\"',$v)."\"\n";
- }
-
- if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[" )$ink = False;;
-
- if ($ink) {
- $k .= trim($l,"\"\r\n");
- $k = str_replace('\"','"',$k);
- }
-
- if (substr($l,0,6)=="msgid "){
- $arr=False;
- $k = str_replace("msgid ","",$l);
- if ($k != '""' ) {
- $k = trim($k,"\"\r\n");
- $k = str_replace('\"','"',$k);
- } else {
- $k = "";
- }
- $ink = True;
- }
-
- $out .= $l;
- }
- //echo $out;
- file_put_contents($pofile, $out);
-?> \ No newline at end of file
+ if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[") $ink = False;
+
+ if ($ink) {
+ $k .= trim($l,"\"\r\n");
+ }
+
+ if (substr($l,0,6)=="msgid ") {
+ preg_match('/^msgid "(.*)"/',$l,$m);
+ $k = $m[1];
+ $ink = True;
+ }
+
+ if (substr($l,0,8)=="msgctxt ") {
+ preg_match('/^msgctxt "(.*)"/',$l,$m);
+ $c = $m[1];
+ }
+
+ $out .= $l;
+ }
+ }
+ file_put_contents($pofile, $out);
+?>