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