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