[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Regarding Using multiple Locales on an Application

Hi, I am trying to Use the Locales In ColdFusion. I want to give option to the user to choose from the dropdown in the login screen, and he/she logins, it should change the locale on the checklogin page, and whatever currency or dateformat i should see should be displayed in the chosen locale.  I am also trying to get the timezones for the chosen locale.

I have tried this much so far

<div class="control-group moveahead">
            <div class="controls">
            <select name="mylocale" data-placeholder="Please choose one" data-rel="chosen"> 
            <cfloop index="i" list="#server.coldfusion.supportedlocales#"> 
                <option value="#i#">#GetLocaleDisplayName(i, "en_US")#</option> 
            </cfloop> 
            </select>
            </div>
            </div>
            <div>&nbsp;</div>

Open in new window


The Portion Where i am handling it:

<cfset getusers = Application.tools.checkUser(form)>   
  <cfif getusers.recordcount>
  	<cfset oldlocale=SetLocale("#form.mylocale#")> 
    <cfset session.newlocale = GetLocale()>  
    <cfset SetLocale(session.newLocale)>
    <cfset SESSION.User.ID = 1>
    <cfset session.email = getusers.emailaddress>
    <cfset session.username = getusers.username>
    <cfset session.userid = getusers.adminID>
    <cfset session.loggedin = True>

Open in new window


In the above, Missing is the timezone Information and the Locale is not setting up correctly
0
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
  • 3
  • 3
1 Solution
 
_agx_Commented:
> <cfset session.newlocale = GetLocale()>  

You're assigning the current locale instead of the selected locale. Do this:

   
    <!--- assign selected locale first, then use SetLocale --->
   <cfset session.newlocale = form.mylocale>
   <cfset SetLocale(session.newLocale)>

Open in new window

 



> I am also trying to get the timezones for the chosen locale.
That's a totally different question, but .. there's no such mapping. You either need to create your own, by locale, and store it in a db table (which is a big job) or do what's more typical - display them all and allow the user to choose the one they want.
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
That's a totally different question, but .. there's no such mapping. You either need to create your own, by locale, and store it in a db table (which is a big job) or do what's more typical - display them all and allow the user to choose the one they want.

Hi Agx,

This is what i am thinking rather than displaying the option to change the locale, I think it will be better to do that in database, because my work involves Money transactions and changing the locale will not only the currency format, but not the amount.

I think better would be create a DB and allow user to manually change the Locale during installation and then would not let do so, or if you have any better idea, please drop by

Thanks
0
 
_agx_Commented:
> the currency format, but not the amount.

True. Locale only controls how things are displayed. Changing it won't convert an amount from say 150 U.S. dollars to the equivalent in Euro's, based on the current exchange rate. It will just display 150 with the appropriate currency symbols.  

It all depends on the app, but it sounds like you need to store rates for different countries (based on currency used). That should probably be stored in the db.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
so probably whenever the locale is changed, make an ajax call and call the database table, where the changed currency values are stored and then it calculates the amount.

btw, i need to rerun that query of getting new currency rates every day to get the new rates,

it does not sounds right - what you say
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
wel, at least the answer did not worked, it did not changed the locale.
0
 
_agx_Commented:
@myselfrandhawa - Not really sure what you're talking about ... Handling currency and exchange rates is a totally different subject than what you originally asked, and is not my area of expertise. You need to open a new question for that in the right zones.

I can only answer your original two questions:

1) Setting the locale in CF works fine, so either you're using different code, or didn't apply the fix described here.

<cfparam name="session.newlocale" default="#GetLocale()#">
<cfoutput>
<form method="post">
	<select name="mylocale" data-placeholder="Please choose one" data-rel="chosen"> 
    	<cfloop index="i" list="#server.coldfusion.supportedlocales#"> 
        	<option value="#i#">#GetLocaleDisplayName(i, "en_US")#</option> 
		</cfloop> 
	</select>
	<input type="submit">
</form>

<cfif structKeyExists(FORM, "myLocale")>
	Old Locale = #session.newLocale#<br>
    <cfset session.newlocale = mylocale>  
    <cfset SetLocale(session.newLocale)>
</cfif>
New Locale = #session.newLocale#<br>
Locale date #LSDateFormat(now(), "mmmm dd, yyyy")#<br>
</cfoutput>

Open in new window


2. There is no built in mapping of time zones by locale. Either display them all and let the user choose the one they want (typical of most sites) or roll your own, which is not a trivial task.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now