Commit d7783a3e by Alexander Makarov

Merge pull request #1979 from SergeiKutanov/po_generation

po filles generation.
parents 96f210f0 a937e970
......@@ -173,9 +173,8 @@ class MessageController extends Controller
if (is_file($fileName)) {
if($format === 'po'){
$translated = file_get_contents($fileName);
preg_match_all('/(?<=msgid ").*(?="\nmsgstr)/', $translated, $keys);
preg_match_all('/(?<=msgid ").*(?="\n(#*)msgstr)/', $translated, $keys);
preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values);
$translated = array_combine($keys[0], $values[0]);
} else {
$translated = require($fileName);
......@@ -189,6 +188,9 @@ class MessageController extends Controller
$merged = [];
$untranslated = [];
foreach ($messages as $message) {
if($format === 'po'){
$message = preg_replace('/\"/', '\"', $message);
}
if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) {
$merged[$message] = $translated[$message];
} else {
......@@ -221,8 +223,15 @@ class MessageController extends Controller
if($format === 'po'){
$out_str = '';
foreach($merged as $k=>$v){
$k = preg_replace('/(\")|(\\\")/', "\\\"", $k);
$v = preg_replace('/(\")|(\\\")/', "\\\"", $v);
if(substr($v, 0, 2) === '@@' && substr($v, -2) === '@@'){
$out_str .= "#msgid \"$k\"\n";
$out_str .= "#msgstr \"$v\"\n";
}else{
$out_str .= "msgid \"$k\"\n";
$out_str .= "msgstr \"$v\"\n";
}
$out_str .= "\n";
}
$merged = $out_str;
......@@ -233,6 +242,7 @@ class MessageController extends Controller
$merged = '';
sort($messages);
foreach($messages as $message) {
$message = preg_replace('/(\")|(\\\")/', '\\\"', $message);
$merged .= "msgid \"$message\"\n";
$merged .= "msgstr \"\"\n";
$merged .= "\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment