Post by mynameismosa » Thu Jan 11, 2018 6:38 pm

I'm trying to set the default language programmatically in OpenCart 3 when user for the first time visit the website.
I tried a lot but I have 2 problems which I can't find a solution for them:

1. I don't know how to set the default language programmatically
2. How to detect if the website / page loads for the first time

Here is the code I tried:

Code: Select all

	$supportedLangs = array('en', 'ru', 'ar', 'fa', 'tr');
	
	$languages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
	
	foreach($languages as $lang)
	{
		$lan = explode(';',$lang);
		if (strlen($lan[0]) <= 2) {
			if(in_array($lan[0], $supportedLangs))
			{
				$this->language->set($lan[0]);
				break;
			}
		}
	}

Newbie

Posts

Joined
Wed Aug 16, 2017 3:34 pm

Post by straightlight » Thu Jan 11, 2018 6:55 pm

catalog/controller/startup/startup.php file.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 298 guests