1 | <?php |
||
29 | class GettextMessageSource extends MessageSource |
||
30 | { |
||
31 | const MO_FILE_EXT = '.mo'; |
||
32 | const PO_FILE_EXT = '.po'; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | public $basePath = '@app/messages'; |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | public $catalog = 'messages'; |
||
42 | /** |
||
43 | * @var boolean |
||
44 | */ |
||
45 | public $useMoFile = true; |
||
46 | /** |
||
47 | * @var boolean |
||
48 | */ |
||
49 | public $useBigEndian = false; |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Loads the message translation for the specified $language and $category. |
||
54 | * If translation for specific locale code such as `en-US` isn't found it |
||
55 | * tries more generic `en`. When both are present, the `en-US` messages will be merged |
||
56 | * over `en`. See [[loadFallbackMessages]] for details. |
||
57 | * If the $language is less specific than [[sourceLanguage]], the method will try to |
||
58 | * load the messages for [[sourceLanguage]]. For example: [[sourceLanguage]] is `en-GB`, |
||
59 | * $language is `en`. The method will load the messages for `en` and merge them over `en-GB`. |
||
60 | * |
||
61 | * @param string $category the message category |
||
62 | * @param string $language the target language |
||
63 | * @return array the loaded messages. The keys are original messages, and the values are translated messages. |
||
64 | * @see loadFallbackMessages |
||
65 | * @see sourceLanguage |
||
66 | */ |
||
67 | protected function loadMessages($category, $language) |
||
87 | |||
88 | /** |
||
89 | * The method is normally called by [[loadMessages]] to load the fallback messages for the language. |
||
90 | * Method tries to load the $category messages for the $fallbackLanguage and adds them to the $messages array. |
||
91 | * |
||
92 | * @param string $category the message category |
||
93 | * @param string $fallbackLanguage the target fallback language |
||
94 | * @param array $messages the array of previously loaded translation messages. |
||
95 | * The keys are original messages, and the values are the translated messages. |
||
96 | * @param string $originalMessageFile the path to the file with messages. Used to log an error message |
||
97 | * in case when no translations were found. |
||
98 | * @return array the loaded messages. The keys are original messages, and the values are the translated messages. |
||
99 | * @since 2.0.7 |
||
100 | */ |
||
101 | protected function loadFallbackMessages($category, $fallbackLanguage, $messages, $originalMessageFile) |
||
121 | |||
122 | /** |
||
123 | * Returns message file path for the specified language and category. |
||
124 | * |
||
125 | * @param string $language the target language |
||
126 | * @return string path to message file |
||
127 | */ |
||
128 | protected function getMessageFilePath($language) |
||
139 | |||
140 | /** |
||
141 | * Loads the message translation for the specified language and category or returns null if file doesn't exist. |
||
142 | * |
||
143 | * @param string $messageFile path to message file |
||
144 | * @param string $category the message category |
||
145 | * @return array|null array of messages or null if file not found |
||
146 | */ |
||
147 | protected function loadMessagesFromFile($messageFile, $category) |
||
165 | } |
||
166 |
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.