Commit 40b3c2e8 by Alexander Makarov

Fixes #2209: When I18N message translation is missing source language is now used for formatting

parent 83a459cc
......@@ -41,6 +41,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)
......
......@@ -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);
}
}
/**
......
......@@ -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 $message;
return false;
}
}
......@@ -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,7 @@ class MessageSource extends Component
'language' => $language,
]);
$this->trigger(self::EVENT_MISSING_TRANSLATION, $event);
return $this->_messages[$key] = $event->message;
} else {
return $message;
}
return false;
}
}
......@@ -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>';
}
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment