Welcome Guest, Not a member yet? Register   Sign In
Change language runtime
#1

Hi
On my shop website, I need to change shop language auto with user IP
For example, if a user is from Turkey, so load Turkey language or English language for America
I load English language default
I try to change the language in the config file but I cannot use the $this->db command and got error
I have country IPs in database and use query for detect user country with ip
And that is important check IP before set $config['language'] parameter
Thanks
Reply
#2

Please read this docs

https://codeigniter.com/user_guide/outgo...-detection
Reply
#3

(11-21-2021, 09:09 PM)hxd Wrote: Please read this docs

https://codeigniter.com/user_guide/outgo...-detection

That is Codeigniter 4 and I'm still on Codeigniter 3
My question is change language runtime
Reply
#4

Well, since you already have a way of detecting a user's country, I believe you are already close to what you are looking for.

From the docs, you will need to store the particular language of a user in the session. So, you can use that to automatically display the current page/language to the user.

PHP Code:
$idiom $this->session->get_userdata('language');
$this->lang->load('error_messages'$idiom); 
Reply
#5

(11-21-2021, 08:43 AM)omid_student Wrote: Hi
On my shop website, I need to change shop language auto with user IP
For example, if a user is from Turkey, so load Turkey language or English language for America
I load English language default
I try to change the language in the config file but I cannot use the $this->db command and got error
I have country IPs in database and use query for detect user country with ip
And that is important check IP before set $config['language'] parameter
Thanks

(11-21-2021, 09:09 PM)hxd Wrote: Please read this docs

https://codeigniter.com/user_guide/outgo...-detectionio games
thanks a lot!
Reply
#6

(11-21-2021, 09:09 PM)hxd Wrote: Please read this docs

https://codeigniter.com/user_guide/outgo...-detection

Thanks alot Sir!
Reply
#7

Here is how to get it with php.

How to detect Browser Language in PHP?

Make sure you do not have any security issues in your method with this code.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB