Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
4fe0eeb1
Commit
4fe0eeb1
authored
Jan 21, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refacotring.
parent
92215a2f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
26 deletions
+21
-26
MessageController.php
framework/console/controllers/MessageController.php
+18
-24
messageConfig.php
framework/views/messageConfig.php
+3
-2
No files found.
framework/console/controllers/MessageController.php
View file @
4fe0eeb1
...
...
@@ -129,20 +129,14 @@ class MessageController extends Controller
}
}
}
elseif
(
$config
[
'format'
]
===
'db'
)
{
$dbConnection
=
\Yii
::
$app
->
getComponent
(
isset
(
$config
[
'connectionID'
])
?
$config
[
'connectionID'
]
:
'db'
);
if
(
!
$dbConnection
instanceof
\yii\db\Connection
)
{
throw
new
Exception
(
'The "connectionID" must refer to a valid database application component.'
);
}
$sourceMessageTable
=
isset
(
$config
[
'sourceMessageTable'
])
?
$config
[
'sourceMessageTable'
]
:
'SourceMessage'
;
$res
=
[];
foreach
(
$config
[
'languages'
]
as
$language
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
$res
[
$category
]
=
$msgs
;
}
$db
=
\Yii
::
$app
->
getComponent
(
isset
(
$config
[
'db'
])
?
$config
[
'db'
]
:
'db'
);
if
(
!
$db
instanceof
\yii\db\Connection
)
{
throw
new
Exception
(
'The "db" option must refer to a valid database application component.'
);
}
$sourceMessageTable
=
isset
(
$config
[
'sourceMessageTable'
])
?
$config
[
'sourceMessageTable'
]
:
'{{%source_message}}'
;
$this
->
saveMessagesToDb
(
$
r
es
,
$db
Connection
,
$
messag
es
,
$db
,
$sourceMessageTable
,
$config
[
'removeUnused'
]
);
...
...
@@ -153,11 +147,11 @@ class MessageController extends Controller
* Saves messages to database
*
* @param array $messages
* @param \yii\db\Connection $db
Connection
* @param \yii\db\Connection $db
* @param string $sourceMessageTable
* @param boolean $removeUnused
*/
protected
function
saveMessagesToDb
(
$messages
,
$db
Connection
,
$sourceMessageTable
,
$removeUnused
)
protected
function
saveMessagesToDb
(
$messages
,
$db
,
$sourceMessageTable
,
$removeUnused
)
{
$q
=
new
\yii\db\Query
;
$current
=
[];
...
...
@@ -200,7 +194,7 @@ class MessageController extends Controller
foreach
(
$msgs
as
$m
)
{
$savedFlag
=
true
;
$db
Connection
->
createCommand
()
$db
->
createCommand
()
->
insert
(
$sourceMessageTable
,
[
'category'
=>
$category
,
'message'
=>
$m
])
->
execute
();
}
}
...
...
@@ -212,11 +206,11 @@ class MessageController extends Controller
echo
"nothing obsoleted...skipped.
\n
"
;
}
else
{
if
(
$removeUnused
)
{
$db
Connection
->
createCommand
()
$db
->
createCommand
()
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
])
->
execute
();
echo
"deleted.
\n
"
;
}
else
{
$db
Connection
->
createCommand
()
$db
->
createCommand
()
->
update
(
$sourceMessageTable
,
[
'message'
=>
new
\yii\db\Expression
(
"CONCAT('@@',message,'@@')"
)],
...
...
@@ -324,20 +318,20 @@ class MessageController extends Controller
$fileName
.=
'.merged'
;
}
if
(
$format
===
'po'
){
$out
_str
=
''
;
$out
put
=
''
;
foreach
(
$merged
as
$k
=>
$v
){
$k
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$k
);
$v
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$v
);
if
(
substr
(
$v
,
0
,
2
)
===
'@@'
&&
substr
(
$v
,
-
2
)
===
'@@'
)
{
$out
_str
.=
"#msgid
\"
$k
\"\n
"
;
$out
_str
.=
"#msgstr
\"
$v
\"\n
"
;
$out
put
.=
"#msgid
\"
$k
\"\n
"
;
$out
put
.=
"#msgstr
\"
$v
\"\n
"
;
}
else
{
$out
_str
.=
"msgid
\"
$k
\"\n
"
;
$out
_str
.=
"msgstr
\"
$v
\"\n
"
;
$out
put
.=
"msgid
\"
$k
\"\n
"
;
$out
put
.=
"msgstr
\"
$v
\"\n
"
;
}
$out
_str
.=
"
\n
"
;
$out
put
.=
"
\n
"
;
}
$merged
=
$out
_str
;
$merged
=
$out
put
;
}
echo
"translation merged.
\n
"
;
}
else
{
...
...
framework/views/messageConfig.php
View file @
4fe0eeb1
...
...
@@ -44,6 +44,7 @@ return [
],
// Generated file format. Can be either "php", "po" or "db".
'format'
=>
'php'
,
// Connection component ID for "db".
//'connectionID' => 'db',
// When format is "db", you may specify the following two options
//'db' => 'db',
//'sourceMessageTable' => '{{%source_message}}',
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment