|
|
@ -29,9 +29,13 @@ class I18N extends Component |
|
|
|
{ |
|
|
|
{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var array list of [[MessageSource]] configurations or objects. The array keys are message |
|
|
|
* @var array list of [[MessageSource]] configurations or objects. The array keys are message |
|
|
|
* categories, and the array values are the corresponding [[MessageSource]] objects or the configurations |
|
|
|
* category patterns, and the array values are the corresponding [[MessageSource]] objects or the configurations |
|
|
|
* for creating the [[MessageSource]] objects. The message categories can contain the wildcard '*' at the end |
|
|
|
* for creating the [[MessageSource]] objects. |
|
|
|
* to match multiple categories with the same prefix. For example, 'app\*' matches both 'app\cat1' and 'app\cat2'. |
|
|
|
* |
|
|
|
|
|
|
|
* The message category patterns can contain the wildcard '*' at the end to match multiple categories with the same prefix. |
|
|
|
|
|
|
|
* For example, 'app\*' matches both 'app\cat1' and 'app\cat2'. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* The '*' category pattern will match all categories that do not match any other category patterns. |
|
|
|
* |
|
|
|
* |
|
|
|
* This property may be modified on the fly by extensions who want to have their own message sources |
|
|
|
* This property may be modified on the fly by extensions who want to have their own message sources |
|
|
|
* registered under their own namespaces. |
|
|
|
* registered under their own namespaces. |
|
|
@ -169,14 +173,23 @@ class I18N extends Component |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// try wildcard matching |
|
|
|
// try wildcard matching |
|
|
|
foreach ($this->translations as $pattern => $config) { |
|
|
|
foreach ($this->translations as $pattern => $source) { |
|
|
|
if ($pattern === '*' || substr($pattern, -1) === '*' && strpos($category, rtrim($pattern, '*')) === 0) { |
|
|
|
if (strpos($pattern, '*') > 0 && strpos($category, rtrim($pattern, '*')) === 0) { |
|
|
|
if ($config instanceof MessageSource) { |
|
|
|
if ($source instanceof MessageSource) { |
|
|
|
return $config; |
|
|
|
return $source; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return $this->translations[$category] = $this->translations[$pattern] = Yii::createObject($config); |
|
|
|
return $this->translations[$category] = $this->translations[$pattern] = Yii::createObject($source); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// match '*' in the last |
|
|
|
|
|
|
|
if (isset($this->translations['*'])) { |
|
|
|
|
|
|
|
$source = $this->translations['*']; |
|
|
|
|
|
|
|
if ($source instanceof MessageSource) { |
|
|
|
|
|
|
|
return $source; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return $this->translations[$category] = $this->translations['*'] = Yii::createObject($source); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|