Post by montanasoftware » Fri Mar 30, 2012 7:01 am

Hi: Is there a way to force the language and currency in the URL? If so, what are the parameters?

I ask this because I would like to link to a specific language/currency combination, rather than rely on the requester's browser defaults.

I'm looking for something like this: http://www.mysite.com&language=de&cur=EUR

Thanks!

I use OpenCart 1.5.2.1 at: http://www.alpineultralight.com



Posts

Joined
Sun Mar 25, 2012 10:42 pm

Post by montanasoftware » Fri Mar 30, 2012 10:30 am

Hi Guru: Thank you for your response. I read the posts you linked to and they all said it would work if you append

"&language=de" to the URL.

I tried that before posting this question and it didn't work properly.

This is what I've typed in the URL box of the browser:

http://mysite.com/index.php?language=de

If I changed from English to German, it worked. But if I then entered:

http://mysite.com/index.php?language=en

It doesn't switch back to english.

If I hit the British flag, it will switch back to english.

Was this language in the URL option modified from version 1.5.x? I'm running 1.5.2.1

Thanks again for your willingness to help.

I use OpenCart 1.5.2.1 at: http://www.alpineultralight.com



Posts

Joined
Sun Mar 25, 2012 10:42 pm

Post by remcofaasse » Tue Apr 03, 2012 7:35 pm

index.php?language=en&currency=AUD
works! great!

New member

Posts

Joined
Mon Dec 05, 2011 2:20 am

Post by dpit » Sun Apr 08, 2012 1:04 am

qphoria - you're going to hate me but it simply doesn't work on the OpenCart install I'm working on - 1.5.2.1

I am looking all over the solution for a sign of where it enquires the URL for the language (or indeed the currency) but I simply cannot find it.

It seems crazy for me to write my own function if the Core should be taking care of this already.

Could you please point me to the code where the URL query params are used for setting the lanaguage, then I can reconcile with mine ?

Newbie

Posts

Joined
Sun Apr 08, 2012 12:58 am

Post by dpit » Sun Apr 08, 2012 6:47 am

Ok... I must be missing the blindingly obvious. But ?language=fr simply did nothing and I could find no code that suggested it would (OC 1.5.2.1).

In case it helps others or even myself if this encourages someone able, to shed some light:

I have added my some amendments, after a little battle with the redirect (if the language param exists in the url when you post a new lang choice, the url param was winning), and these are them (feel free to improve or nuke!):

the index.php file:

Code: Select all

/*NEW*/if(isset($_GET['language']) && array_key_exists($_GET['language'], $languages)) {
        $code = $_GET['language']; $_GET['language'] = null;
} else /*NEW*/if (isset($session->data['language']) && array_key_exists($session->data['language'], $languages) && $languages[$session->data['language']]['status']) {
	$code = $session->data['language'];
} elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages) && $languages[$request->cookie['language']]['status']) {
	$code = $request->cookie['language'];
} elseif ($detect) {
	$code = $detect;
} else {
	$code = $config->get('config_language');
}
and the sys/eng/controller.php file

Code: Select all

protected function redirect($url, $status = 302) {
		header('Status: ' . $status);
                /*NEW*/
                $url = str_replace('&', '&', $url);
                $purl = explode('?', $url);
                parse_str($purl[1], $gets);
                unset($gets['language']);
                $url = $purl[0].'?'.urldecode(http_build_query($gets));
                header('Location: ' . $url);
                /*NEW*/
		/*OLD*/header('Location: ' . str_replace('&', '&', $url));/*OLD*/
		exit();
	}

----
I can only assume my OC files are missing something along the lines of GET["language"] that should exist or my NetBeans find is broken :(

Any chance someone able can shed some light?

For clairty, solely due to the code above ?language=fr now works and altering the language via the form in the header area continues to work alongside.

Newbie

Posts

Joined
Sun Apr 08, 2012 12:58 am

Post by Qphoria » Tue Apr 10, 2012 3:02 am

Ah you are right.. looks like daniel removed it in 1.5.2 here..
http://code.google.com/p/opencart/sourc ... /index.php
Your index.php change is correct. Don't think you need the other change as that was never there before.

I'll talk to him about it

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by arames » Sat Apr 14, 2012 4:35 am

Hi Qphoria,

are these changes ok? can we go ahead and change our index.php if we want to create links that directly chooses the language for the customers?

Example:
http://mysite.com/index.php?language=de

this will be the link we will post in our german forums for customers to get directly to our store with the german interface.

Anticipated thx

New member

Posts

Joined
Fri Mar 09, 2012 8:27 pm

Post by arames » Sat Apr 28, 2012 5:40 am

Qphoria,

I have added the BELOW code to main index.php

Code: Select all

/*NEW*/if(isset($_GET['language']) && array_key_exists($_GET['language'], $languages)) {
        $code = $_GET['language']; $_GET['language'] = null;
} else /*NEW*/if (isset($session->data['language']) && array_key_exists($session->data['language'], $languages) && $languages[$session->data['language']]['status']) {
   $code = $session->data['language'];
} elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages) && $languages[$request->cookie['language']]['status']) {
   $code = $request->cookie['language'];
} elseif ($detect) {
   $code = $detect;
} else {
   $code = $config->get('config_language');
}
saved it and uploaded it ... still if you click on
http://mysite.com/index.php?language=de

it will still show you the ENGLISH version.

Please any help on WHAT to add or what to do?

Anticipated thx

New member

Posts

Joined
Fri Mar 09, 2012 8:27 pm

Post by dpit » Sat Apr 28, 2012 5:47 am

Are you able to debug? If you choose de via the long flags, does it set?

You or I can tweak the code to log an error to the error log explaining why the language wasn't used - just to debug..

Newbie

Posts

Joined
Sun Apr 08, 2012 12:58 am

Post by arames » Sat Apr 28, 2012 6:03 am

Hi dpit,

thank you for your prompt answer.

1/
Yes if I click on the German flag then the language of the site changes to german

2/
How can I set a debug to see the error?

3/
I must admit I only made the changes to index.php and NOT to "sys/eng/controller.php" file.

Should I retest it with the controller.php changes as well see if the problem lies there?

Thank you again for helping us with this Language issue, since it does make a LOT more sense if you wish to send a customer to a product or page in his language rather then to tell him (and by the way, dont forget to click on the flag..)

New member

Posts

Joined
Fri Mar 09, 2012 8:27 pm

Post by dpit » Sat Apr 28, 2012 6:17 am

I use netbeans against a local copy.

The controller was to support flag usage alongside this.

So it should work now. I think the best thing might be to spit out some debug info to your error log.

I can have a look Sunday if you need help. You will find it quite easy to spit out info to the log though, and thus find out what's wrong.

Newbie

Posts

Joined
Sun Apr 08, 2012 12:58 am

Post by msmith » Sat Jul 07, 2012 7:41 pm

Hi, what happened to this?

I'd like to use &language and &currency but it doesn't work on 1.5.3.1 either... was it removed because of a security problem?

Active Member

Posts

Joined
Mon Oct 18, 2010 8:57 pm

Post by Qphoria » Sun Jul 08, 2012 6:27 am

It was removed because daniel didn't like it.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by msmith » Sun Jul 08, 2012 6:32 am

lol love the cool answer, in your line - don't like to touch the index.php, but couldn't get the vqmod to work

Active Member

Posts

Joined
Mon Oct 18, 2010 8:57 pm

Post by JAY6390 » Sun Jul 08, 2012 9:26 am

msmith: If you use seo url's, you may want to check out this vQmod (commercial)

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by OC2PS » Sat Aug 18, 2012 10:04 pm

Qphoria wrote:It was removed because daniel didn't like it.
Any reason why he didn't like it?

Is he planning to provide language-specific SEO keywords (slugs)?

OC2PS
OC 3.0.3.7, vQmod 2.6.2, Journal3 theme
Arcfesték, Csillámtetoválás, Henna
Image
Check out: All my extensions | My FREE extensions


User avatar
Active Member

Posts

Joined
Wed Jul 22, 2009 4:15 am
Location - Hungary

Post by madimar » Mon Dec 17, 2012 6:54 am

Follow...
I'd like too old one (or a better method) to be introduced again in last Opencart versions!

M

-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------


User avatar
Active Member

Posts

Joined
Thu Sep 24, 2009 6:27 pm


Post by krissaa » Tue Dec 10, 2013 3:23 am

dpit's code worked in 1.5.5.1, and both the index.php and the controller.php changes are necessary to get both the url and the language flag buttons working correctly.

I think arames's problem was that he added the index code incorrectly. Only this code is added:

Code: Select all

/*NEW*/if(isset($_GET['language']) && array_key_exists($_GET['language'], $languages)) {
        $code = $_GET['language']; $_GET['language'] = null;
} else /*NEW*/
The rest of it is just there to show you were it goes.

Newbie

Posts

Joined
Tue Dec 10, 2013 3:11 am
Who is online

Users browsing this forum: No registered users and 81 guests