Welcome Guest, Not a member yet? Register   Sign In
How to set default Locale {locale} on default redirected controller?

(This post was last modified: 05-10-2022, 08:15 PM by luckmoshy.)

Hi all! I have an app that works ok in different languages but want to filter and fix on home URL to append locale as
PHP Code:
/*Filter class*/
    /*I get too many redirect error message*/
$uri = &$request->uri;
$segments array_filter($uri->getSegments());
$checkSegments count($segments);

//  the first 2 letters (en => en)
$userLocale strtolower(substr($request->getLocale(), 02));

$locale in_array($userLocale$request->config->supportedLocales) ? 
$userLocale :

       if if (
$checkSegments == 0)

I want if any incoming request should fall on eg: (www. example.com/en) and not (www. example.com)
PHP Code:
public function index(){
view('homepage');/*I want to fix in homepage should be appended with surport locale  = exapmple.com/{locale}*/
/* I get 404 error */
$routes->get('/{locale}''HomePage::index',['filter'=>'locales']); /*get 404 error*/ 
Do Codeigniter Before Do You!


Well, On Routes.php you can assign {locale} for the homepage and maybe this easy approach might give you idea for the rest:

PHP Code:
$lang $this->request->uri->getSegment(1); //this is the language code part.
        if($lang == ''){
            return redirect()->to(site_url('/en'));

So, it will automatically redirect to your default language, whatever it is..

IncludeBeer has a very nice tutorial on creating a Multi-Language web site for a Blog.

IncludeBeer Website
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB