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
f6e6ea99
Commit
f6e6ea99
authored
Jan 14, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1973 from SergeiKutanov/po_generation
po file generating added.
parents
2aa8fc71
77776576
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
12 deletions
+52
-12
MessageController.php
framework/console/controllers/MessageController.php
+52
-12
No files found.
framework/console/controllers/MessageController.php
View file @
f6e6ea99
...
@@ -69,7 +69,7 @@ class MessageController extends Controller
...
@@ -69,7 +69,7 @@ class MessageController extends Controller
* this file and then customize it for your needs.
* this file and then customize it for your needs.
* @throws Exception on failure.
* @throws Exception on failure.
*/
*/
public
function
actionExtract
(
$configFile
)
public
function
actionExtract
(
$configFile
,
$out
=
null
)
{
{
$configFile
=
Yii
::
getAlias
(
$configFile
);
$configFile
=
Yii
::
getAlias
(
$configFile
);
if
(
!
is_file
(
$configFile
))
{
if
(
!
is_file
(
$configFile
))
{
...
@@ -109,13 +109,21 @@ class MessageController extends Controller
...
@@ -109,13 +109,21 @@ class MessageController extends Controller
@
mkdir
(
$dir
);
@
mkdir
(
$dir
);
}
}
foreach
(
$messages
as
$category
=>
$msgs
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
$file
=
str_replace
(
"
\\
"
,
'/'
,
"
$dir
/
$category
.php"
);
if
(
$out
==
'po'
){
$file
=
str_replace
(
"
\\
"
,
'/'
,
"
$dir
/
$category
.po"
);
}
else
if
(
$out
==
null
){
$file
=
str_replace
(
"
\\
"
,
'/'
,
"
$dir
/
$category
.php"
);
}
$path
=
dirname
(
$file
);
$path
=
dirname
(
$file
);
if
(
!
is_dir
(
$path
))
{
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
,
0755
,
true
);
mkdir
(
$path
,
0755
,
true
);
}
}
$msgs
=
array_values
(
array_unique
(
$msgs
));
$msgs
=
array_values
(
array_unique
(
$msgs
));
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
]);
if
(
$out
==
'po'
){
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
],
$out
);
}
else
if
(
$out
==
null
){
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
]);
}
}
}
}
}
}
}
...
@@ -161,11 +169,19 @@ class MessageController extends Controller
...
@@ -161,11 +169,19 @@ class MessageController extends Controller
* @param boolean $removeUnused if obsolete translations should be removed
* @param boolean $removeUnused if obsolete translations should be removed
* @param boolean $sort if translations should be sorted
* @param boolean $sort if translations should be sorted
*/
*/
protected
function
generateMessageFile
(
$messages
,
$fileName
,
$overwrite
,
$removeUnused
,
$sort
)
protected
function
generateMessageFile
(
$messages
,
$fileName
,
$overwrite
,
$removeUnused
,
$sort
,
$type
=
null
)
{
{
echo
"Saving messages to
$fileName
..."
;
echo
"Saving messages to
$fileName
..."
;
if
(
is_file
(
$fileName
))
{
if
(
is_file
(
$fileName
))
{
$translated
=
require
(
$fileName
);
if
(
$type
==
'po'
){
$translated
=
file_get_contents
(
$fileName
);
preg_match_all
(
'/(?<=msgid ").*(?="\nmsgstr)/'
,
$translated
,
$keys
);
preg_match_all
(
'/(?<=msgstr ").*(?="\n\n)/'
,
$translated
,
$values
);
$translated
=
array_combine
(
$keys
[
0
],
$values
[
0
]);
}
else
if
(
$type
==
null
){
$translated
=
require
(
$fileName
);
}
sort
(
$messages
);
sort
(
$messages
);
ksort
(
$translated
);
ksort
(
$translated
);
if
(
array_keys
(
$translated
)
==
$messages
)
{
if
(
array_keys
(
$translated
)
==
$messages
)
{
...
@@ -204,17 +220,40 @@ class MessageController extends Controller
...
@@ -204,17 +220,40 @@ class MessageController extends Controller
if
(
false
===
$overwrite
)
{
if
(
false
===
$overwrite
)
{
$fileName
.=
'.merged'
;
$fileName
.=
'.merged'
;
}
}
if
(
$type
==
'po'
){
$out_str
=
''
;
ksort
(
$merged
);
foreach
(
$merged
as
$k
=>
$v
){
$out_str
.=
"msgid
\"
$k
\"\n
"
;
$out_str
.=
"msgstr
\"
$v
\"\n
"
;
$out_str
.=
"
\n
"
;
}
$merged
=
$out_str
;
}
echo
"translation merged.
\n
"
;
echo
"translation merged.
\n
"
;
}
else
{
}
else
{
$merged
=
[];
if
(
$type
==
'po'
){
foreach
(
$messages
as
$message
)
{
$merged
=
''
;
$merged
[
$message
]
=
''
;
sort
(
$messages
);
}
foreach
(
$messages
as
$message
){
ksort
(
$merged
);
$merged
.=
"msgid
\"
$message
\"\n
"
;
$merged
.=
"msgstr
\"\"\n
"
;
$merged
.=
"
\n
"
;
}
}
else
if
(
$type
==
null
){
$merged
=
[];
foreach
(
$messages
as
$message
)
{
$merged
[
$message
]
=
''
;
}
ksort
(
$merged
);
}
echo
"saved.
\n
"
;
echo
"saved.
\n
"
;
}
}
$array
=
str_replace
(
"
\r
"
,
''
,
var_export
(
$merged
,
true
));
if
(
$type
==
'po'
){
$content
=
<<<EOD
$content
=
$merged
;
}
else
if
(
$type
==
null
){
$array
=
str_replace
(
"
\r
"
,
''
,
var_export
(
$merged
,
true
));
$content
=
<<<EOD
<?php
<?php
/**
/**
* Message translations.
* Message translations.
...
@@ -236,6 +275,7 @@ class MessageController extends Controller
...
@@ -236,6 +275,7 @@ class MessageController extends Controller
return $array;
return $array;
EOD;
EOD;
}
file_put_contents
(
$fileName
,
$content
);
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