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
89fe3549
Commit
89fe3549
authored
Feb 08, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2285 from yiisoft/missing-translation-formatting
When translation is missing source language should be used for formatting
parents
928df009
0f59ba2d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
15 deletions
+35
-15
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
I18N.php
framework/i18n/I18N.php
+7
-2
MessageSource.php
framework/i18n/MessageSource.php
+5
-6
BaseListView.php
framework/widgets/BaseListView.php
+13
-7
I18NTest.php
tests/unit/framework/i18n/I18NTest.php
+9
-0
No files found.
framework/CHANGELOG.md
View file @
89fe3549
...
...
@@ -40,6 +40,7 @@ Yii Framework 2 Change Log
-
Bug #2084: AssetController adjusting CSS URLs declared at same line fixed (klimov-paul)
-
Bug #2091:
`QueryBuilder::buildInCondition()`
fails to handle array not starting with index 0 (qiangxue)
-
Bug #2160: SphinxQL does not support OFFSET (qiangxue, romeo7)
-
Bug #2209: When I18N message translation is missing source language is now used for formatting (samdark)
-
Bug #2212:
`yii\gridview\DataColumn`
generates incorrect labels when used with nosql DB and there is no data (qiangxue)
-
Bug #2298: Fixed the bug that Gii controller generator did not allow digit in the controller ID (qiangxue)
-
Bug #2303: Fixed the bug that
`yii\base\Theme::pathMap`
did not support dynamic update with path aliases (qiangxue)
...
...
framework/i18n/I18N.php
View file @
89fe3549
...
...
@@ -85,8 +85,13 @@ class I18N extends Component
*/
public
function
translate
(
$category
,
$message
,
$params
,
$language
)
{
$message
=
$this
->
getMessageSource
(
$category
)
->
translate
(
$category
,
$message
,
$language
);
return
$this
->
format
(
$message
,
$params
,
$language
);
$messageSource
=
$this
->
getMessageSource
(
$category
);
$translation
=
$messageSource
->
translate
(
$category
,
$message
,
$language
);
if
(
$translation
===
false
)
{
return
$this
->
format
(
$message
,
$params
,
$messageSource
->
sourceLanguage
);
}
else
{
return
$this
->
format
(
$translation
,
$params
,
$language
);
}
}
/**
...
...
framework/i18n/MessageSource.php
View file @
89fe3549
...
...
@@ -78,14 +78,14 @@ class MessageSource extends Component
* @param string $category the message category
* @param string $message the message to be translated
* @param string $language the target language
* @return string
the translated message (or the original message if translation is not needed)
* @return string
|boolean the translated message or false if translation wasn't found or isn't required
*/
public
function
translate
(
$category
,
$message
,
$language
)
{
if
(
$this
->
forceTranslation
||
$language
!==
$this
->
sourceLanguage
)
{
return
$this
->
translateMessage
(
$category
,
$message
,
$language
);
}
else
{
return
$messag
e
;
return
fals
e
;
}
}
...
...
@@ -96,7 +96,7 @@ class MessageSource extends Component
* @param string $category the category that the message belongs to
* @param string $message the message to be translated
* @param string $language the target language
* @return string
the translated message
* @return string
|boolean the translated message or false if translation wasn't found
*/
protected
function
translateMessage
(
$category
,
$message
,
$language
)
{
...
...
@@ -113,9 +113,8 @@ class MessageSource extends Component
'language'
=>
$language
,
]);
$this
->
trigger
(
self
::
EVENT_MISSING_TRANSLATION
,
$event
);
return
$this
->
_messages
[
$key
]
=
$event
->
message
;
}
else
{
return
$message
;
$this
->
_messages
[
$key
]
=
$event
->
message
;
}
return
false
;
}
}
framework/widgets/BaseListView.php
View file @
89fe3549
...
...
@@ -160,25 +160,31 @@ abstract class BaseListView extends Widget
$page
=
$pagination
->
getPage
()
+
1
;
$pageCount
=
$pagination
->
pageCount
;
if
((
$summaryContent
=
$this
->
summary
)
===
null
)
{
$summaryContent
=
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.'
)
return
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.'
,
[
'begin'
=>
$begin
,
'end'
=>
$end
,
'count'
=>
$count
,
'totalCount'
=>
$totalCount
,
'page'
=>
$page
,
'pageCount'
=>
$pageCount
,
])
.
'</div>'
;
}
}
else
{
$begin
=
$page
=
$pageCount
=
1
;
$end
=
$totalCount
=
$count
;
if
((
$summaryContent
=
$this
->
summary
)
===
null
)
{
$summaryContent
=
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.'
)
.
'</div>'
;
}
}
return
Yii
::
$app
->
getI18n
()
->
format
(
$summaryContent
,
[
return
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.'
,
[
'begin'
=>
$begin
,
'end'
=>
$end
,
'count'
=>
$count
,
'totalCount'
=>
$totalCount
,
'page'
=>
$page
,
'pageCount'
=>
$pageCount
,
],
Yii
::
$app
->
language
);
])
.
'</div>'
;
}
}
}
/**
...
...
tests/unit/framework/i18n/I18NTest.php
View file @
89fe3549
...
...
@@ -89,6 +89,15 @@ class I18NTest extends TestCase
$model
=
new
ParamModel
();
$this
->
assertEquals
(
'His name is peer and he is 5 years old.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$model
,
'en-US'
));
}
/**
* When translation is missing source language should be used for formatting.
* https://github.com/yiisoft/yii2/issues/2209
*/
public
function
testMissingTranslationFormatting
()
{
$this
->
assertEquals
(
'1 item'
,
$this
->
i18n
->
translate
(
'test'
,
'{0, number} {0, plural, one{item} other{items}}'
,
1
,
'hu'
));
}
}
class
ParamModel
extends
Model
...
...
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