Locale support for address labels

S

Steven Nagy

Hiyas

Our app has a search field where you can select a country drop down
and then enter some search criteria that is address based. We want the
labels on the search form to change based on what country you select.
For example, if I select UK, it might ask for District and Borough
(sp?). Whereas if I select Australia, I need it to say State and
Postcode. For the US it might say Zip instead.

I figure best way is to store all these labels in a resx file by
locale, and when I select UK from ddl, it passes en-uk locale to my
control, which loads the correct labels.

Before I start typing out all the locales in my resx file, I'd like to
know if it already exists. No doubt it does, but couldn't find it by
searching. Anyone know of such a file or even a control that supports
it all?

Cheers,
Steve
 
G

Guest

Hiyas

Our app has a search field where you can select a country drop down
and then enter some search criteria that is address based. We want the
labels on the search form to change based on what country you select.
For example, if I select UK, it might ask for District and Borough
(sp?). Whereas if I select Australia, I need it to say State and
Postcode. For the US it might say Zip instead.

I figure best way is to store all these labels in a resx file by
locale, and when I select UK from ddl, it passes en-uk locale to my
control, which loads the correct labels.

Before I start typing out all the locales in my resx file, I'd like to
know if it already exists. No doubt it does, but couldn't find it by
searching. Anyone know of such a file or even a control that supports
it all?

Cheers,
Steve

Hi Steve,

here's a list of cultures
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(VS..80).aspx

and here is an example of using resx for a label customization
http://msdn.microsoft.com/en-us/library/fw69ke6f(VS.80).aspx

Hope this helps
 
S

Steven Nagy

Thanks Alexey,

Do you (or anyone) know if you can set the locale for a specific
control only?
Lets say my CurrentThread.CurrentUICulture is set to en-US and I want
this to remain as is (loading all the resources for en-US) but I want
to change the locale for just one control to en-UK so that those
resources are loaded for that control instead.
Is this possible?

Cheers,
Steve
 
G

Guest

Thanks Alexey,

Do you (or anyone) know if you can set the locale for a specific
control only?
Lets say my CurrentThread.CurrentUICulture is set to en-US and I want
this to remain as is (loading all the resources for en-US) but I want
to change the locale for just one control to en-UK so that those
resources are loaded for that control instead.
Is this possible?

Cheers,
Steve

If you understood you correct, you could do it per control as follows

<asp:Label ID="ZIPCodeLabel" Runat="server" Text="<%$
Resources:LocalizedText, ZIPname %>">

For US it would be a "ZIP", for Canada/Europe a "Postal Code", etc.

You could also check the current culture and decide if control/string
needs to be translated or not

if (Thread.CurrentThread.CurrentCulture.Name == "en-US") {
....
} else {
....
}

or

System.Globalization.CultureInfo culture = new
System.Globalization.CultureInfo("en-US");
HttpContext.GetGlobalResourceObject("resource", "ZIPname", culture);

where GetGlobalResourceObject is to retrieve the resource value
("ZIPname") from global resource file, named Resource.resx
programmatically

http://msdn.microsoft.com/en-us/library/ms149953.aspx
http://msdn.microsoft.com/en-us/library/ms227982.aspx

Basically the idea of using resources is to have the translation for
all "strings" in the application. And an application loads the
appropriate localized resources based on the current culture.
 
S

Steven Nagy

Ah this is the code I was after:

System.Globalization.CultureInfo culture = new
System.Globalization.CultureInfo("en-US");
HttpContext.GetGlobalResourceObject("resource", "ZIPname", culture);

Means I can have my single control changed to a different culture, and
have the labels loaded for that culture, while the rest of hte
application still sits in a different culture.

Thanks!
 
G

Guest

Ah this is the code I was after:


Means I can have my single control changed to a different culture, and
have the labels loaded for that culture, while the rest of hte
application still sits in a different culture.

Thanks!


Yes, you can.

Note, there is also the GetLocalResourceObject method to get a page-
level resource (not the global one)
http://msdn.microsoft.com/en-us/library/ms149953.aspx

for example

System.Globalization.CultureInfo culture = new
System.Globalization.CultureInfo("en-US");
GetLocalResourceObject("~/Default.aspx", "PageResource1.Title",
culture);

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top