streams/util/php2po.php

81 lines
2.9 KiB
PHP
Raw Normal View History

2011-03-18 10:03:15 +00:00
<?php
2018-07-19 22:22:04 +00:00
if(! class_exists('App')) {
class App {
static public $rtl;
static public $strings = Array();
2018-07-19 22:22:04 +00:00
}
}
2011-03-18 10:03:15 +00:00
2018-07-28 15:36:48 +00:00
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);
2011-03-18 10:03:15 +00:00
2018-07-28 15:36:48 +00:00
print "Out to '$pofile'\n";
2011-03-18 10:03:15 +00:00
2018-07-28 15:36:48 +00:00
$out = "";
$infile = file($pofile);
$k="";
$ink = False;
foreach ($infile as $l) {
2011-03-18 10:03:15 +00:00
2018-07-28 15:36:48 +00:00
if (!preg_match("/^msgstr\[[1-9]/",$l)) {
if ($k!="" && (substr($l,0,7)=="msgstr " || substr($l,0,8)=="msgstr[0")){
$ink = False;
2018-07-29 00:11:27 +00:00
$k = str_replace('\"','"',$k);
2018-07-28 15:36:48 +00:00
$v = "";
if (isset(App::$strings[$k])) {
$v = App::$strings[$k];
2018-07-29 00:11:27 +00:00
} else {
$k = "__ctx:".$c."__ ".$k;
if (isset(App::$strings[$k]))
$v = App::$strings[$k];
}
if (!empty($v)) {
2018-07-28 15:36:48 +00:00
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";
}
}
}
if (substr($l,0,6)=="msgid_" || substr($l,0,7)=="msgstr[") $ink = False;
if ($ink) {
$k .= trim($l,"\"\r\n");
}
2018-07-29 00:11:27 +00:00
if (substr($l,0,6)=="msgid ") {
preg_match('/^msgid "(.*)"/',$l,$m);
$k = $m[1];
2018-07-28 15:36:48 +00:00
$ink = True;
}
2018-07-29 00:11:27 +00:00
if (substr($l,0,8)=="msgctxt ") {
preg_match('/^msgctxt "(.*)"/',$l,$m);
$c = $m[1];
}
2018-07-28 15:36:48 +00:00
$out .= $l;
}
}
file_put_contents($pofile, $out);
?>