Class yii\i18n\MessageSource
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
| $forceTranslation | boolean | 是否在源语言和目标语言相同时强制进行消息转换。 默认为 false,表示仅在源语言和目标语言不同时执行转换。 | yii\i18n\MessageSource |
| $sourceLanguage | string | 原始消息的语言。 如果没有设置,将使用 yii\base\Application::$sourceLanguage 的值。 | yii\i18n\MessageSource |
公共方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| __call() | Calls the named method which is not a class method. | yii\base\Component |
| __clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
| __construct() | Constructor. | yii\base\BaseObject |
| __get() | Returns the value of a component property. | yii\base\Component |
| __isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
| __set() | Sets the value of a component property. | yii\base\Component |
| __unset() | Sets a component property to be null. | yii\base\Component |
| attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
| attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
| behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
| canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
| canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
| className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
| detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
| detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
| getBehavior() | Returns the named behavior object. | yii\base\Component |
| getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
| hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
| hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
| hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
| init() | 初始化此组件。 | yii\i18n\MessageSource |
| off() | Detaches an existing event handler from this component. | yii\base\Component |
| on() | Attaches an event handler to an event. | yii\base\Component |
| translate() | 翻译消息到指定的语言。 | yii\i18n\MessageSource |
| trigger() | Triggers an event. | yii\base\Component |
受保护的方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| loadMessages() | 加载指定语言和类别的消息转换。
如果找不到特定区域代码的翻译,例如 en-US,
则会尝试更通用的 en。 |
yii\i18n\MessageSource |
| translateMessage() | 翻译指定的消息。 如果未找到该消息,将触发 missingTranslation 事件。 如果有事件处理程序,它可能会提供 fallback translation. | yii\i18n\MessageSource |
Events
| 事件 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| EVENT_MISSING_TRANSLATION | yii\i18n\MissingTranslationEvent | 当找不到一条消息翻译时触发的事件。 | yii\i18n\MessageSource |
属性详情
是否在源语言和目标语言相同时强制进行消息转换。 默认为 false,表示仅在源语言和目标语言不同时执行转换。
原始消息的语言。 如果没有设置,将使用 yii\base\Application::$sourceLanguage 的值。
方法详情
初始化此组件。
| public void init() |
加载指定语言和类别的消息转换。
如果找不到特定区域代码的翻译,例如 en-US,
则会尝试更通用的 en。
| protected array loadMessages($category, $language) | ||
| $category | string | 消息类别 |
| $language | string | 目标语言 |
| return | array | 加载的消息。 键是原始的消息,值是翻译的消息。 |
|---|---|---|
翻译消息到指定的语言。
请注意,除非 $forceTranslation 为 true, 否则如果目标语言与 source language 相同, 将不会翻译该消息。
如果未找到翻译,将触发 missingTranslation 事件。
| public string|boolean translate($category, $message, $language) | ||
| $category | string | 消息类别 |
| $message | string | 要翻译的信息 |
| $language | string | 目标语言 |
| return | string|boolean | 翻译好的消息,如果未找到或不需要翻译,则为 false |
|---|---|---|
翻译指定的消息。 如果未找到该消息,将触发 missingTranslation 事件。 如果有事件处理程序,它可能会提供 fallback translation.
如果没有提供消息翻译,则此方法将返回 false。
| protected string|boolean translateMessage($category, $message, $language) | ||
| $category | string | 消息所属的类别。 |
| $message | string | 要翻译的信息。 |
| $language | string | 目标语言。 |
| return | string|boolean | 已翻译的消息,如果未找到翻译,则为 false。 |
|---|---|---|
事件详情
当找不到一条消息翻译时触发的事件。