Skip to content

Commit a2a23a6

Browse files
committed
fix: lang() causes error on CLI
Call to undefined method CodeIgniter\HTTP\CLIRequest::getLocale()
1 parent 765c6cd commit a2a23a6

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

system/Config/Services.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
use Config\Toolbar as ToolbarConfig;
7676
use Config\Validation as ValidationConfig;
7777
use Config\View as ViewConfig;
78+
use Locale;
7879

7980
/**
8081
* Services Configuration file.
@@ -363,8 +364,14 @@ public static function language(?string $locale = null, bool $getShared = true)
363364
return static::getSharedInstance('language', $locale)->setLocale($locale);
364365
}
365366

367+
if (AppServices::request() instanceof IncomingRequest) {
368+
$requestLocale = AppServices::request()->getLocale();
369+
} else {
370+
$requestLocale = Locale::getDefault();
371+
}
372+
366373
// Use '?:' for empty string check
367-
$locale = $locale ?: AppServices::request()->getLocale();
374+
$locale = $locale ?: $requestLocale;
368375

369376
return new Language($locale);
370377
}

0 commit comments

Comments
 (0)