Код: Выделить всё
Platform::$app->language = 'ru-RU';
$source = Platform::$app->i18n->getMessageSource('platform');
$source->on(
MessageSource::EVENT_MISSING_TRANSLATION,
function ($event) {
var_dump($event);
}
);
Platform::t('platform', 'I am');
всегда создает новый обьект MessageSource, и событий соответственно привязанных нет
предлагаю сделать что то типа
Код: Выделить всё
diff --git a/yii/i18n/I18N.php b/yii/i18n/I18N.php
index c59a6d2..f9ca991 100644
--- a/yii/i18n/I18N.php
+++ b/yii/i18n/I18N.php
@@ -167,7 +167,8 @@ class I18N extends Component
}
}
if (isset($source)) {
- return $source instanceof MessageSource ? $source : Yii::createObject($source);
+ $this->translations[$category] = $source instanceof MessageSource ? $source : Yii::createObject($source);
+ return $this->translations[$category];
} else {
throw new InvalidConfigException("Unable to locate message source for category '$category'.");
}
diff --git a/yii/i18n/MessageSource.php b/yii/i18n/MessageSource.php
index 95f907d..07871bb 100644
--- a/yii/i18n/MessageSource.php
+++ b/yii/i18n/MessageSource.php
@@ -105,7 +105,7 @@ class MessageSource extends Component
}
if (isset($this->_messages[$key][$message]) && $this->_messages[$key][$message] !== '') {
return $this->_messages[$key][$message];
- } elseif ($this->hasEventHandlers('missingTranslation')) {
+ } elseif ($this->hasEventHandlers(self::EVENT_MISSING_TRANSLATION)) {
$event = new MissingTranslationEvent([
'category' => $category,
'message' => $message,