1 | <?php |
||
27 | class I18N extends Component |
||
28 | { |
||
29 | /** |
||
30 | * @var array list of [[MessageSource]] configurations or objects. The array keys are message |
||
31 | * category patterns, and the array values are the corresponding [[MessageSource]] objects or the configurations |
||
32 | * for creating the [[MessageSource]] objects. |
||
33 | * |
||
34 | * The message category patterns can contain the wildcard `*` at the end to match multiple categories with the same prefix. |
||
35 | * For example, `app/*` matches both `app/cat1` and `app/cat2`. |
||
36 | * |
||
37 | * The `*` category pattern will match all categories that do not match any other category patterns. |
||
38 | * |
||
39 | * This property may be modified on the fly by extensions who want to have their own message sources |
||
40 | * registered under their own namespaces. |
||
41 | * |
||
42 | * The category `yii` and `app` are always defined. The former refers to the messages used in the Yii core |
||
43 | * framework code, while the latter refers to the default message category for custom application code. |
||
44 | * By default, both of these categories use [[PhpMessageSource]] and the corresponding message files are |
||
45 | * stored under `@yii/messages` and `@app/messages`, respectively. |
||
46 | * |
||
47 | * You may override the configuration of both categories. |
||
48 | */ |
||
49 | public $translations; |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Initializes the component by configuring the default message categories. |
||
54 | */ |
||
55 | 535 | public function init() |
|
83 | |||
84 | /** |
||
85 | * Translates a message to the specified language. |
||
86 | * |
||
87 | * After translation the message will be formatted using [[MessageFormatter]] if it contains |
||
88 | * ICU message format and `$params` are not empty. |
||
89 | * |
||
90 | * @param string $category the message category. |
||
91 | * @param string $message the message to be translated. |
||
92 | * @param array $params the parameters that will be used to replace the corresponding placeholders in the message. |
||
93 | * @param string $language the language code (e.g. `en-US`, `en`). |
||
94 | * @return string the translated and formatted message. |
||
95 | */ |
||
96 | 533 | public function translate($category, $message, $params, $language) |
|
106 | |||
107 | /** |
||
108 | * Formats a message using [[MessageFormatter]]. |
||
109 | * |
||
110 | * @param string $message the message to be formatted. |
||
111 | * @param array $params the parameters that will be used to replace the corresponding placeholders in the message. |
||
112 | * @param string $language the language code (e.g. `en-US`, `en`). |
||
113 | * @return string the formatted message. |
||
114 | */ |
||
115 | 535 | public function format($message, $params, $language) |
|
142 | |||
143 | /** |
||
144 | * @var string|array|MessageFormatter |
||
145 | */ |
||
146 | private $_messageFormatter; |
||
147 | |||
148 | /** |
||
149 | * Returns the message formatter instance. |
||
150 | * @return MessageFormatter the message formatter to be used to format message via ICU message format. |
||
151 | */ |
||
152 | 123 | public function getMessageFormatter() |
|
162 | |||
163 | /** |
||
164 | * @param string|array|MessageFormatter $value the message formatter to be used to format message via ICU message format. |
||
165 | * Can be given as array or string configuration that will be given to [[Yii::createObject]] to create an instance |
||
166 | * or a [[MessageFormatter]] instance. |
||
167 | */ |
||
168 | public function setMessageFormatter($value) |
||
172 | |||
173 | /** |
||
174 | * Returns the message source for the given category. |
||
175 | * @param string $category the category name. |
||
176 | * @return MessageSource the message source for the given category. |
||
177 | * @throws InvalidConfigException if there is no message source available for the specified category. |
||
178 | */ |
||
179 | 533 | public function getMessageSource($category) |
|
212 | } |
||
213 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.