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
...
@@ -77,16 +77,13 @@ class MessageController extends Controller
throw
new
Exception
(
"The configuration file does not exist:
$configFile
"
);
throw
new
Exception
(
"The configuration file does not exist:
$configFile
"
);
}
}
$config
=
array_merge
(
$config
=
array_merge
([
[
'translator'
=>
'Yii::t'
,
'translator'
=>
'Yii::t'
,
'overwrite'
=>
false
,
'overwrite'
=>
false
,
'removeUnused'
=>
false
,
'removeUnused'
=>
false
,
'sort'
=>
false
,
'sort'
=>
false
,
'format'
=>
'php'
,
'format'
=>
'php'
,
],
],
require
(
$configFile
));
require
(
$configFile
)
);
if
(
!
isset
(
$config
[
'sourcePath'
],
$config
[
'messagePath'
],
$config
[
'languages'
]))
{
if
(
!
isset
(
$config
[
'sourcePath'
],
$config
[
'messagePath'
],
$config
[
'languages'
]))
{
throw
new
Exception
(
'The configuration file must specify "sourcePath", "messagePath" and "languages".'
);
throw
new
Exception
(
'The configuration file must specify "sourcePath", "messagePath" and "languages".'
);
...
@@ -125,23 +122,11 @@ class MessageController extends Controller
...
@@ -125,23 +122,11 @@ class MessageController extends Controller
mkdir
(
$path
,
0755
,
true
);
mkdir
(
$path
,
0755
,
true
);
}
}
$msgs
=
array_values
(
array_unique
(
$msgs
));
$msgs
=
array_values
(
array_unique
(
$msgs
));
$this
->
generateMessageFile
(
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
],
$config
[
'format'
]);
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
],
$config
[
'format'
]
);
}
}
}
}
}
}
if
(
$config
[
'format'
]
===
'db'
)
{
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
(
$config
[
'languages'
]
as
$language
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
$messages
[
$category
]
=
array_values
(
array_unique
(
$msgs
));
$messages
[
$category
]
=
array_values
(
array_unique
(
$msgs
));
...
@@ -162,9 +147,7 @@ class MessageController extends Controller
...
@@ -162,9 +147,7 @@ class MessageController extends Controller
$q
=
new
\yii\db\Query
;
$q
=
new
\yii\db\Query
;
$current
=
[];
$current
=
[];
foreach
(
$q
->
select
([
'id'
,
'category'
,
'message'
])
foreach
(
$q
->
select
([
'id'
,
'category'
,
'message'
])
->
from
(
$sourceMessageTable
)
->
all
()
as
$row
)
{
->
from
(
$sourceMessageTable
)
->
all
()
as
$row
)
{
$current
[
$row
[
'category'
]][
$row
[
'id'
]]
=
$row
[
'message'
];
$current
[
$row
[
'category'
]][
$row
[
'id'
]]
=
$row
[
'message'
];
}
}
...
@@ -229,6 +212,7 @@ class MessageController extends Controller
...
@@ -229,6 +212,7 @@ class MessageController extends Controller
}
}
}
}
/**
/**
* Extracts messages from a file
* Extracts messages from a file
*
*
...
@@ -247,10 +231,7 @@ class MessageController extends Controller
...
@@ -247,10 +231,7 @@ class MessageController extends Controller
foreach
(
$translator
as
$currentTranslator
)
{
foreach
(
$translator
as
$currentTranslator
)
{
$n
=
preg_match_all
(
$n
=
preg_match_all
(
'/\b'
.
$currentTranslator
.
'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s'
,
'/\b'
.
$currentTranslator
.
'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s'
,
$subject
,
$subject
,
$matches
,
PREG_SET_ORDER
);
$matches
,
PREG_SET_ORDER
);
for
(
$i
=
0
;
$i
<
$n
;
++
$i
)
{
for
(
$i
=
0
;
$i
<
$n
;
++
$i
)
{
if
((
$pos
=
strpos
(
$matches
[
$i
][
1
],
'.'
))
!==
false
)
{
if
((
$pos
=
strpos
(
$matches
[
$i
][
1
],
'.'
))
!==
false
)
{
$category
=
substr
(
$matches
[
$i
][
1
],
$pos
+
1
,
-
1
);
$category
=
substr
(
$matches
[
$i
][
1
],
$pos
+
1
,
-
1
);
...
@@ -278,7 +259,7 @@ class MessageController extends Controller
...
@@ -278,7 +259,7 @@ class MessageController extends Controller
{
{
echo
"Saving messages to
$fileName
..."
;
echo
"Saving messages to
$fileName
..."
;
if
(
is_file
(
$fileName
))
{
if
(
is_file
(
$fileName
))
{
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$translated
=
file_get_contents
(
$fileName
);
$translated
=
file_get_contents
(
$fileName
);
preg_match_all
(
'/(?<=msgid ").*(?="\n(#*)msgstr)/'
,
$translated
,
$keys
);
preg_match_all
(
'/(?<=msgid ").*(?="\n(#*)msgstr)/'
,
$translated
,
$keys
);
preg_match_all
(
'/(?<=msgstr ").*(?="\n\n)/'
,
$translated
,
$values
);
preg_match_all
(
'/(?<=msgstr ").*(?="\n\n)/'
,
$translated
,
$values
);
...
@@ -295,7 +276,7 @@ class MessageController extends Controller
...
@@ -295,7 +276,7 @@ class MessageController extends Controller
$merged
=
[];
$merged
=
[];
$untranslated
=
[];
$untranslated
=
[];
foreach
(
$messages
as
$message
)
{
foreach
(
$messages
as
$message
)
{
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$message
=
preg_replace
(
'/\"/'
,
'\"'
,
$message
);
$message
=
preg_replace
(
'/\"/'
,
'\"'
,
$message
);
}
}
if
(
array_key_exists
(
$message
,
$translated
)
&&
strlen
(
$translated
[
$message
])
>
0
)
{
if
(
array_key_exists
(
$message
,
$translated
)
&&
strlen
(
$translated
[
$message
])
>
0
)
{
...
@@ -327,9 +308,9 @@ class MessageController extends Controller
...
@@ -327,9 +308,9 @@ class MessageController extends Controller
if
(
false
===
$overwrite
)
{
if
(
false
===
$overwrite
)
{
$fileName
.=
'.merged'
;
$fileName
.=
'.merged'
;
}
}
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$out_str
=
''
;
$out_str
=
''
;
foreach
(
$merged
as
$k
=>
$v
)
{
foreach
(
$merged
as
$k
=>
$v
)
{
$k
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$k
);
$k
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$k
);
$v
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$v
);
$v
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$v
);
if
(
substr
(
$v
,
0
,
2
)
===
'@@'
&&
substr
(
$v
,
-
2
)
===
'@@'
)
{
if
(
substr
(
$v
,
0
,
2
)
===
'@@'
&&
substr
(
$v
,
-
2
)
===
'@@'
)
{
...
@@ -348,7 +329,7 @@ class MessageController extends Controller
...
@@ -348,7 +329,7 @@ class MessageController extends Controller
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$merged
=
''
;
$merged
=
''
;
sort
(
$messages
);
sort
(
$messages
);
foreach
(
$messages
as
$message
)
{
foreach
(
$messages
as
$message
)
{
$message
=
preg_replace
(
'/(\")|(\\\")/'
,
'\\\"'
,
$message
);
$message
=
preg_replace
(
'/(\")|(\\\")/'
,
'\\\"'
,
$message
);
$merged
.=
"msgid
\"
$message
\"\n
"
;
$merged
.=
"msgid
\"
$message
\"\n
"
;
$merged
.=
"msgstr
\"\"\n
"
;
$merged
.=
"msgstr
\"\"\n
"
;
...
@@ -393,4 +374,3 @@ EOD;
...
@@ -393,4 +374,3 @@ 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