Welcome Guest, Not a member yet? Register   Sign In
language abbreviation in url
#1

Hello everybody,

I am working with codeigniter 4. I have a problem.
how can i recognize language abbreviation in url.

with
PHP Code:
$routes->get('{locale}/books''App\Books::index'); 

I tried but the problem is the following.

1. for all routes {locale} must be defined.
2. without language abbreviation the controller is not found.
3. $routes->setAutoRoute(true); no longer works.

it has to work like this:
when user enters the URL:
www.domain.com requires its browser language to be recognized and redirected to www.domain.com/en/

and if user enters the URL www.domain.com/de/ the locale must be changed in German.

this must work as well:
http://www.domain.com/contoller/method redirect to http://www.domain.com/en/contoller/method

I look forward to your suggestions
thanks
Reply
#2

Did you read this section in the user guide? I didn't try it yet, but it explains how to do it:
https://codeigniter4.github.io/CodeIgnit...#in-routes
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(04-24-2019, 05:28 AM)includebeer Wrote: Did you read this section in the user guide? I didn't try it yet, but it explains how to do it:
https://codeigniter4.github.io/CodeIgnit...#in-routes

yes but that is not four for this.
Reply
#4

(04-23-2019, 09:45 PM)arassaff Wrote: Hello everybody,

I am working with codeigniter 4. I have a problem.
how can i recognize language abbreviation in url.

with
PHP Code:
$routes->get('{locale}/books''App\Books::index'); 

I tried but the problem is the following.

1. for all routes {locale} must be defined.
2. without language abbreviation the controller is not found.
3. $routes->setAutoRoute(true); no longer works.

it has to work like this:
when user enters the URL:
www.domain.com requires its browser language to be recognized and redirected to www.domain.com/en/

and if user enters the URL www.domain.com/de/ the locale must be changed in German.

this must work as well:
http://www.domain.com/contoller/method redirect to http://www.domain.com/en/contoller/method

I look forward to your suggestions
thanks

Hi,
did you find any solution? I am struggling the same problem now. Thanks in advance.
Reply
#5

See https://github.com/codeigniter4projects/website2 for a working example.
Reply
#6

Edit routes.php like this:

PHP Code:
$routes->get('{locale}/auth/(:any)''Auth::$1');
$routes->post('{locale}/auth/(:any)''Auth::$1'); 

{locale} - local code
auth - name controller
(:any) - name method
Reply




Theme © iAndrew 2016 - Forum software by © MyBB