|
|
|
@ -55,7 +55,8 @@ class MessageController extends Controller
|
|
|
|
|
* directory 'sourcePath/a/b'. |
|
|
|
|
* - translator: the name of the function for translating messages. |
|
|
|
|
* Defaults to 'Yii::t'. This is used as a mark to find messages to be |
|
|
|
|
* translated. |
|
|
|
|
* translated. Accepts both string for single function name or array for |
|
|
|
|
* multiple function names. |
|
|
|
|
* - overwrite: if message file must be overwritten with the merged messages. |
|
|
|
|
* - removeOld: if message no longer needs translation it will be removed, |
|
|
|
|
* instead of being enclosed between a pair of '@@' marks. |
|
|
|
@ -133,10 +134,14 @@ class MessageController extends Controller
|
|
|
|
|
{ |
|
|
|
|
echo "Extracting messages from $fileName...\n"; |
|
|
|
|
$subject = file_get_contents($fileName); |
|
|
|
|
$messages = array(); |
|
|
|
|
if (!is_array($translator)) { |
|
|
|
|
$translator = array($translator); |
|
|
|
|
} |
|
|
|
|
foreach ($translator as $currentTranslator) { |
|
|
|
|
$n = preg_match_all( |
|
|
|
|
'/\b' . $translator . '\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s', |
|
|
|
|
'/\b' . $currentTranslator . '\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s', |
|
|
|
|
$subject, $matches, PREG_SET_ORDER); |
|
|
|
|
$messages = array(); |
|
|
|
|
for ($i = 0; $i < $n; ++$i) { |
|
|
|
|
if (($pos = strpos($matches[$i][1], '.')) !== false) { |
|
|
|
|
$category = substr($matches[$i][1], $pos + 1, -1); |
|
|
|
@ -146,6 +151,7 @@ class MessageController extends Controller
|
|
|
|
|
$message = $matches[$i][2]; |
|
|
|
|
$messages[$category][] = eval("return $message;"); // use eval to eliminate quote escape |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $messages; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -172,7 +178,7 @@ class MessageController extends Controller
|
|
|
|
|
$merged = array(); |
|
|
|
|
$untranslated = array(); |
|
|
|
|
foreach ($messages as $message) { |
|
|
|
|
if (!empty($translated[$message])) { |
|
|
|
|
if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { |
|
|
|
|
$merged[$message] = $translated[$message]; |
|
|
|
|
} else { |
|
|
|
|
$untranslated[] = $message; |
|
|
|
|