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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
05db070b
Commit
05db070b
authored
Jan 22, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjusted #2008
parent
583c56d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
24 deletions
+33
-24
MessageController.php
framework/console/controllers/MessageController.php
+27
-22
config.php
framework/messages/config.php
+3
-1
messageConfig.php
framework/views/messageConfig.php
+3
-1
No files found.
framework/console/controllers/MessageController.php
View file @
05db070b
...
...
@@ -9,15 +9,19 @@
namespace
yii\console\controllers
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\console\Controller
;
use
yii\console\Exception
;
use
yii\helpers\FileHelper
;
/**
* This command extracts messages to be translated from source files.
* The extracted messages are saved either as PHP message source files
* or ".po" files under the specified directory or to a database. Format
* depends on `format` setting in config file.
* The extracted messages can be saved the following depending on `format`
* setting in config file:
*
* - PHP message source files.
* - ".po" files.
* - Database.
*
* Usage:
* 1. Create a configuration file using the 'message/config' command:
...
...
@@ -125,13 +129,12 @@ class MessageController extends Controller
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
],
$config
[
'format'
]);
}
}
}
if
(
$config
[
'format'
]
===
'db'
)
{
}
elseif
(
$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.'
);
throw
new
Exception
(
'The "connectionID" must refer to a valid database application component.'
);
}
$sourceMessageTable
=
!
isset
(
$config
[
'sourceMessageTable'
])
?
'SourceMessage'
:
$config
[
'sourceMessageTable'
]
;
$sourceMessageTable
=
isset
(
$config
[
'sourceMessageTable'
])
?
$config
[
'sourceMessageTable'
]
:
'SourceMessage'
;
$res
=
[];
foreach
(
$config
[
'languages'
]
as
$language
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
...
...
@@ -148,11 +151,13 @@ class MessageController extends Controller
}
/**
* @param $messages
* @param \yii\db\Connection $dbConnection
* @param $sourceMessageTable
* @param $removeUnused
*/
* Saves messages to database
*
* @param array $messages
* @param \yii\db\Connection $dbConnection
* @param string $sourceMessageTable
* @param boolean $removeUnused
*/
protected
function
saveMessagesToDb
(
$messages
,
$dbConnection
,
$sourceMessageTable
,
$removeUnused
)
{
$q
=
new
\yii\db\Query
;
...
...
@@ -163,36 +168,36 @@ class MessageController extends Controller
}
$new
=
[];
$obsolete
d
=
[];
$obsolete
=
[];
foreach
(
$messages
as
$category
=>
$msgs
)
{
$msgs
=
array_unique
(
$msgs
);
if
(
isset
(
$current
[
$category
]))
{
$new
[
$category
]
=
array_diff
(
$msgs
,
$current
[
$category
]);
$obsolete
d
=
array_diff
(
$current
[
$category
],
$msgs
);
$obsolete
=
array_diff
(
$current
[
$category
],
$msgs
);
}
else
{
$new
[
$category
]
=
$msgs
;
}
}
foreach
(
array_diff
(
array_keys
(
$current
),
array_keys
(
$messages
))
as
$category
)
{
$obsolete
d
+=
$current
[
$category
];
$obsolete
+=
$current
[
$category
];
}
if
(
!
$removeUnused
)
{
foreach
(
$obsolete
d
as
$pk
=>
$m
)
{
foreach
(
$obsolete
as
$pk
=>
$m
)
{
if
(
mb_substr
(
$m
,
0
,
2
)
===
'@@'
&&
mb_substr
(
$m
,
-
2
)
===
'@@'
)
{
unset
(
$obsolete
d
[
$pk
]);
unset
(
$obsolete
[
$pk
]);
}
}
}
$obsolete
d
=
array_keys
(
$obsoleted
);
$obsolete
=
array_keys
(
$obsolete
);
echo
"Inserting new messages..."
;
$savedFlag
=
false
;
foreach
(
$new
as
$category
=>
$msgs
)
{
foreach
(
$new
as
$category
=>
$msgs
)
{
foreach
(
$msgs
as
$m
)
{
$savedFlag
=
true
;
...
...
@@ -204,19 +209,19 @@ class MessageController extends Controller
echo
$savedFlag
?
"saved.
\n
"
:
"nothing new...skipped.
\n
"
;
echo
$removeUnused
?
"Deleting obsoleted messages..."
:
"Updating obsoleted messages..."
;
if
(
empty
(
$obsolete
d
))
{
if
(
empty
(
$obsolete
))
{
echo
"nothing obsoleted...skipped.
\n
"
;
}
else
{
if
(
$removeUnused
)
{
$dbConnection
->
createCommand
()
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
d
])
->
execute
();
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
])
->
execute
();
echo
"deleted.
\n
"
;
}
else
{
$dbConnection
->
createCommand
()
->
update
(
$sourceMessageTable
,
[
'message'
=>
new
\yii\db\Expression
(
"CONCAT('@@',message,'@@')"
)],
[
'in'
,
'id'
,
$obsolete
d
]
[
'in'
,
'id'
,
$obsolete
]
)
->
execute
();
echo
"updated.
\n
"
;
}
...
...
framework/messages/config.php
View file @
05db070b
...
...
@@ -42,6 +42,8 @@ return [
'.hgkeep'
,
'/messages'
,
],
// Generated file format. Can be either "
db", "php" or "po
".
// Generated file format. Can be either "
php", "po" or "db
".
'format'
=>
'php'
,
// Connection component ID for "db".
//'connectionID' => 'db',
];
framework/views/messageConfig.php
View file @
05db070b
...
...
@@ -42,6 +42,8 @@ return [
'.hgkeep'
,
'/messages'
,
],
// Generated file format. Can be either "php"
or "po
".
// Generated file format. Can be either "php"
, "po" or "db
".
'format'
=>
'php'
,
// Connection component ID for "db".
//'connectionID' => 'db',
];
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