Last post Jan 16, 2008 10:04 AM by davidhov
Jan 15, 2008 04:51 AM|ddpoona|LINK
I am creating a website in which the user is allowed to select the country name from a dropdownlist.
On selection of the country name the .resx file created for that culture should be used.
How to achieve that.
Please help me its very urgent.
Please tell me the steps to follow. I read a lot on net but didn't found that working.
Any code is appreciated.
Thank you in advance.
Jan 15, 2008 09:16 AM|rabeehabla|LINK
Check the following article
Jan 15, 2008 10:17 AM|davidhov|LINK
There are several steps here. First, your pages must be translatable. To do this, you need to create resource files (.resx) for each page, one for each target language you want to support. So if the page's name is MyPage.aspx, your App_LocalResources
folder must have MyPage.aspx (for default translation) and versions such as MyPage.aspx.it-IT.resx (for Italian), MyPage.aspx.fr-FR.resx (for French), etc.
The starting point for translation is to create the initial default RESX file: you must use the "Create Local Resource" tool. See
http://msdn.microsoft.com/en-us/library/ms247246(VS.80).aspx for information on how to do this. Once you have a RESX file for a page, you can simply make a copy of it, renaming it for
the correct language, and then edit it in the resource editor (just double-click in VS) and translate every string entry.
NOTE: the "Create Local Resource" tool will only translate code inside ASP server controls! Standard <p>, <table>, etc, will not be translated you can extract chunks of code manually into the resource file and replace them with "asp:Localize" controls. See
http://msdn.microsoft.com/en-us/library/ms228093(VS.80).aspx for information on how to do this.
Now, at run-time, assuming all your RESX files are in place, here's what happens. The user's browser will send a header called HTTP_ACCEPT_LANGUAGES in the GET request. ASP.NET will set the responding thread's "culture" (language and display options) based
on this, and ASP.NET will extract the resources from the correct RESX file as necessary.
In your case, however, you want to let user's choose a country, by which I presume you mean a language or language variant. Personally, I recommend against this, since it's tedious for the user and requires that she know how to read the home page. However,
I think you can accomplish this by intercepting the BeginRequest for your Application and setting the thread's CurrentCulture and CurrentUICulture based upon information you get from a cookie. Alternatively, you could use session state and save the user's
choice in there.
As an example, here's how you find out all the Cultures on your machine (C#):
public static string GetCultureNames ()
CultureInfo cif = GetAvailableCultures();
string asNames = new string[cif.Length];
int i = 0;
foreach ( CultureInfo ci in cif )
asNames[i++] = ci.Name;
Here's a VERY SIMPLE example of changing the culture. In this case, I needed to parse DateTime strings using en-US (U.S. English or mm/dd/yy) syntax (again in C#"):
protected CategorizedImages LoadSets()
// Save the current UI culture and set the UI culture to "en-US"
// to parse DateTime strings correctly!
CultureInfo ci = CultureInfo.CurrentCulture;
CultureInfo ciUS = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentCulture = ciUS;
CategorizedImages cimgs = new CategorizedImages();
cimgs.LoadSets( sfnXml, null, null );
// Restore the UI culture back to what it was.
Thread.CurrentThread.CurrentCulture = ci;
If your user's cookie or session state choice were the culture string ('it-IT") and you set the thread's state to that, the rendering engine should honor that. Be sure to set it back to its original value during EndRequest.
I hope all this helps. I am currently writing a tool to extrace ALL the text from XHTML web pages, create language RESX pages automatically and allow simple editing. That's how I found all this out.
Jan 16, 2008 06:30 AM|ddpoona|LINK
Thanks for the answer.
I am having a dropdownlist and in that I have country names and dropdowns value is culture variant.
so if user selects a country name I get the culture variant for that.
Please can you help me to achive this functionality in step by step procedure.
Also can you give code for the related events. that is the code I would require to achieve this functionality.
Please let me know in which event I need to write code and what the code should be.
Jan 16, 2008 10:04 AM|davidhov|LINK
Please link to http://www.theserverside.net/tt/articles/showarticle.tss?id=LocalizationPractices and see the section called "Selection Culture for ASP.NET Requests". It's about as clear as you can get, except that it's not a complete implementation.
Hope this helps,
Localization BeginRequest Culture