|
|
|
@ -57,50 +57,58 @@ class MessageController extends Controller
|
|
|
|
|
*/ |
|
|
|
|
public function actionIndex($config) |
|
|
|
|
{ |
|
|
|
|
if(!is_file($config)) |
|
|
|
|
if (!is_file($config)) { |
|
|
|
|
$this->usageError("the configuration file {$config} does not exist."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$config = require_once($config); |
|
|
|
|
|
|
|
|
|
$translator='Yii::t'; |
|
|
|
|
extract($config); |
|
|
|
|
|
|
|
|
|
if(!isset($sourcePath,$messagePath,$languages)) |
|
|
|
|
if (!isset($sourcePath, $messagePath, $languages)) { |
|
|
|
|
$this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".'); |
|
|
|
|
if(!is_dir($sourcePath)) |
|
|
|
|
} |
|
|
|
|
if (!is_dir($sourcePath)) { |
|
|
|
|
$this->usageError("The source path $sourcePath is not a valid directory."); |
|
|
|
|
if(!is_dir($messagePath)) |
|
|
|
|
} |
|
|
|
|
if (!is_dir($messagePath)) { |
|
|
|
|
$this->usageError("The message path $messagePath is not a valid directory."); |
|
|
|
|
if(empty($languages)) |
|
|
|
|
} |
|
|
|
|
if (empty($languages)) { |
|
|
|
|
$this->usageError("Languages cannot be empty."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!isset($overwrite)) |
|
|
|
|
if (!isset($overwrite)) { |
|
|
|
|
$overwrite = false; |
|
|
|
|
|
|
|
|
|
if(!isset($removeOld)) |
|
|
|
|
} |
|
|
|
|
if (!isset($removeOld)) { |
|
|
|
|
$removeOld = false; |
|
|
|
|
|
|
|
|
|
if(!isset($sort)) |
|
|
|
|
} |
|
|
|
|
if (!isset($sort)) { |
|
|
|
|
$sort = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$options = array(); |
|
|
|
|
if(isset($fileTypes)) |
|
|
|
|
if (isset($fileTypes)) { |
|
|
|
|
$options['fileTypes'] = $fileTypes; |
|
|
|
|
if(isset($exclude)) |
|
|
|
|
} |
|
|
|
|
if (isset($exclude)) { |
|
|
|
|
$options['exclude'] = $exclude; |
|
|
|
|
} |
|
|
|
|
$files = CFileHelper::findFiles(realpath($sourcePath), $options); |
|
|
|
|
|
|
|
|
|
$messages = array(); |
|
|
|
|
foreach($files as $file) |
|
|
|
|
foreach ($files as $file) { |
|
|
|
|
$messages = array_merge_recursive($messages, $this->extractMessages($file, $translator)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach($languages as $language) |
|
|
|
|
{ |
|
|
|
|
foreach ($languages as $language) { |
|
|
|
|
$dir = $messagePath . DIRECTORY_SEPARATOR . $language; |
|
|
|
|
if(!is_dir($dir)) |
|
|
|
|
if (!is_dir($dir)) { |
|
|
|
|
@mkdir($dir); |
|
|
|
|
foreach($messages as $category=>$msgs) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
foreach ($messages as $category => $msgs) { |
|
|
|
|
$msgs = array_values(array_unique($msgs)); |
|
|
|
|
$this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld, $sort); |
|
|
|
|
} |
|
|
|
@ -111,14 +119,16 @@ class MessageController extends Controller
|
|
|
|
|
{ |
|
|
|
|
echo "Extracting messages from $fileName...\n"; |
|
|
|
|
$subject = file_get_contents($fileName); |
|
|
|
|
$n=preg_match_all('/\b'.$translator.'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',$subject,$matches,PREG_SET_ORDER); |
|
|
|
|
$n = preg_match_all( |
|
|
|
|
'/\b' . $translator . '\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) |
|
|
|
|
for ($i = 0; $i < $n; ++$i) { |
|
|
|
|
if (($pos = strpos($matches[$i][1], '.')) !== false) { |
|
|
|
|
$category=substr($matches[$i][1], $pos + 1, -1); |
|
|
|
|
else |
|
|
|
|
} else { |
|
|
|
|
$category=substr($matches[$i][1], 1, -1); |
|
|
|
|
} |
|
|
|
|
$message = $matches[$i][2]; |
|
|
|
|
$messages[$category][] = eval("return $message;"); // use eval to eliminate quote escape |
|
|
|
|
} |
|
|
|
@ -128,53 +138,53 @@ class MessageController extends Controller
|
|
|
|
|
protected function generateMessageFile($messages,$fileName,$overwrite,$removeOld,$sort) |
|
|
|
|
{ |
|
|
|
|
echo "Saving messages to $fileName..."; |
|
|
|
|
if(is_file($fileName)) |
|
|
|
|
{ |
|
|
|
|
if (is_file($fileName)) { |
|
|
|
|
$translated = require($fileName); |
|
|
|
|
sort($messages); |
|
|
|
|
ksort($translated); |
|
|
|
|
if(array_keys($translated)==$messages) |
|
|
|
|
{ |
|
|
|
|
if (array_keys($translated) == $messages) { |
|
|
|
|
echo "nothing new...skipped.\n"; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
$merged = array(); |
|
|
|
|
$untranslated = array(); |
|
|
|
|
foreach($messages as $message) |
|
|
|
|
{ |
|
|
|
|
if(!empty($translated[$message])) |
|
|
|
|
foreach ($messages as $message) { |
|
|
|
|
if (!empty($translated[$message])) { |
|
|
|
|
$merged[$message] = $translated[$message]; |
|
|
|
|
else |
|
|
|
|
} else { |
|
|
|
|
$untranslated[] = $message; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ksort($merged); |
|
|
|
|
sort($untranslated); |
|
|
|
|
$todo = array(); |
|
|
|
|
foreach($untranslated as $message) |
|
|
|
|
foreach ($untranslated as $message) { |
|
|
|
|
$todo[$message] = ''; |
|
|
|
|
} |
|
|
|
|
ksort($translated); |
|
|
|
|
foreach($translated as $message=>$translation) |
|
|
|
|
{ |
|
|
|
|
foreach ($translated as $message => $translation) { |
|
|
|
|
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld) |
|
|
|
|
{ |
|
|
|
|
if(substr($translation,0,2)==='@@' && substr($translation,-2)==='@@') |
|
|
|
|
if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { |
|
|
|
|
$todo[$message]=$translation; |
|
|
|
|
else |
|
|
|
|
} else { |
|
|
|
|
$todo[$message] = '@@' . $translation . '@@'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$merged = array_merge($todo, $merged); |
|
|
|
|
if($sort) |
|
|
|
|
if ($sort) { |
|
|
|
|
ksort($merged); |
|
|
|
|
if($overwrite === false) |
|
|
|
|
} |
|
|
|
|
if (false === $overwrite) { |
|
|
|
|
$fileName .= '.merged'; |
|
|
|
|
echo "translation merged.\n"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
echo "translation merged.\n"; |
|
|
|
|
} else { |
|
|
|
|
$merged = array(); |
|
|
|
|
foreach($messages as $message) |
|
|
|
|
foreach ($messages as $message) { |
|
|
|
|
$merged[$message] = ''; |
|
|
|
|
} |
|
|
|
|
ksort($merged); |
|
|
|
|
echo "saved.\n"; |
|
|
|
|
} |
|
|
|
|