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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
3713b369
Commit
3713b369
authored
Jan 15, 2014
by
Paul Klimov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
parents
91c86fb7
e09b016a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
20 deletions
+88
-20
init
apps/advanced/init
+20
-5
assets.md
docs/guide/assets.md
+4
-0
CHANGELOG.md
framework/CHANGELOG.md
+4
-0
Controller.php
framework/base/Controller.php
+1
-1
MessageController.php
framework/console/controllers/MessageController.php
+49
-12
BaseHtml.php
framework/helpers/BaseHtml.php
+5
-1
config.php
framework/messages/config.php
+2
-0
messageConfig.php
framework/views/messageConfig.php
+3
-1
No files found.
apps/advanced/init
View file @
3713b369
#!/usr/bin/env php
<?php
/**
* Yii Application Initialization Tool
*
* In order to run in non-interactive mode:
*
* init --env=dev --overwrite=n
*
* @author Alexander Makarov <sam@rmcreative.ru>
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
$params
=
getParams
();
$root
=
str_replace
(
'\\'
,
'/'
,
__DIR__
);
$envs
=
require
(
"
$root
/environments/index.php"
);
...
...
@@ -24,8 +38,7 @@ if (empty($params['env']) || $params['env'] === '1') {
if
(
isset
(
$envNames
[
$answer
]))
{
$envName
=
$envNames
[
$answer
];
}
}
else
{
}
else
{
$envName
=
$params
[
'env'
];
}
...
...
@@ -50,7 +63,7 @@ echo "\n Start initialization ...\n\n";
$files
=
getFileList
(
"
$root
/environments/
{
$env
[
'path'
]
}
"
);
$all
=
false
;
foreach
(
$files
as
$file
)
{
if
(
!
copyFile
(
$root
,
"environments/
{
$env
[
'path'
]
}
/
$file
"
,
$file
,
$all
))
{
if
(
!
copyFile
(
$root
,
"environments/
{
$env
[
'path'
]
}
/
$file
"
,
$file
,
$all
,
$params
))
{
break
;
}
}
...
...
@@ -91,7 +104,7 @@ function getFileList($root, $basePath = '')
return
$files
;
}
function
copyFile
(
$root
,
$source
,
$target
,
&
$all
)
function
copyFile
(
$root
,
$source
,
$target
,
&
$all
,
$params
)
{
if
(
!
is_file
(
$root
.
'/'
.
$source
))
{
echo
" skip
$target
(
$source
not exist)
\n
"
;
...
...
@@ -107,7 +120,9 @@ function copyFile($root, $source, $target, &$all)
}
else
{
echo
" exist
$target
\n
"
;
echo
" ...overwrite? [Yes|No|All|Quit] "
;
$answer
=
trim
(
fgets
(
STDIN
));
$answer
=
!
empty
(
$params
[
'overwrite'
])
?
$params
[
'overwrite'
]
:
trim
(
fgets
(
STDIN
));
if
(
!
strncasecmp
(
$answer
,
'q'
,
1
))
{
return
false
;
}
else
{
...
...
docs/guide/assets.md
View file @
3713b369
...
...
@@ -52,6 +52,10 @@ Here `yii\web\YiiAsset` adds Yii's JavaScript library while `yii\bootstrap\Boots
Asset bundles are regular classes so if you need to define another one, just create alike class with unique name. This
class can be placed anywhere but the convention for it is to be under
`assets`
directory of the application.
Additionally you may specify
`$jsOptions`
,
`$cssOptions`
and
`$publishOptions`
that will be passed to
[
[\yii\web\View::registerJsFile()
]
],
[
[\yii\web\View::registerCssFile()
]
] and
[
[\yii\web\AssetManager::publish()
]
]
respectively during registering and publising an asset.
Registering asset bundle
------------------------
...
...
framework/CHANGELOG.md
View file @
3713b369
...
...
@@ -27,6 +27,8 @@ Yii Framework 2 Change Log
-
Bug #1827: Debugger toolbar is loaded twice if an action is calling
`run()`
to execute another action (qiangxue)
-
Bug #1870: Validation errors weren't properly translated when using clientside validation (samdark)
-
Bug #1937: Fixed wrong behavior or advanced app's
`init --env`
when called without parameter actually specified (samdark)
-
Bug #1959:
`Html::activeCheckbox`
wasn't respecting custom values for checked/unckecked state (klevron, samdark)
-
Bug #1965:
`Controller::findLayoutFile()`
returns incorrect file path when layout name starts with a slash (qiangxue)
-
Bug: Fixed
`Call to a member function registerAssetFiles() on a non-object`
in case of wrong
`sourcePath`
for an asset bundle (samdark)
-
Bug: Fixed incorrect event name for
`yii\jui\Spinner`
(samdark)
-
Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
...
...
@@ -62,6 +64,7 @@ Yii Framework 2 Change Log
-
Enh #1852: ActiveRecord::tableName() now returns table name using DbConnection::tablePrefix (creocoder)
-
Enh #1894: The path aliases
`@webroot`
and
`@web`
are now available right after the application is initialized (qiangxue)
-
Enh #1921: Grid view ActionColumn now allow to name buttons like
`{controller/action}`
(creocoder)
-
Enh #1973:
`yii message/extract`
is now able to generate
`.po`
files (SergeiKutanov, samdark)
-
Enh: Added
`favicon.ico`
and
`robots.txt`
to default application templates (samdark)
-
Enh: Added
`Widget::autoIdPrefix`
to support prefixing automatically generated widget IDs (qiangxue)
-
Enh: Support for file aliases in console command 'message' (omnilight)
...
...
@@ -69,6 +72,7 @@ Yii Framework 2 Change Log
-
Enh: Added support for using array-typed arguments for console commands (qiangxue)
-
Enh: Added support for installing packages conforming to PSR-4 standard (qiangxue)
-
Enh: Better exception message when class cannot be loaded (samdark)
-
Enh:
`init`
of advanced application now allows to specify answer for overwriting files via
`init --overwrite=n`
(samdark)
-
Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic)
-
Chg #1519:
`yii\web\User::loginRequired()`
now returns the
`Response`
object instead of exiting the application (qiangxue)
-
Chg #1586:
`QueryBuilder::buildLikeCondition()`
will now escape special characters and use percentage characters by default (qiangxue)
...
...
framework/base/Controller.php
View file @
3713b369
...
...
@@ -400,7 +400,7 @@ class Controller extends Component implements ViewContextInterface
if
(
strncmp
(
$layout
,
'@'
,
1
)
===
0
)
{
$file
=
Yii
::
getAlias
(
$layout
);
}
elseif
(
strncmp
(
$layout
,
'/'
,
1
)
===
0
)
{
$file
=
Yii
::
$app
->
getLayoutPath
()
.
DIRECTORY_SEPARATOR
.
$layout
;
$file
=
Yii
::
$app
->
getLayoutPath
()
.
DIRECTORY_SEPARATOR
.
substr
(
$layout
,
1
)
;
}
else
{
$file
=
$module
->
getLayoutPath
()
.
DIRECTORY_SEPARATOR
.
$layout
;
}
...
...
framework/console/controllers/MessageController.php
View file @
3713b369
...
...
@@ -15,8 +15,9 @@ use yii\helpers\FileHelper;
/**
* This command extracts messages to be translated from source files.
* The extracted messages are saved as PHP message source files
* under the specified directory.
* The extracted messages are saved either as PHP message source files
* or ".po" files under the specified directory. Format depends on `format`
* setting in config file.
*
* Usage:
* 1. Create a configuration file using the 'message/config' command:
...
...
@@ -81,6 +82,7 @@ class MessageController extends Controller
'overwrite'
=>
false
,
'removeUnused'
=>
false
,
'sort'
=>
false
,
'format'
=>
'php'
,
],
require
(
$configFile
));
if
(
!
isset
(
$config
[
'sourcePath'
],
$config
[
'messagePath'
],
$config
[
'languages'
]))
{
...
...
@@ -95,6 +97,9 @@ class MessageController extends Controller
if
(
empty
(
$config
[
'languages'
]))
{
throw
new
Exception
(
"Languages cannot be empty."
);
}
if
(
empty
(
$config
[
'format'
])
||
!
in_array
(
$config
[
'format'
],
[
'php'
,
'po'
]))
{
throw
new
Exception
(
'Format should be either "php" or "po".'
);
}
$files
=
FileHelper
::
findFiles
(
realpath
(
$config
[
'sourcePath'
]),
$config
);
...
...
@@ -109,13 +114,13 @@ class MessageController extends Controller
@
mkdir
(
$dir
);
}
foreach
(
$messages
as
$category
=>
$msgs
)
{
$file
=
str_replace
(
"
\\
"
,
'/'
,
"
$dir
/
$category
.
php"
);
$file
=
str_replace
(
"
\\
"
,
'/'
,
"
$dir
/
$category
.
"
.
$config
[
'format'
]
);
$path
=
dirname
(
$file
);
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
,
0755
,
true
);
}
$msgs
=
array_values
(
array_unique
(
$msgs
));
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
]);
$this
->
generateMessageFile
(
$msgs
,
$file
,
$config
[
'overwrite'
],
$config
[
'removeUnused'
],
$config
[
'sort'
]
,
$config
[
'format'
]
);
}
}
}
...
...
@@ -160,12 +165,21 @@ class MessageController extends Controller
* @param boolean $overwrite if existing file should be overwritten without backup
* @param boolean $removeUnused if obsolete translations should be removed
* @param boolean $sort if translations should be sorted
* @param string $format output format
*/
protected
function
generateMessageFile
(
$messages
,
$fileName
,
$overwrite
,
$removeUnused
,
$sort
)
protected
function
generateMessageFile
(
$messages
,
$fileName
,
$overwrite
,
$removeUnused
,
$sort
,
$format
)
{
echo
"Saving messages to
$fileName
..."
;
if
(
is_file
(
$fileName
))
{
$translated
=
require
(
$fileName
);
if
(
$format
===
'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
{
$translated
=
require
(
$fileName
);
}
sort
(
$messages
);
ksort
(
$translated
);
if
(
array_keys
(
$translated
)
==
$messages
)
{
...
...
@@ -204,17 +218,39 @@ class MessageController extends Controller
if
(
false
===
$overwrite
)
{
$fileName
.=
'.merged'
;
}
if
(
$format
===
'po'
){
$out_str
=
''
;
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
"
;
}
else
{
$merged
=
[];
foreach
(
$messages
as
$message
)
{
$merged
[
$message
]
=
''
;
if
(
$format
===
'po'
)
{
$merged
=
''
;
sort
(
$messages
);
foreach
(
$messages
as
$message
)
{
$merged
.=
"msgid
\"
$message
\"\n
"
;
$merged
.=
"msgstr
\"\"\n
"
;
$merged
.=
"
\n
"
;
}
}
else
{
$merged
=
[];
foreach
(
$messages
as
$message
)
{
$merged
[
$message
]
=
''
;
}
ksort
(
$merged
);
}
ksort
(
$merged
);
echo
"saved.
\n
"
;
}
$array
=
str_replace
(
"
\r
"
,
''
,
var_export
(
$merged
,
true
));
$content
=
<<<EOD
if
(
$format
===
'po'
)
{
$content
=
$merged
;
}
else
{
$array
=
str_replace
(
"
\r
"
,
''
,
var_export
(
$merged
,
true
));
$content
=
<<<EOD
<?php
/**
* Message translations.
...
...
@@ -236,6 +272,7 @@ class MessageController extends Controller
return $array;
EOD;
}
file_put_contents
(
$fileName
,
$content
);
}
}
framework/helpers/BaseHtml.php
View file @
3713b369
...
...
@@ -1161,10 +1161,14 @@ class BaseHtml
public
static
function
activeCheckbox
(
$model
,
$attribute
,
$options
=
[])
{
$name
=
isset
(
$options
[
'name'
])
?
$options
[
'name'
]
:
static
::
getInputName
(
$model
,
$attribute
);
$checked
=
static
::
getAttributeValue
(
$model
,
$attribute
);
$value
=
static
::
getAttributeValue
(
$model
,
$attribute
);
if
(
!
array_key_exists
(
'uncheck'
,
$options
))
{
$options
[
'uncheck'
]
=
'0'
;
}
$checked
=
(
$value
!=
$options
[
'uncheck'
]);
if
(
!
array_key_exists
(
'id'
,
$options
))
{
$options
[
'id'
]
=
static
::
getInputId
(
$model
,
$attribute
);
}
...
...
framework/messages/config.php
View file @
3713b369
...
...
@@ -42,4 +42,6 @@ return [
'.hgkeep'
,
'/messages'
,
],
// Generated file format. Can be either "php" or "po".
'format'
=>
'php'
,
];
framework/views/messageConfig.php
View file @
3713b369
...
...
@@ -6,7 +6,7 @@ return [
// string, required, root directory containing message translations.
'messagePath'
=>
__DIR__
.
DIRECTORY_SEPARATOR
.
'messages'
,
// array, required, list of language codes that the extracted messages
// should be translated to. For example, ['zh
_cn
', 'de'].
// should be translated to. For example, ['zh
-CN
', 'de'].
'languages'
=>
[
'de'
],
// string, the name of the function for translating messages.
// Defaults to 'Yii::t'. This is used as a mark to find the messages to be
...
...
@@ -42,4 +42,6 @@ return [
'.hgkeep'
,
'/messages'
,
],
// Generated file format. Can be either "php" or "po".
'format'
=>
'php'
,
];
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