2

This is a struts2 question.

Currently, I am using i18n for internationalization in my webapp. Some of my jsp pages has querystring to store the request information. For example,

http://myWebsite.com/myWebsite/myPage?productId=12345

When users try to switch language, I rewrite the URL by javascript to

http://myWebsite.com/myWebsite/myPage?request_locale=zh_CN

And it loses the query string.

And my urls are used in different ways:

http://myWebsite.com/myWebsite/myPage
http://myWebsite.com/myWebsite/myPage?productId=12345#myAnchor
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3#myAnchor
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3&request_locale=zh_CN
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3
...

When I try to handle all this differences in javascript, it becomes so complicated.

Is there any good way to retain the querystrings and anchors after switching locale?

Drogba
  • 4,186
  • 4
  • 23
  • 31

1 Answers1

1

When you rewrite the URL using JS, you should do it based on the current URL.

So, if in the browser is showed

http://myWebsite.com/myWebsite/myPage?productId=12345

you should rewrite it as

http://myWebsite.com/myWebsite/myPage?productId=12345&request_locale=zh_CN

For that, using JS you should get the current URL displayed. Take a look to this question for how to.

Community
  • 1
  • 1
jddsantaella
  • 3,657
  • 1
  • 23
  • 39
  • I am actually doing this in javascript. When the request_locale is part of the url and it's in the middle of the querystring. It becomes very hard to handle. (becasue user may switch language mutliple times) – Drogba Nov 21 '12 at 05:01
  • So, you should analyse the URL, remove language parameter and add the new one. It shouldn't be so hard. JQuery can help you to do that. See this answer: http://stackoverflow.com/a/1090985/980472 – jddsantaella Nov 21 '12 at 06:52