Commit 92cfdb33 by SergeiKutanov

po now supports obsolete messages

parent 2ce5e652
...@@ -173,7 +173,7 @@ class MessageController extends Controller ...@@ -173,7 +173,7 @@ class MessageController extends Controller
if (is_file($fileName)) { if (is_file($fileName)) {
if($format === 'po'){ if($format === 'po'){
$translated = file_get_contents($fileName); $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); preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values);
$translated = array_combine($keys[0], $values[0]); $translated = array_combine($keys[0], $values[0]);
} else { } else {
...@@ -188,7 +188,7 @@ class MessageController extends Controller ...@@ -188,7 +188,7 @@ class MessageController extends Controller
$merged = []; $merged = [];
$untranslated = []; $untranslated = [];
foreach ($messages as $message) { foreach ($messages as $message) {
$message = preg_replace('/\\"/', '\"', $message); $message = preg_replace('/\"/', '\"', $message);
if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) {
$merged[$message] = $translated[$message]; $merged[$message] = $translated[$message];
} else { } else {
...@@ -202,7 +202,6 @@ class MessageController extends Controller ...@@ -202,7 +202,6 @@ class MessageController extends Controller
$todo[$message] = ''; $todo[$message] = '';
} }
ksort($translated); ksort($translated);
if($format === 'php'){
foreach ($translated as $message => $translation) { foreach ($translated as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
...@@ -212,7 +211,6 @@ class MessageController extends Controller ...@@ -212,7 +211,6 @@ class MessageController extends Controller
} }
} }
} }
}
$merged = array_merge($todo, $merged); $merged = array_merge($todo, $merged);
if ($sort) { if ($sort) {
ksort($merged); ksort($merged);
...@@ -225,8 +223,13 @@ class MessageController extends Controller ...@@ -225,8 +223,13 @@ class MessageController extends Controller
foreach($merged as $k=>$v){ foreach($merged as $k=>$v){
$k = preg_replace('/(\")|(\\\")/', "\\\"", $k); $k = preg_replace('/(\")|(\\\")/', "\\\"", $k);
$v = preg_replace('/(\")|(\\\")/', "\\\"", $v); $v = preg_replace('/(\")|(\\\")/', "\\\"", $v);
$out_str .= "msgid \"$k\"\n"; if(substr($v, 0, 2) === '@@' && substr($v, -2) === '@@'){
$out_str .= "msgstr \"$v\"\n"; $out_str .= "#msgid \"$k\"\n";
$out_str .= "#msgstr \"$v\"\n";
}else{
$out_str .= "msgid \"$k\"\n";
$out_str .= "msgstr \"$v\"\n";
}
$out_str .= "\n"; $out_str .= "\n";
} }
$merged = $out_str; $merged = $out_str;
......
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