@@ -28,7 +28,7 @@ class I18nExtractCommand extends CakeI18nExtractCommand
2828 /**
2929 * App languages.
3030 *
31- * @var array
31+ * @var list<string>
3232 */
3333 protected array $ _languages = [];
3434
@@ -62,6 +62,15 @@ public static function defaultName(): string
6262 */
6363 public function execute (Arguments $ args , ConsoleIo $ io ): ?int
6464 {
65+ $ this ->_languages = $ this ->_getLanguages ($ args );
66+ if ($ this ->_languages === []) {
67+ $ io ->err (
68+ 'You must specify the languages list using the `I18n.languages` config or the `--languages` option. '
69+ );
70+
71+ return static ::CODE_ERROR ;
72+ }
73+
6574 $ plugin = '' ;
6675 if ($ args ->hasOption ('exclude ' )) {
6776 $ this ->_exclude = explode (', ' , (string )$ args ->getOption ('exclude ' ));
@@ -148,7 +157,6 @@ protected function _extract(Arguments $args, ConsoleIo $io): void
148157 $ io ->hr ();
149158 $ this ->_extractTokens ($ args , $ io );
150159
151- $ this ->_getLanguages ($ args );
152160 $ this ->_saveMessages ($ args , $ io );
153161
154162 $ this ->_paths = $ this ->_files = $ this ->_storage = [];
@@ -166,30 +174,31 @@ protected function _extract(Arguments $args, ConsoleIo $io): void
166174 * Get app languages.
167175 *
168176 * @param \Cake\Console\Arguments $args The Arguments instance
169- * @return void
177+ * @return list<string>
170178 */
171- protected function _getLanguages (Arguments $ args ): void
179+ protected function _getLanguages (Arguments $ args ): array
172180 {
173181 $ langs = (string )$ args ->getOption ('languages ' );
174182 if ($ langs ) {
175- $ this ->_languages = explode (', ' , $ langs );
176-
177- return ;
183+ return explode (', ' , $ langs );
178184 }
179185
180- $ langs = Configure::read ('I18n.languages ' );
181- if (empty ( $ langs) ) {
182- return ;
186+ $ langs = Configure::read ('I18n.languages ' , [] );
187+ if ($ langs === [] ) {
188+ return [] ;
183189 }
184190
191+ $ return = [];
185192 $ langs = Hash::normalize ($ langs );
186193 foreach ($ langs as $ key => $ value ) {
187194 if (isset ($ value ['locale ' ])) {
188- $ this -> _languages [] = $ value ['locale ' ];
195+ $ return [] = $ value ['locale ' ];
189196 } else {
190- $ this -> _languages [] = $ key ;
197+ $ return [] = $ key ;
191198 }
192199 }
200+
201+ return $ return ;
193202 }
194203
195204 /**
0 commit comments