Skip to main content
Known Participant
September 7, 2010
Answered

switch language when clicking a link

  • September 7, 2010
  • 3 replies
  • 1202 views

How to switch (change) the current web page language after clicking a link?

e.g.

I tried the following to switch to "English" but they does not work.

<li><div><a href="&lang=en">English</a></div></li>

will get this error:

The requested resource (/dev/prog/&lang=en) is not available.

<li><div><a href="?lang=en">English</a></div></li>

will go to another page instead of staying at the current page.

I use ColdFusion 6,1,0,hf53852_61 Enterprise

This topic has been closed for replies.
Correct answer ilssac

e.g. If the current page is "http://dev.mycom.com/index.cfm?action=add", then clicking the "English" link will go to "http://dev.mycom.com/index.cfm?action=add&lang=en", which will get all the language data from the db.

How to get the current page url with parameters (i.e. "http://dev.mycom.com/index.cfm?action=add")?

What should the cf code be?

<cfdump var="#cgi#"> and "getCurrentTemplatePath()" do not return any parameter: "action=add".


#cgi.query_string# did not contain useful data?

3 replies

albertkaoAuthor
Known Participant
September 9, 2010

index.cfm has the following code:

<cfset servername = #cgi.SERVER_NAME#>

<cfset script = #cgi.SCRIPT_NAME#>

<cfset querystr = #cgi.query_string#>

<cfset position = find("DATA", script)>

<cfset length = Len(script)>

<cfset path = Mid(script, position, length)>

<cfset newpath = servername & "/" & path & "/" & querystr & "&lang=en">

<cfoutput>#script#</cfoutput>

<cfoutput>#position#</cfoutput>

<cfoutput>#length#</cfoutput>

<cfoutput>#path#</cfoutput>

<cfoutput>#htmlEditFormat(newPath)#</cfoutput>

<li class="fiptexta"><div><a href="<cfoutput>#htmlEditFormat(newpath)#</cfoutput>">English</a></div></li>

The resulting web page source seems ok:

<li class="fiptexta"><div><a href="http://dev.mycom.com/DATA/db/index.cfm/action=add&lang=en">English</a></div></li>

However, clicking the "English" link result in this error:

----------------------------------------------------------------------------------------------

HTTP Status 404 - /data/DATA/db/index.cfm/action=add&lang=en

type Status report

message /data/DATA/db/index.cfm/action=add&lang=en

description The requested resource (/data/DATA/db/index.cfm/action=add&lang=en) is not available.

Apache Tomcat/5.5.23

-----------------------------------------------------------------------------------------------

Please help.

Browser is FF 3.6.9 on Windows XP Professional v2002 SP3.

ColdFusion 6,1,0,hf53852_61 Enterprise

Inspiring
September 7, 2010

In addition to ilssac's answer, your anchor tag is not pointing to a web page.

ilssac
Inspiring
September 7, 2010

Where and how are you storing and|or displaying the web pages content in the different languages?

I'm hoping you don't expect the browser or the server to just translate your page for you?

albertkaoAuthor
Known Participant
September 7, 2010

My goal is to append "&lang=en" to the current page url when the "English" link is clicked.

e.g. If the current page is "http://dev.mycom.com/data", then clicking the "English" link will go to "http://dev.mycom.com/data&lang=en", which will get all the language data from the db.

How to get the current page url?

What should the cf code be?

ilssac
Inspiring
September 7, 2010

albertkao wrote:


What should the cf code be?

Ah ok, now we have something to help with.

There is the getCurrentTemplatePath() function. AND There is the CGI variables suc as cgi.scriptName.

I would start by doing a <cfdump var="#cgi#"> and see if that gives you what you need and contrast that with getCurrentTemplatePath() and see which works best for you.

Message was edited by: ilssac  You may also want to look at JavaScript or other client side technologies, if you do not want to have a turn around with the web server.