Post by xoomit » Wed Dec 07, 2016 11:39 pm

Hej guys,

I would like to set the customers language based on the current domain (I have modded my OC so that form one core I got 2 languages running on separate domains). Unfortunately I am a php noob. My solution would be to attach ?language=de or ?language=en to the customers landing page via JS. Not a good one.

In the startup php it says:

Code: Select all

		
// Language Detection
		if (!empty($this->request->server['HTTP_ACCEPT_LANGUAGE']) && !array_key_exists($code, $languages)) {
			$detect = '';
			
			$browser_languages = explode(',', $this->request->server['HTTP_ACCEPT_LANGUAGE']);
			
			// Try using local to detect the language
			foreach ($browser_languages as $browser_language) {
				foreach ($languages as $key => $value) {
					if ($value['status']) {
						$locale = explode(',', $value['locale']);
						
						if (in_array($browser_language, $locale)) {
							$detect = $key;
							break 2;
						}
					}
				}	
			}			
			
			if (!$detect) { 
				// Try using language folder to detect the language
				foreach ($browser_languages as $browser_language) {
					if (array_key_exists(strtolower($browser_language), $languages)) {
						$detect = strtolower($browser_language);
						
						break;
					}
				}
			}
			
			$code = $detect ? $detect : '';
		}
How could I change this code so that it does IF current domain = domainA.de set "de" IF current domain = domainB.com set "en".

Ideas anyone? I'd really appreciate it!

Thanks!

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by opencartmart » Thu Dec 08, 2016 12:28 am

You are in right track! In the file controller/startup/startup.php insert following lines of code before the line if (!array_key_exists($code, $languages)) {

Code: Select all

if (!empty($this->request->server['HTTP_HOST'])) {
		  $code = array_pop(explode('.',$this->request->server['HTTP_HOST']));
		  $code = ($code === 'com') ? 'en' : $code;
		}

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by xoomit » Wed Dec 14, 2016 6:42 pm

Hej opencartmart,

thank you very much for your reply. Unfortunately it doesn't seem to do the trick. Would it have to be HTTPS_Host? Or do you have any other idea as to why this wouldn't work?

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by opencartmart » Wed Dec 14, 2016 9:05 pm

There is nothing like HTTPS_Host. Have you inserted into correct place? Also try refreshing ocmod

If you share your code what you have inserted

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am
Who is online

Users browsing this forum: Bing [Bot] and 67 guests