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
LVL 16
Gurpreet Singh RandhawaCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_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 RandhawaCEOAuthor 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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Gurpreet Singh RandhawaCEOAuthor 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 RandhawaCEOAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.