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
48b8089d
Commit
48b8089d
authored
Jan 17, 2014
by
Digimon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code format fixed
parent
c3976b0f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
31 deletions
+11
-31
MessageController.php
framework/console/controllers/MessageController.php
+11
-31
No files found.
framework/console/controllers/MessageController.php
View file @
48b8089d
...
...
@@ -77,16 +77,13 @@ class MessageController extends Controller
throw
new
Exception
(
"The configuration file does not exist:
$configFile
"
);
}
$config
=
array_merge
(
[
$config
=
array_merge
([
'translator'
=>
'Yii::t'
,
'overwrite'
=>
false
,
'removeUnused'
=>
false
,
'sort'
=>
false
,
'format'
=>
'php'
,
],
require
(
$configFile
)
);
],
require
(
$configFile
));
if
(
!
isset
(
$config
[
'sourcePath'
],
$config
[
'messagePath'
],
$config
[
'languages'
]))
{
throw
new
Exception
(
'The configuration file must specify "sourcePath", "messagePath" and "languages".'
);
...
...
@@ -125,23 +122,11 @@ class MessageController extends Controller
mkdir
(
$path
,
0755
,
true
);
}
$msgs
=
array_values
(
array_unique
(
$msgs
));
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
],
$config
[
'format'
]
);
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
],
$config
[
'format'
]);
}
}
}
if
(
$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.'
);
}
$sourceMessageTable
=
!
isset
(
$config
[
'sourceMessageTable'
])
?
'SourceMessage'
:
$config
[
'sourceMessageTable'
];
foreach
(
$config
[
'languages'
]
as
$language
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
$messages
[
$category
]
=
array_values
(
array_unique
(
$msgs
));
...
...
@@ -162,9 +147,7 @@ class MessageController extends Controller
$q
=
new
\yii\db\Query
;
$current
=
[];
foreach
(
$q
->
select
([
'id'
,
'category'
,
'message'
])
->
from
(
$sourceMessageTable
)
->
all
()
as
$row
)
{
foreach
(
$q
->
select
([
'id'
,
'category'
,
'message'
])
->
from
(
$sourceMessageTable
)
->
all
()
as
$row
)
{
$current
[
$row
[
'category'
]][
$row
[
'id'
]]
=
$row
[
'message'
];
}
...
...
@@ -229,6 +212,7 @@ class MessageController extends Controller
}
}
/**
* Extracts messages from a file
*
...
...
@@ -247,10 +231,7 @@ class MessageController extends Controller
foreach
(
$translator
as
$currentTranslator
)
{
$n
=
preg_match_all
(
'/\b'
.
$currentTranslator
.
'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s'
,
$subject
,
$matches
,
PREG_SET_ORDER
);
$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
);
...
...
@@ -278,7 +259,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
);
...
...
@@ -295,7 +276,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
)
{
...
...
@@ -327,9 +308,9 @@ class MessageController extends Controller
if
(
false
===
$overwrite
)
{
$fileName
.=
'.merged'
;
}
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$out_str
=
''
;
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
)
===
'@@'
)
{
...
...
@@ -348,7 +329,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
"
;
...
...
@@ -393,4 +374,3 @@ EOD;
file_put_contents
(
$fileName
,
$content
);
}
}
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