Page 1 of 1

Language and Currency in the URL?

Posted: Fri Mar 30, 2012 7:01 am
by montanasoftware
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!

Re: Language and Currency in the URL?

Posted: Fri Mar 30, 2012 10:30 am
by montanasoftware
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.

Re: Language and Currency in the URL?

Posted: Tue Apr 03, 2012 7:35 pm
by remcofaasse
index.php?language=en&currency=AUD
works! great!

Re: Language and Currency in the URL?

Posted: Sun Apr 08, 2012 1:04 am
by dpit
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 ?

Re: Language and Currency in the URL?

Posted: Sun Apr 08, 2012 6:47 am
by dpit
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.

Re: Language and Currency in the URL?

Posted: Tue Apr 10, 2012 3:02 am
by Qphoria
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

Re: Language and Currency in the URL?

Posted: Sat Apr 14, 2012 4:35 am
by arames
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

Re: Language and Currency in the URL?

Posted: Sat Apr 28, 2012 5:40 am
by arames
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

Re: Language and Currency in the URL?

Posted: Sat Apr 28, 2012 5:47 am
by dpit
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..

Re: Language and Currency in the URL?

Posted: Sat Apr 28, 2012 6:03 am
by arames
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..)

Re: Language and Currency in the URL?

Posted: Sat Apr 28, 2012 6:17 am
by dpit
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.

Re: Language and Currency in the URL?

Posted: Sat Jul 07, 2012 7:41 pm
by msmith
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?

Re: Language and Currency in the URL?

Posted: Sun Jul 08, 2012 6:27 am
by Qphoria
It was removed because daniel didn't like it.

Re: Language and Currency in the URL?

Posted: Sun Jul 08, 2012 6:32 am
by msmith
lol love the cool answer, in your line - don't like to touch the index.php, but couldn't get the vqmod to work

Re: Language and Currency in the URL?

Posted: Sun Jul 08, 2012 9:26 am
by JAY6390
msmith: If you use seo url's, you may want to check out this vQmod (commercial)

Re: Language and Currency in the URL?

Posted: Sat Aug 18, 2012 10:04 pm
by OC2PS
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)?

Re: Language and Currency in the URL?

Posted: Mon Dec 17, 2012 6:54 am
by madimar
Follow...
I'd like too old one (or a better method) to be introduced again in last Opencart versions!

M

Re: Language and Currency in the URL?

Posted: Tue Dec 10, 2013 3:23 am
by krissaa
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.