Welcome Guest, Not a member yet? Register   Sign In
Change language dynamically CI 4.4.6
#1

I'm trying to change the language of my app.

I've tried inside the BaseController in the initController method in several ways

PHP Code:
$lingua session('lingua');
config('App')->defaultLocale $lingua

or
PHP Code:
$lingua session('lingua');
(!isset(
$lingua)) ? $this->request->setLocale('it') : $this->request->setLocale(session('lingua')); 
or

PHP Code:
$lingua session('lingua');
config('App')->defaultLocale $lingua;
(!isset(
$lingua)) ? $this->request->setLocale('it') : $this->request->setLocale(session('lingua')); 


If I try to print these variables on the screen I receive:
echo session('language'); returns "en"
echo config('App')->defaultLocale; returns "en"
echo $this->request->getLocale(); return 'it'
If I manually change the value of public string $defaultLocale to 'en' or 'it' everything works and I see the app in the desired language

What should I do to be able to change the language dynamically?

I don't need the URL changed.
Reply


Messages In This Thread
Change language dynamically CI 4.4.6 - by serialkiller - 03-13-2024, 07:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB