1 | <?php |
||
34 | class PhpMessageSource extends MessageSource |
||
35 | { |
||
36 | /** |
||
37 | * @var string the base path for all translated messages. Defaults to '@app/messages'. |
||
38 | */ |
||
39 | public $basePath = '@app/messages'; |
||
40 | /** |
||
41 | * @var array mapping between message categories and the corresponding message file paths. |
||
42 | * The file paths are relative to [[basePath]]. For example, |
||
43 | * |
||
44 | * ```php |
||
45 | * [ |
||
46 | * 'core' => 'core.php', |
||
47 | * 'ext' => 'extensions.php', |
||
48 | * ] |
||
49 | * ``` |
||
50 | */ |
||
51 | public $fileMap; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Loads the message translation for the specified $language and $category. |
||
56 | * If translation for specific locale code such as `en-US` isn't found it |
||
57 | * tries more generic `en`. When both are present, the `en-US` messages will be merged |
||
58 | * over `en`. See [[loadFallbackMessages]] for details. |
||
59 | * If the $language is less specific than [[sourceLanguage]], the method will try to |
||
60 | * load the messages for [[sourceLanguage]]. For example: [[sourceLanguage]] is `en-GB`, |
||
61 | * $language is `en`. The method will load the messages for `en` and merge them over `en-GB`. |
||
62 | * |
||
63 | * @param string $category the message category |
||
64 | 154 | * @param string $language the target language |
|
65 | * @return array the loaded messages. The keys are original messages, and the values are the translated messages. |
||
66 | 154 | * @see loadFallbackMessages |
|
67 | 154 | * @see sourceLanguage |
|
68 | */ |
||
69 | 154 | protected function loadMessages($category, $language) |
|
89 | |||
90 | /** |
||
91 | 11 | * The method is normally called by [[loadMessages]] to load the fallback messages for the language. |
|
92 | * Method tries to load the $category messages for the $fallbackLanguage and adds them to the $messages array. |
||
93 | * |
||
94 | * @param string $category the message category |
||
95 | * @param string $fallbackLanguage the target fallback language |
||
96 | * @param array $messages the array of previously loaded translation messages. |
||
97 | * The keys are original messages, and the values are the translated messages. |
||
98 | * @param string $originalMessageFile the path to the file with messages. Used to log an error message |
||
99 | * in case when no translations were found. |
||
100 | * @return array the loaded messages. The keys are original messages, and the values are the translated messages. |
||
101 | 154 | * @since 2.0.7 |
|
102 | */ |
||
103 | 154 | protected function loadFallbackMessages($category, $fallbackLanguage, $messages, $originalMessageFile) |
|
123 | 152 | ||
124 | /** |
||
125 | * Returns message file path for the specified language and category. |
||
126 | * |
||
127 | 152 | * @param string $category the message category |
|
128 | * @param string $language the target language |
||
129 | 150 | * @return string path to message file |
|
130 | */ |
||
131 | protected function getMessageFilePath($category, $language) |
||
142 | |||
143 | /** |
||
144 | * Loads the message translation for the specified language and category or returns null if file doesn't exist. |
||
145 | * |
||
146 | * @param string $messageFile path to message file |
||
147 | * @return array|null array of messages or null if file not found |
||
148 | */ |
||
149 | protected function loadMessagesFromFile($messageFile) |
||
162 | } |
||
163 |
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.