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
7c9f7472
Commit
7c9f7472
authored
Jun 11, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"yii\console\controllers\MessageController" has been fixed.
parent
41d1a354
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
18 deletions
+26
-18
MessageController.php
framework/yii/console/controllers/MessageController.php
+18
-12
MessageControllerTest.php
...t/framework/console/controllers/MessageControllerTest.php
+8
-6
No files found.
framework/yii/console/controllers/MessageController.php
View file @
7c9f7472
...
...
@@ -55,7 +55,8 @@ class MessageController extends Controller
* directory 'sourcePath/a/b'.
* - translator: the name of the function for translating messages.
* Defaults to 'Yii::t'. This is used as a mark to find messages to be
* translated.
* translated. Accepts both string for single function name or array for
* multiple function names.
* - overwrite: if message file must be overwritten with the merged messages.
* - removeOld: if message no longer needs translation it will be removed,
* instead of being enclosed between a pair of '@@' marks.
...
...
@@ -133,18 +134,23 @@ class MessageController extends Controller
{
echo
"Extracting messages from
$fileName
...
\n
"
;
$subject
=
file_get_contents
(
$fileName
);
$n
=
preg_match_all
(
'/\b'
.
$translator
.
'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s'
,
$subject
,
$matches
,
PREG_SET_ORDER
);
$messages
=
array
();
for
(
$i
=
0
;
$i
<
$n
;
++
$i
)
{
if
((
$pos
=
strpos
(
$matches
[
$i
][
1
],
'.'
))
!==
false
)
{
$category
=
substr
(
$matches
[
$i
][
1
],
$pos
+
1
,
-
1
);
}
else
{
$category
=
substr
(
$matches
[
$i
][
1
],
1
,
-
1
);
if
(
!
is_array
(
$translator
))
{
$translator
=
array
(
$translator
);
}
foreach
(
$translator
as
$currentTranslator
)
{
$n
=
preg_match_all
(
'/\b'
.
$currentTranslator
.
'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s'
,
$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
);
}
else
{
$category
=
substr
(
$matches
[
$i
][
1
],
1
,
-
1
);
}
$message
=
$matches
[
$i
][
2
];
$messages
[
$category
][]
=
eval
(
"return
$message
;"
);
// use eval to eliminate quote escape
}
$message
=
$matches
[
$i
][
2
];
$messages
[
$category
][]
=
eval
(
"return
$message
;"
);
// use eval to eliminate quote escape
}
return
$messages
;
}
...
...
@@ -172,7 +178,7 @@ class MessageController extends Controller
$merged
=
array
();
$untranslated
=
array
();
foreach
(
$messages
as
$message
)
{
if
(
!
empty
(
$translated
[
$message
])
)
{
if
(
array_key_exists
(
$message
,
$translated
)
&&
strlen
(
$translated
[
$message
])
>
0
)
{
$merged
[
$message
]
=
$translated
[
$message
];
}
else
{
$untranslated
[]
=
$message
;
...
...
tests/unit/framework/console/controllers/MessageControllerTest.php
View file @
7c9f7472
...
...
@@ -17,6 +17,9 @@ class MessageControllerTest extends TestCase
{
$this
->
sourcePath
=
Yii
::
getAlias
(
'@yiiunit/runtime/test_source'
);
$this
->
createDir
(
$this
->
sourcePath
);
if
(
!
file_exists
(
$this
->
sourcePath
))
{
$this
->
markTestIncomplete
(
'Unit tests runtime directory should have writable permissions!'
);
}
$this
->
messagePath
=
Yii
::
getAlias
(
'@yiiunit/runtime/test_messages'
);
$this
->
createDir
(
$this
->
messagePath
);
$this
->
configFileName
=
Yii
::
getAlias
(
'@yiiunit/runtime'
)
.
DIRECTORY_SEPARATOR
.
'message_controller_test_config.php'
;
...
...
@@ -81,8 +84,9 @@ class MessageControllerTest extends TestCase
protected
function
createMessageController
()
{
$module
=
$this
->
getMock
(
'yii\\base\\Module'
,
array
(
'fake'
),
array
(
'console'
));
$command
=
new
MessageController
(
'message'
,
$module
);
return
$command
;
$messageController
=
new
MessageController
(
'message'
,
$module
);
$messageController
->
interactive
=
false
;
return
$messageController
;
}
/**
...
...
@@ -91,7 +95,7 @@ class MessageControllerTest extends TestCase
* @param array $args action arguments.
* @return string command output.
*/
protected
function
runMessageControllerAction
(
$actionId
,
array
$args
=
array
())
protected
function
runMessageControllerAction
(
$actionId
,
array
$args
=
array
())
{
$controller
=
$this
->
createMessageController
();
ob_start
();
...
...
@@ -166,13 +170,11 @@ class MessageControllerTest extends TestCase
public
function
testCreateTranslation
()
{
$this
->
markTestIncomplete
(
'MessageController is incomplete'
);
$language
=
'en'
;
$category
=
'test_category'
;
$message
=
'test message'
;
$sourceFileContent
=
"Yii::t('
{
$category
}
','
{
$message
}
')"
;
$sourceFileContent
=
"Yii::t('
{
$category
}
',
'
{
$message
}
')"
;
$this
->
createSourceFile
(
$sourceFileContent
);
$this
->
composeConfigFile
(
array
(
...
...
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