Localization :: Assign Culture To Current Thread When Http Is Stateless?
Feb 5, 2010
When I was localizing my web application I got one strange doubt.
In the first request i set current thread's current culture to user chosen culture. It worked fine for that particular request. But when i browsed for other page, server rendered content in default english culture. I think the reason meight be "http is stateless" means current request is served by a thread whose culture was set properly. Send request will be serverd another thread which does not about previous thread. So we should once again assign culture to this thread. Localization can be done by setting culture to a session variable.
So my question is what is the benifit that we get by setting culture to current thread. With setting to thread we can show the page in user desired language.
i have three master pages and some contents pages in my project.
in content page i have wrote below script:
[Code]....
And i have a language flags in my master page. so i have created image button for language flag to perform on click action. where On click of language flag (polish) i like to change the content (English) of my page as per the selected flag click.
hence i have wrote in master page:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../common/images/pol.gif" AlternateText="Polish" /> And in code behind --- ImageButton1_Click Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("pl-PL") Thread.CurrentThread.CurrentUICulture = New CultureInfo("pl-PL") Response.Write(Thread.CurrentThread.CurrentCulture) Dim geturl As String geturl = Request.Url.ToString() Response.Redirect(geturl)
here the geturl is print with "pl-PL" but the page content is printed with English language.
I want to change page content also as per flag seletion.
I have a ASP.NET page with a WebMethod that creates an object and runs one of the object's methods in a new thread.I need to access the System.Web.HttpContext.Current.Response.ContentType property from within this thread. Each time I (try to) access it, I receive a NullReferenceException.
I need to change culture of the specific aspx page bases on the main user's culture.I am able to fetch the data that which culture main user have.But some how I am not able to set the same culture for that aspx page.I had written the below code for that.
[Code]....
But that is not working it sets the default culture of the browser.
how can to get culture info or just culture name from the datetime string e.g i have strings like: "16/02/2008" or "23/02/2008 " can i know the culture name from the above datetime strings?
With asp.net MVC 2, I have been trying to get Matt Hawley's Localization helper to work in my web application, but I am getting stuck feeding a null into the Language string variable. I can't figure out why I am doing this.
I have a static class with serveral static methods. In these methods, I'm trying to access the current thread's context using HttpContext.Current. For example:
var userName = HttpContext.Current.User.Identity.Name;
However, when I do that, I receive a NullReferenceException, the infamous "Object reference not set to an instance of an object."
I want to set culture info for my full application. where're i say datetime.now, it should give datetime based on my cultureinfo i set. how do i do it?
I have a very simple bilingual site with a link at the bottom that will allow users to switch between the two languages (english/french). the the web.config I have the following line:
<globalization culture="auto" uiCulture="auto" />
This allows for whatever the users browser culture is to be the default lanauge but I'd still like the ablility for them to click a bottom button to toggle. whats the best what to go about doing this?
As per MSDN - Culture is name for traiditional wotd locale But at som many places, people use phrase like . "I am trying to implement culture and locale" Are they same or different?
I'm following the instructions step by step in VS 2010, and it creates the resource files exactly how it's supposed to. However, when I run the program it just doesn't apply it. I don't see the different values from the resource file.
If I leave my resource file name as sample.aspx.resx, it works. But when I change it to sample.aspx.en-us.resx, it doesn't work. I'm supplying culture from the aspx page's Culter and UICulture properties. I'm being very careful in choosing the correct file name, as that could be the issue, but it just doesn't work. I also tried changing the culture in the backend code this way:
Protected Overrides Sub InitializeCulture() [code]....
I'm trying to change the value of the language and culture values via a database entry and then appending the culture to the returned value. IE: "en" is in the database, I add "-CA" via VB code.When I hardcode the values, it does work no problem. However, appding the "-CA" makes it crash with the following error message:
[Code]....
Now, I'm retrieving the language value from a database and, since the information is used all over the web site, I cannot really change the data within the database.The following code is posted in the Default.aspx page, called by the master page.The function "siteSetLanguage" retrieves from the database the base language (EN/FR) and returns the value. Null values are checked for and if a null value is returned from the database, it defaults to EN.[Code]....
I do want to force UICulture to english as everything in the databases and external files are stored through the english canadian regional method. However, I've been trying to use .resx files using the above method, but to no avail.Needless to say, my language files don't seem to work no matter what I do.
I have an Label where I need to show the value 0.00 if the culture is Englidh and 0,00 if the Culture is french. I am using the following code but it does not work.
below is what I'd like to do (but i cant because cant convert source type string to target type 'System.DateTime'). I want to localize the account.LastUpdated value from DateTime to localized string and have it available to use in my view. Im getting the account.LastUpdated from a service, which I cant control. what I get back is what i get back. do i extend AccountsViewModel to have additional properties in AccountsViewModelFormatted? [Code]....
I am working on an ASP.net web application, the application need to display text in English, Chinese and Japanese based on the parameters passed, however the culture settings such as currency symbol, time and number format should remain as en-US locale.
My understanding about ASP.Net localization is a package deal, am I wrong? If I am right, the only way to do this is to roll my own solution?
Can I call Initialize Culture of every page from the Global.asax?
Every page looks at the query string of "?lang=##" and sets the language accordingly. Since all pages do this, is there a place where I can implement it once and all pages will load it?
My site has around 200 pages and I dont want to implement the code in everypage. Would take too long for maintenance and to implement. It would be more convinient if I could simply put it in a function that all pages call when loading.
I've used 3 languages on my site and I've also put 3 Image Buttons. The language image button that you click will allow that language to be seen on the site. What should I write for that command btn (btn1_command event)
but when I cllick language button, culture should change for all pages for only current user.other users can use different culture.how can I
I am now building the NerdDinner tutorial from asp.net/mvc.
The problem is that when posting back a created model the ModelState is not valid. The model has two double values that are being set from jscript(to values like 44.2).
I checked the ModelState values and the value Culture is "ro-RO" (I am from Romania) so I guess it expects values like "44,2". How can I ignore the culture,or change the validation?