Commit 48b8089d by Digimon

code format fixed

parent c3976b0f
......@@ -77,16 +77,13 @@ class MessageController extends Controller
throw new Exception("The configuration file does not exist: $configFile");
}
$config = array_merge(
[
$config = array_merge([
'translator' => 'Yii::t',
'overwrite' => false,
'removeUnused' => false,
'sort' => false,
'format' => 'php',
],
require($configFile)
);
], require($configFile));
if (!isset($config['sourcePath'], $config['messagePath'], $config['languages'])) {
throw new Exception('The configuration file must specify "sourcePath", "messagePath" and "languages".');
......@@ -125,23 +122,11 @@ class MessageController extends Controller
mkdir($path, 0755, true);
}
$msgs = array_values(array_unique($msgs));
$this->generateMessageFile(
$msgs,
$file,
$config['overwrite'],
$config['removeUnused'],
$config['sort'],
$config['format']
);
$this->generateMessageFile($msgs, $file, $config['overwrite'], $config['removeUnused'], $config['sort'], $config['format']);
}
}
}
if ($config['format'] === 'db') {
$dbConnection = \Yii::$app->getComponent(isset($config['connectionID']) ? $config['connectionID'] : 'db');
if (!$dbConnection instanceof \yii\db\Connection) {
$this->usageError('The "connectionID" must refer to a valid database application component.');
}
$sourceMessageTable = !isset($config['sourceMessageTable']) ? 'SourceMessage' : $config['sourceMessageTable'];
foreach ($config['languages'] as $language) {
foreach ($messages as $category => $msgs) {
$messages[$category] = array_values(array_unique($msgs));
......@@ -162,9 +147,7 @@ class MessageController extends Controller
$q = new \yii\db\Query;
$current = [];
foreach ($q->select(['id', 'category', 'message'])
->from($sourceMessageTable)
->all() as $row) {
foreach ($q->select(['id', 'category', 'message'])->from($sourceMessageTable)->all() as $row) {
$current[$row['category']][$row['id']] = $row['message'];
}
......@@ -229,6 +212,7 @@ class MessageController extends Controller
}
}
/**
* Extracts messages from a file
*
......@@ -247,10 +231,7 @@ class MessageController extends Controller
foreach ($translator as $currentTranslator) {
$n = preg_match_all(
'/\b' . $currentTranslator . '\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',
$subject,
$matches,
PREG_SET_ORDER
);
$subject, $matches, PREG_SET_ORDER);
for ($i = 0; $i < $n; ++$i) {
if (($pos = strpos($matches[$i][1], '.')) !== false) {
$category = substr($matches[$i][1], $pos + 1, -1);
......@@ -278,7 +259,7 @@ class MessageController extends Controller
{
echo "Saving messages to $fileName...";
if (is_file($fileName)) {
if ($format === 'po') {
if($format === 'po'){
$translated = file_get_contents($fileName);
preg_match_all('/(?<=msgid ").*(?="\n(#*)msgstr)/', $translated, $keys);
preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values);
......@@ -295,7 +276,7 @@ class MessageController extends Controller
$merged = [];
$untranslated = [];
foreach ($messages as $message) {
if ($format === 'po') {
if($format === 'po'){
$message = preg_replace('/\"/', '\"', $message);
}
if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) {
......@@ -327,9 +308,9 @@ class MessageController extends Controller
if (false === $overwrite) {
$fileName .= '.merged';
}
if ($format === 'po') {
if ($format === 'po'){
$out_str = '';
foreach ($merged as $k => $v) {
foreach ($merged as $k => $v){
$k = preg_replace('/(\")|(\\\")/', "\\\"", $k);
$v = preg_replace('/(\")|(\\\")/', "\\\"", $v);
if (substr($v, 0, 2) === '@@' && substr($v, -2) === '@@') {
......@@ -348,7 +329,7 @@ class MessageController extends Controller
if ($format === 'po') {
$merged = '';
sort($messages);
foreach ($messages as $message) {
foreach($messages as $message) {
$message = preg_replace('/(\")|(\\\")/', '\\\"', $message);
$merged .= "msgid \"$message\"\n";
$merged .= "msgstr \"\"\n";
......@@ -393,4 +374,3 @@ EOD;
file_put_contents($fileName, $content);
}
}
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