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
1a14ed21
Commit
1a14ed21
authored
Mar 04, 2014
by
Sorokin Victor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update MessageController.php
parent
4d4a3f08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
MessageController.php
framework/console/controllers/MessageController.php
+21
-21
No files found.
framework/console/controllers/MessageController.php
View file @
1a14ed21
...
...
@@ -134,14 +134,14 @@ class MessageController extends Controller
throw
new
Exception
(
'The "db" option must refer to a valid database application component.'
);
}
$sourceMessageTable
=
isset
(
$config
[
'sourceMessageTable'
])
?
$config
[
'sourceMessageTable'
]
:
'{{%source_message}}'
;
$messageTable
=
isset
(
$config
[
'messageTable'
])
?
$config
[
'messageTable'
]
:
'{{%message}}'
;
$messageTable
=
isset
(
$config
[
'messageTable'
])
?
$config
[
'messageTable'
]
:
'{{%message}}'
;
$this
->
saveMessagesToDb
(
$messages
,
$db
,
$sourceMessageTable
,
$messageTable
,
$messageTable
,
$config
[
'removeUnused'
],
$config
[
'languages'
]
$config
[
'languages'
]
);
}
}
...
...
@@ -152,9 +152,9 @@ class MessageController extends Controller
* @param array $messages
* @param \yii\db\Connection $db
* @param string $sourceMessageTable
* @param string $messageTable
* @param string $messageTable
* @param boolean $removeUnused
* @param array $languages
* @param array $languages
*/
protected
function
saveMessagesToDb
(
$messages
,
$db
,
$sourceMessageTable
,
$messageTable
,
$removeUnused
,
$languages
)
{
...
...
@@ -195,16 +195,16 @@ class MessageController extends Controller
echo
"Inserting new messages..."
;
$savedFlag
=
false
;
foreach
(
$new
as
$category
=>
$msgs
)
{
foreach
(
$new
as
$category
=>
$msgs
)
{
foreach
(
$msgs
as
$m
)
{
$savedFlag
=
true
;
$db
->
createCommand
()
->
insert
(
$sourceMessageTable
,
[
'category'
=>
$category
,
'message'
=>
$m
])
->
execute
();
$lastId
=
$db
->
getLastInsertID
();
->
insert
(
$sourceMessageTable
,
[
'category'
=>
$category
,
'message'
=>
$m
])
->
execute
();
$lastId
=
$db
->
getLastInsertID
();
foreach
(
$languages
as
$language
)
{
$db
->
createCommand
()
->
insert
(
$messageTable
,
[
'id'
=>
$lastId
,
'language'
=>
$language
])
->
execute
();
->
insert
(
$messageTable
,
[
'id'
=>
$lastId
,
'language'
=>
$language
])
->
execute
();
}
}
}
...
...
@@ -217,19 +217,19 @@ class MessageController extends Controller
}
else
{
if
(
$removeUnused
)
{
$db
->
createCommand
()
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
])
->
execute
();
echo
"deleted.
\n
"
;
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
])
->
execute
();
echo
"deleted.
\n
"
;
}
else
{
$last_id
=
$db
->
getLastInsertID
();
$last_id
=
$db
->
getLastInsertID
();
$db
->
createCommand
()
->
update
(
->
update
(
$sourceMessageTable
,
[
'message'
=>
new
\yii\db\Expression
(
"CONCAT('@@',message,'@@')"
)],
[
'in'
,
'id'
,
$obsolete
]
)
->
execute
();
foreach
(
$languages
as
$language
)
{
$db
->
createCommand
()
->
insert
(
$messageTable
,
[
'id'
=>
$last_id
,
'language'
=>
$language
])
->
execute
();
foreach
(
$languages
as
$language
)
{
$db
->
createCommand
()
->
insert
(
$messageTable
,
[
'id'
=>
$last_id
,
'language'
=>
$language
])
->
execute
();
}
echo
"updated.
\n
"
;
}
...
...
@@ -283,7 +283,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
);
...
...
@@ -300,7 +300,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
)
{
...
...
@@ -332,9 +332,9 @@ class MessageController extends Controller
if
(
false
===
$overwrite
)
{
$fileName
.=
'.merged'
;
}
if
(
$format
===
'po'
){
if
(
$format
===
'po'
)
{
$output
=
''
;
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
)
===
'@@'
)
{
...
...
@@ -353,7 +353,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
"
;
...
...
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