version: develop (4.3.x)
Locale::getDefault() is different from $this->request->getLocale() when we use content negotiation.
--- a/app/Config/App.php
+++ b/app/Config/App.php
@@ -83,7 +83,7 @@ class App extends BaseConfig
*
* If false, no automatic detection will be performed.
*/
- public bool $negotiateLocale = false;
+ public bool $negotiateLocale = true;
/**
* --------------------------------------------------------------------------
@@ -98,7 +98,7 @@ class App extends BaseConfig
*
* @var string[]
*/
- public array $supportedLocales = ['en'];
+ public array $supportedLocales = ['en', 'ja'];
/**
* --------------------------------------------------------------------------
<?php
namespace App\Controllers;
use Locale;
class Home extends BaseController
{
public function index()
{
return 'Request:' . $this->request->getLocale()
. ', Locale:' . Locale::getDefault();
}
}
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -31,6 +31,8 @@ $routes->set404Override();
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
+$routes->get('{locale}', 'Home::index');
+
/*
* --------------------------------------------------------------------
* Additional Routing
When we use only content negotiation:
$ curl -H "Accept-Language: ja,en-US;q=0.9,en;q=0.8" http://localhost:8080/
Request:ja, Locale:en
But If {locale} is used in a route, both locales are set to ja.
$ curl -H "Accept-Language: ja,en-US;q=0.9,en;q=0.8" http://localhost:8080/ja
Request:ja, Locale:ja
version: develop (4.3.x)
Locale::getDefault()is different from$this->request->getLocale()when we use content negotiation.When we use only content negotiation:
But If
{locale}is used in a route, both locales are set toja.