Make translation contexts effective.

This commit is contained in:
Alexandre Hannud Abdo 2014-05-21 04:48:22 -03:00
parent c6de9096fa
commit 72a633dc51
3 changed files with 18 additions and 11 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ include/jquery-1.4.2.min.js
home.html home.html
addon addon
*~ *~
.*.swp
compiled/ compiled/
custom/ custom/
/store/ /store/

View File

@ -153,8 +153,9 @@ function load_translation_table($lang, $install = false) {
function t($s,$ctx = '') { function t($s,$ctx = '') {
global $a; global $a;
if(x($a->strings,$s)) { $cs = $ctx?"__ctx:".$ctx."__ ".$s:$s;
$t = $a->strings[$s]; if(x($a->strings,$cs)) {
$t = $a->strings[$cs];
return is_array($t) ? $t[0] : $t; return is_array($t) ? $t[0] : $t;
} }
return $s; return $s;

View File

@ -30,6 +30,7 @@ function po2php_run($argv, $argc) {
$infile = file($pofile); $infile = file($pofile);
$k=""; $k="";
$v=""; $v="";
$ctx="";
$arr = False; $arr = False;
$ink = False; $ink = False;
$inv = False; $inv = False;
@ -92,22 +93,26 @@ function po2php_run($argv, $argc) {
if ($k!="") $out .= $arr?");\n":";\n"; if ($k!="") $out .= $arr?");\n":";\n";
$arr=False; $arr=False;
$k = str_replace("msgid ","",$l); $k = str_replace("msgid ","",$l);
if ($k != '""' ) { $k = trim($k,"\"\r\n");
$k = trim($k,"\"\r\n"); $k = $ctx.$k;
} else { // echo $ctx ? $ctx."\nX\n":"";
$k = "";
}
$k = preg_replace_callback($escape_s_exp,'escape_s',$k); $k = preg_replace_callback($escape_s_exp,'escape_s',$k);
$ctx = "";
$ink = True; $ink = True;
} }
if ($inv && substr($l,0,6)!="msgstr") { if ($inv && substr($l,0,6)!="msgstr" && substr($l,0,7)!="msgctxt") {
$v .= trim($l,"\"\r\n"); $v .= trim($l,"\"\r\n");
$v = preg_replace_callback($escape_s_exp,'escape_s',$v); $v = preg_replace_callback($escape_s_exp,'escape_s',$v);
//$out .= '$a->strings['.$k.'] = '; //$out .= '$a->strings['.$k.'] = ';
} }
if (substr($l,0,7)=="msgctxt") {
$ctx = str_replace("msgctxt ","",$l);
$ctx = trim($ctx,"\"\r\n");
$ctx = "__ctx:".$ctx."__ ";
$ctx = preg_replace_callback($escape_s_exp,'escape_s',$ctx);
}
} }