Browse Source

Fixes #1654: Fixed the issue that a new message source object is generated for every new message being translated

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
5e8a48a60a
  1. 1
      framework/CHANGELOG.md
  2. 17
      framework/yii/i18n/I18N.php
  3. 2
      framework/yii/i18n/MessageSource.php

1
framework/CHANGELOG.md

@ -11,6 +11,7 @@ Yii Framework 2 Change Log
- Bug #1509: The SQL for creating Postgres RBAC tables is incorrect (qiangxue) - Bug #1509: The SQL for creating Postgres RBAC tables is incorrect (qiangxue)
- Bug #1545: It was not possible to execute db Query twice, params where missing (cebe) - Bug #1545: It was not possible to execute db Query twice, params where missing (cebe)
- Bug #1550: fixed the issue that JUI input widgets did not property input IDs. - Bug #1550: fixed the issue that JUI input widgets did not property input IDs.
- Bug #1654: Fixed the issue that a new message source object is generated for every new message being translated (qiangxue)
- Bug #1582: Error messages shown via client-side validation should not be double encoded (qiangxue) - Bug #1582: Error messages shown via client-side validation should not be double encoded (qiangxue)
- Bug #1591: StringValidator is accessing undefined property (qiangxue) - Bug #1591: StringValidator is accessing undefined property (qiangxue)
- Bug #1597: Added `enableAutoLogin` to basic and advanced application templates so "remember me" now works properly (samdark) - Bug #1597: Added `enableAutoLogin` to basic and advanced application templates so "remember me" now works properly (samdark)

17
framework/yii/i18n/I18N.php

@ -157,19 +157,24 @@ class I18N extends Component
{ {
if (isset($this->translations[$category])) { if (isset($this->translations[$category])) {
$source = $this->translations[$category]; $source = $this->translations[$category];
if ($source instanceof MessageSource) {
return $source;
} else {
return $this->translations[$category] = Yii::createObject($source);
}
} else { } else {
// try wildcard matching // try wildcard matching
foreach ($this->translations as $pattern => $config) { foreach ($this->translations as $pattern => $config) {
if ($pattern === '*' || substr($pattern, -1) === '*' && strpos($category, rtrim($pattern, '*')) === 0) { if ($pattern === '*' || substr($pattern, -1) === '*' && strpos($category, rtrim($pattern, '*')) === 0) {
$source = $config; if ($config instanceof MessageSource) {
break; return $config;
} else {
return $this->translations[$category] = $this->translations[$pattern] = Yii::createObject($config);
} }
} }
} }
if (isset($source)) {
return $source instanceof MessageSource ? $source : Yii::createObject($source);
} else {
throw new InvalidConfigException("Unable to locate message source for category '$category'.");
} }
throw new InvalidConfigException("Unable to locate message source for category '$category'.");
} }
} }

2
framework/yii/i18n/MessageSource.php

@ -105,7 +105,7 @@ class MessageSource extends Component
} }
if (isset($this->_messages[$key][$message]) && $this->_messages[$key][$message] !== '') { if (isset($this->_messages[$key][$message]) && $this->_messages[$key][$message] !== '') {
return $this->_messages[$key][$message]; return $this->_messages[$key][$message];
} elseif ($this->hasEventHandlers('missingTranslation')) { } elseif ($this->hasEventHandlers(self::EVENT_MISSING_TRANSLATION)) {
$event = new MissingTranslationEvent([ $event = new MissingTranslationEvent([
'category' => $category, 'category' => $category,
'message' => $message, 'message' => $message,

Loading…
Cancel
Save