Welcome Guest, Not a member yet? Register   Sign In
setLocale() doesn't change the language set by browser
#11

(This post was last modified: 07-29-2024, 01:33 PM by kenjis.)

in the BaseController I did this:
PHP Code:
    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        // Preload any models, libraries, etc, here.
        $session = \Config\Services::session();
        $language = \Config\Services::language(); <--------- Added This
        $language
->setLocale($session->site_lang)  <--------- Added This;  
        
// E.g.: $this->session = \Config\Services::session();
    

in app/config/Lang.pgp
PHP Code:
<?php
namespace App\Controllers;
use 
CodeIgniter\Controller;

class 
Lang extends BaseController 
{
    function __construct() 
    {
        //parent::__construct();
    }

    public function index()
    {
        session()->set('site_lang',  "pt");
        //$this->load->view('welcome_message');
    }

    public function switchLang$language 'pt' 
    {
        session()->set('site_lang'$language);
        //header('Location: http://localhost/ci_multilingual_app/');
    }

Reply




Theme © iAndrew 2016 - Forum software by © MyBB