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
d2e5f2c5
Commit
d2e5f2c5
authored
Nov 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1234: use dash instead of underscore to separate language and country in locale id.
parent
53457a0a
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
43 additions
and
46 deletions
+43
-46
main.php
apps/advanced/backend/views/layouts/main.php
+1
-1
main.php
apps/advanced/frontend/views/layouts/main.php
+1
-1
main.php
apps/basic/views/layouts/main.php
+1
-1
i18n.md
docs/guide/i18n.md
+1
-1
view.md
docs/guide/view.md
+1
-1
DbPanel.php
extensions/debug/panels/DbPanel.php
+1
-1
BaseYii.php
framework/yii/BaseYii.php
+1
-1
Application.php
framework/yii/base/Application.php
+2
-2
I18N.php
framework/yii/i18n/I18N.php
+4
-4
MissingTranslationEvent.php
framework/yii/i18n/MissingTranslationEvent.php
+1
-1
config.php
framework/yii/messages/config.php
+1
-1
Request.php
framework/yii/web/Request.php
+4
-4
test.php
tests/unit/data/i18n/messages/de-DE/test.php
+0
-0
test.php
tests/unit/data/i18n/messages/en-US/test.php
+0
-0
FallbackMessageFormatterTest.php
tests/unit/framework/i18n/FallbackMessageFormatterTest.php
+4
-5
FormatterTest.php
tests/unit/framework/i18n/FormatterTest.php
+1
-1
I18NTest.php
tests/unit/framework/i18n/I18NTest.php
+12
-13
MessageFormatterTest.php
tests/unit/framework/i18n/MessageFormatterTest.php
+7
-8
No files found.
apps/advanced/backend/views/layouts/main.php
View file @
d2e5f2c5
...
...
@@ -13,7 +13,7 @@ AppAsset::register($this);
?>
<?php
$this
->
beginPage
();
?>
<!DOCTYPE html>
<html
lang=
"
en
"
>
<html
lang=
"
<?=
Yii
::
$app
->
language
?>
"
>
<head>
<meta
charset=
"
<?=
Yii
::
$app
->
charset
?>
"
/>
<title>
<?=
Html
::
encode
(
$this
->
title
)
?>
</title>
...
...
apps/advanced/frontend/views/layouts/main.php
View file @
d2e5f2c5
...
...
@@ -14,7 +14,7 @@ AppAsset::register($this);
?>
<?php
$this
->
beginPage
();
?>
<!DOCTYPE html>
<html
lang=
"
en
"
>
<html
lang=
"
<?=
Yii
::
$app
->
language
?>
"
>
<head>
<meta
charset=
"
<?=
Yii
::
$app
->
charset
?>
"
/>
<title>
<?=
Html
::
encode
(
$this
->
title
)
?>
</title>
...
...
apps/basic/views/layouts/main.php
View file @
d2e5f2c5
...
...
@@ -13,7 +13,7 @@ AppAsset::register($this);
?>
<?php
$this
->
beginPage
();
?>
<!DOCTYPE html>
<html
lang=
"
en
"
>
<html
lang=
"
<?=
Yii
::
$app
->
language
?>
"
>
<head>
<meta
charset=
"
<?=
Yii
::
$app
->
charset
?>
"
/>
<title>
<?=
Html
::
encode
(
$this
->
title
)
?>
</title>
...
...
docs/guide/i18n.md
View file @
d2e5f2c5
...
...
@@ -57,7 +57,7 @@ Yii tries to load approprite translation from one of the message sources defined
'app*'
=>
[
'class'
=>
'yii\i18n\PhpMessageSource'
,
//'basePath' => '@app/messages',
//'sourceLanguage' => 'en
_
US',
//'sourceLanguage' => 'en
-
US',
'fileMap'
=>
[
'app'
=>
'app.php'
,
'app/error'
=>
'error.php'
,
...
...
docs/guide/view.md
View file @
d2e5f2c5
...
...
@@ -256,7 +256,7 @@ use yii\helpers\Html;
?>
<?php
$this
->
beginPage
();
?>
<!DOCTYPE html>
<html
lang=
"
<?=
Yii
::
$app
->
charset
?>
"
>
<html
lang=
"
<?=
Yii
::
$app
->
language
?>
"
>
<head>
<meta
charset=
"
<?=
Yii
::
$app
->
charset
?>
"
/>
<title>
<?=
Html
::
encode
(
$this
->
title
)
?>
</title>
...
...
extensions/debug/panels/DbPanel.php
View file @
d2e5f2c5
...
...
@@ -48,7 +48,7 @@ EOD;
public
function
getDetail
()
{
$timings
=
$this
->
calculateTimings
();
ArrayHelper
::
multisort
(
$timings
,
3
,
true
);
ArrayHelper
::
multisort
(
$timings
,
3
,
SORT_DESC
);
$rows
=
[];
foreach
(
$timings
as
$timing
)
{
$duration
=
sprintf
(
'%.1f ms'
,
$timing
[
3
]
*
1000
);
...
...
framework/yii/BaseYii.php
View file @
d2e5f2c5
...
...
@@ -498,7 +498,7 @@ class BaseYii
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en
_
US`, `en`). If this is null, the current
* @param string $language the language code (e.g. `en
-
US`, `en`). If this is null, the current
* [[\yii\base\Application::language|application language]] will be used.
* @return string the translated message.
*/
...
...
framework/yii/base/Application.php
View file @
d2e5f2c5
...
...
@@ -79,13 +79,13 @@ abstract class Application extends Module
* @var string the language that is meant to be used for end users.
* @see sourceLanguage
*/
public
$language
=
'en
_
US'
;
public
$language
=
'en
-
US'
;
/**
* @var string the language that the application is written in. This mainly refers to
* the language that the messages and view files are written in.
* @see language
*/
public
$sourceLanguage
=
'en
_
US'
;
public
$sourceLanguage
=
'en
-
US'
;
/**
* @var Controller the currently active controller instance
*/
...
...
framework/yii/i18n/I18N.php
View file @
d2e5f2c5
...
...
@@ -53,14 +53,14 @@ class I18N extends Component
if
(
!
isset
(
$this
->
translations
[
'yii'
]))
{
$this
->
translations
[
'yii'
]
=
[
'class'
=>
'yii\i18n\PhpMessageSource'
,
'sourceLanguage'
=>
'en
_
US'
,
'sourceLanguage'
=>
'en
-
US'
,
'basePath'
=>
'@yii/messages'
,
];
}
if
(
!
isset
(
$this
->
translations
[
'app'
]))
{
$this
->
translations
[
'app'
]
=
[
'class'
=>
'yii\i18n\PhpMessageSource'
,
'sourceLanguage'
=>
'en
_
US'
,
'sourceLanguage'
=>
'en
-
US'
,
'basePath'
=>
'@app/messages'
,
];
}
...
...
@@ -75,7 +75,7 @@ class I18N extends Component
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en
_
US`, `en`).
* @param string $language the language code (e.g. `en
-
US`, `en`).
* @return string the translated and formatted message.
*/
public
function
translate
(
$category
,
$message
,
$params
,
$language
)
...
...
@@ -89,7 +89,7 @@ class I18N extends Component
*
* @param string $message the message to be formatted.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en
_
US`, `en`).
* @param string $language the language code (e.g. `en
-
US`, `en`).
* @return string the formatted message.
*/
public
function
format
(
$message
,
$params
,
$language
)
...
...
framework/yii/i18n/MissingTranslationEvent.php
View file @
d2e5f2c5
...
...
@@ -27,7 +27,7 @@ class MissingTranslationEvent extends Event
*/
public
$category
;
/**
* @var string the language ID (e.g. en
_
US) that the message is to be translated to
* @var string the language ID (e.g. en
-
US) that the message is to be translated to
*/
public
$language
;
}
framework/yii/messages/config.php
View file @
d2e5f2c5
...
...
@@ -6,7 +6,7 @@ return [
// string, required, root directory containing message translations.
'messagePath'
=>
__DIR__
,
// 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
...
...
framework/yii/web/Request.php
View file @
d2e5f2c5
...
...
@@ -908,11 +908,11 @@ class Request extends \yii\base\Request
return
isset
(
$acceptedLanguages
[
0
])
?
$acceptedLanguages
[
0
]
:
null
;
}
foreach
(
$acceptedLanguages
as
$acceptedLanguage
)
{
$acceptedLanguage
=
str_replace
(
'
-'
,
'_
'
,
strtolower
(
$acceptedLanguage
));
$acceptedLanguage
=
str_replace
(
'
_'
,
'-
'
,
strtolower
(
$acceptedLanguage
));
foreach
(
$languages
as
$language
)
{
$language
=
str_replace
(
'
-'
,
'_
'
,
strtolower
(
$language
));
// en
_us==en_us, en==en_us, en_
us==en
if
(
$language
===
$acceptedLanguage
||
strpos
(
$acceptedLanguage
,
$language
.
'
_'
)
===
0
||
strpos
(
$language
,
$acceptedLanguage
.
'_
'
)
===
0
)
{
$language
=
str_replace
(
'
_'
,
'-
'
,
strtolower
(
$language
));
// en
-us==en-us, en==en-us, en-
us==en
if
(
$language
===
$acceptedLanguage
||
strpos
(
$acceptedLanguage
,
$language
.
'
-'
)
===
0
||
strpos
(
$language
,
$acceptedLanguage
.
'-
'
)
===
0
)
{
return
$language
;
}
}
...
...
tests/unit/data/i18n/messages/de
_
DE/test.php
→
tests/unit/data/i18n/messages/de
-
DE/test.php
View file @
d2e5f2c5
File moved
tests/unit/data/i18n/messages/en
_
US/test.php
→
tests/unit/data/i18n/messages/en
-
US/test.php
View file @
d2e5f2c5
File moved
tests/unit/framework/i18n/FallbackMessageFormatterTest.php
View file @
d2e5f2c5
...
...
@@ -136,7 +136,7 @@ _MSG_
public
function
testNamedArguments
(
$pattern
,
$expected
,
$args
)
{
$formatter
=
new
FallbackMessageFormatter
();
$result
=
$formatter
->
fallbackFormat
(
$pattern
,
$args
,
'en
_
US'
);
$result
=
$formatter
->
fallbackFormat
(
$pattern
,
$args
,
'en
-
US'
);
$this
->
assertEquals
(
$expected
,
$result
,
$formatter
->
getErrorMessage
());
}
...
...
@@ -147,7 +147,7 @@ _MSG_
$formatter
=
new
FallbackMessageFormatter
();
$result
=
$formatter
->
fallbackFormat
(
'{'
.
self
::
SUBJECT
.
'} is {'
.
self
::
N
.
'}'
,
[
self
::
N
=>
self
::
N_VALUE
,
],
'en
_
US'
);
],
'en
-
US'
);
$this
->
assertEquals
(
$expected
,
$result
);
}
...
...
@@ -157,7 +157,7 @@ _MSG_
$pattern
=
'{'
.
self
::
SUBJECT
.
'} is '
.
self
::
N
;
$formatter
=
new
FallbackMessageFormatter
();
$result
=
$formatter
->
fallbackFormat
(
$pattern
,
[],
'en
_
US'
);
$result
=
$formatter
->
fallbackFormat
(
$pattern
,
[],
'en
-
US'
);
$this
->
assertEquals
(
$pattern
,
$result
,
$formatter
->
getErrorMessage
());
}
}
...
...
@@ -168,4 +168,4 @@ class FallbackMessageFormatter extends MessageFormatter
{
return
parent
::
fallbackFormat
(
$pattern
,
$args
,
$locale
);
}
}
\ No newline at end of file
}
tests/unit/framework/i18n/FormatterTest.php
View file @
d2e5f2c5
...
...
@@ -29,7 +29,7 @@ class FormatterTest extends TestCase
$this
->
markTestSkipped
(
'intl extension is required.'
);
}
$this
->
mockApplication
();
$this
->
formatter
=
new
Formatter
([
'locale'
=>
'en
_
US'
]);
$this
->
formatter
=
new
Formatter
([
'locale'
=>
'en
-
US'
]);
}
protected
function
tearDown
()
...
...
tests/unit/framework/i18n/I18NTest.php
View file @
d2e5f2c5
...
...
@@ -40,16 +40,16 @@ class I18NTest extends TestCase
public
function
testTranslate
()
{
$msg
=
'The dog runs fast.'
;
$this
->
assertEquals
(
'The dog runs fast.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
[],
'en
_
US'
));
$this
->
assertEquals
(
'Der Hund rennt schnell.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
[],
'de
_
DE'
));
$this
->
assertEquals
(
'The dog runs fast.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
[],
'en
-
US'
));
$this
->
assertEquals
(
'Der Hund rennt schnell.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
[],
'de
-
DE'
));
}
public
function
testTranslateParams
()
{
$msg
=
'His speed is about {n} km/h.'
;
$params
=
[
'n'
=>
42
];
$this
->
assertEquals
(
'His speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'en
_
US'
));
$this
->
assertEquals
(
'Seine Geschwindigkeit beträgt 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'de
_
DE'
));
$this
->
assertEquals
(
'His speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'en
-
US'
));
$this
->
assertEquals
(
'Seine Geschwindigkeit beträgt 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'de
-
DE'
));
}
public
function
testTranslateParams2
()
...
...
@@ -62,22 +62,22 @@ class I18NTest extends TestCase
'n'
=>
42
,
'name'
=>
'DA VINCI'
,
// http://petrix.com/dognames/d.html
];
$this
->
assertEquals
(
'His name is DA VINCI and his speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'en
_
US'
));
$this
->
assertEquals
(
'Er heißt DA VINCI und ist 42 km/h schnell.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'de
_
DE'
));
$this
->
assertEquals
(
'His name is DA VINCI and his speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'en
-
US'
));
$this
->
assertEquals
(
'Er heißt DA VINCI und ist 42 km/h schnell.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'de
-
DE'
));
}
public
function
testSpecialParams
()
{
$msg
=
'His speed is about {0} km/h.'
;
$this
->
assertEquals
(
'His speed is about 0 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
0
,
'en
_
US'
));
$this
->
assertEquals
(
'His speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
42
,
'en
_
US'
));
$this
->
assertEquals
(
'His speed is about {0} km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
null
,
'en
_
US'
));
$this
->
assertEquals
(
'His speed is about {0} km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
[],
'en
_
US'
));
$this
->
assertEquals
(
'His speed is about 0 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
0
,
'en
-
US'
));
$this
->
assertEquals
(
'His speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
42
,
'en
-
US'
));
$this
->
assertEquals
(
'His speed is about {0} km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
null
,
'en
-
US'
));
$this
->
assertEquals
(
'His speed is about {0} km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
[],
'en
-
US'
));
$msg
=
'His name is {name} and he is {age} years old.'
;
$model
=
new
ParamModel
();
$this
->
assertEquals
(
'His name is peer and he is 5 years old.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$model
,
'en
_
US'
));
$this
->
assertEquals
(
'His name is peer and he is 5 years old.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$model
,
'en
-
US'
));
}
}
...
...
@@ -85,4 +85,4 @@ class ParamModel extends Model
{
public
$name
=
'peer'
;
public
$age
=
5
;
}
\ No newline at end of file
}
tests/unit/framework/i18n/MessageFormatterTest.php
View file @
d2e5f2c5
...
...
@@ -250,7 +250,7 @@ _MSG_
1
=>
123
,
2
=>
37.073
],
'en
_
US'
'en
-
US'
],
[
...
...
@@ -272,7 +272,7 @@ _MSG_
'trees'
=>
123
,
'monkeysPerTree'
=>
37.073
],
'en
_
US'
'en
-
US'
],
[
...
...
@@ -297,14 +297,14 @@ _MSG_
$this
->
markTestSkipped
(
$skipMessage
);
}
$formatter
=
new
MessageFormatter
();
$result
=
$formatter
->
format
(
$pattern
,
$args
,
'en
_
US'
);
$result
=
$formatter
->
format
(
$pattern
,
$args
,
'en
-
US'
);
$this
->
assertEquals
(
$expected
,
$result
,
$formatter
->
getErrorMessage
());
}
/**
* @dataProvider parsePatterns
*/
public
function
testParseNamedArguments
(
$pattern
,
$expected
,
$args
,
$locale
=
'en
_
US'
)
public
function
testParseNamedArguments
(
$pattern
,
$expected
,
$args
,
$locale
=
'en
-
US'
)
{
if
(
!
extension_loaded
(
"intl"
))
{
$this
->
markTestSkipped
(
"intl not installed. Skipping."
);
...
...
@@ -322,7 +322,7 @@ _MSG_
$formatter
=
new
MessageFormatter
();
$result
=
$formatter
->
format
(
'{'
.
self
::
SUBJECT
.
'} is {'
.
self
::
N
.
', number}'
,
[
self
::
N
=>
self
::
N_VALUE
,
],
'en
_
US'
);
],
'en
-
US'
);
$this
->
assertEquals
(
$expected
,
$result
,
$formatter
->
getErrorMessage
());
}
...
...
@@ -331,7 +331,7 @@ _MSG_
{
$pattern
=
'{'
.
self
::
SUBJECT
.
'} is '
.
self
::
N
;
$formatter
=
new
MessageFormatter
();
$result
=
$formatter
->
format
(
$pattern
,
[],
'en
_
US'
);
$result
=
$formatter
->
format
(
$pattern
,
[],
'en
-
US'
);
$this
->
assertEquals
(
$pattern
,
$result
,
$formatter
->
getErrorMessage
());
}
}
\ No newline at end of file
}
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