Last post Mar 15, 2008 12:23 PM by email@example.com
Mar 13, 2008 06:07 PMfirstname.lastname@example.org|LINK
The ASP.NET, when using auto Culture auto UICulture does set the properties to the values for which it has not resources. I would like to ask how can I found, which resources are being used?
Have a Default.aspx set to auto:fr
In App_LocalResources, have
Now, the client's browser preffers Spanish language, but since there is no such resource, the result is:
Page.Culture / Page.UICulture set to Spanish (this could be a bug from some point of view)
Resources being French (reading the fallback resource - Default.aspx.fr.resx).
The question is, how do I from code find out, that the ASP.NET is using French resources on the Page?
Mar 13, 2008 07:12 PM|farazsk11|LINK
If you want to know the current culture which is assinged to the current thread you can use this
Mar 13, 2008 08:21 PMemail@example.com|LINK
thanks for reply but unfortunately this is not the trick...
I want to get the culture which ASP.NET choosed to take resources from. This is not the user's preffered language (Spanish) neither thread culture (which is set from the user's prefferd language by the framework, isn't it?).
Mar 14, 2008 07:14 AM|farazsk11|LINK
Well usually the developer itself set the culture according to the user prefered language. More over you should be having one default culture which will work when none of the listed cultures will match user's preference. You can also look at this article
written by Vivek to implement localization
System.Thread.CurrentThread.CurrentCulture will always give you the culture being used.
Mar 14, 2008 07:57 AMfirstname.lastname@example.org|LINK
So you suggest me that I should not use the ASP.NET mechanism and create one myself? In other words, that the answer is not possible. [:^)]
Well could you point me to the method, which actually sets the culture in the framework (when using Culture="auto:fr")? So that I could override or create one myself...
I can't find it, the Page.InitializeCulture is virtual and I haven't find anyone who would call it...
Mar 14, 2008 08:27 AM|farazsk11|LINK
Why don't you do like this Culture ="auto"
and have these cultures
Default.aspx.resx 'a default culture when ASP.net could not find any matched cultureit will automatically takes this culture. Now its upto you in which language you want to create a default culture.
Default.aspx.de.resx 'page with german
Default.aspx.fr.resx 'page with french
I didn't said that do it manually by default culture I meant something like what I have said above. by the way I found an article which can help you out a bit more further.
Mar 14, 2008 08:56 AMemail@example.com|LINK
Default.aspx.resx 'a default culture when ASP.net could not find any matched cultureit will automatically takes this culture
I'd like to, but how do I find which culture it has taken?
Mar 15, 2008 01:54 AM|farazsk11|LINK
You can also use the above function on an ASP.NET page if your localization focus is more narrow. When using ASP.NET pages realize that any changes to culture settings should be applied in the special InitializeCulture method which you
need to override.
Mar 15, 2008 02:23 AM|farazsk11|LINK
Suppose you have this hierarchy
Default.aspx.en-GB.resx 'for UK english
Default.aspx.en-US.resx 'for US english
Default.aspx.fi-FI.resx 'for Finish language
Default.aspx.resx 'If none of the languages found use default
ASP.Net Culture:auto will check user's browser prefered language if its en-GB or en-US or fi-FI it will take the respective resource file and display the text but if it is not able to find the resource as per the prefered language it will move on to Default.aspx.resx
Mar 15, 2008 05:50 AMfirstname.lastname@example.org|LINK
I really appreciate your help. I've done lot of reading, debugging and reflectoring before my every post here.
My problem is still the same:
if its en-GB or en-US or fi-FI it will take the respective resource file and display the text but if it is not able to find the resource as per the prefered language it will move on to Default.aspx.resx
What I've found so far:
- If you put culture auto:fr-FR to the web.config file, the thread culture is set even before Application.BeginRequest. Do you know where exactly?
- If you put culture auto:fr-FR to the page declaration, the
Page.Culture = "auto:fr-FR" is generated into BuildControlTree method in FrameworkInitiliaze and immediately after this, the InitializeCulture is called.
- Assigning "auto:fr-FR" to the Page.Culture sets the fr-FR culture to the current thread. No checking, no fallback, the thread's culture during processing the request is just fr-FR.
So from this I would think, that every fallback occurs inside the "get resource" function, but I still can't find where... and it seems that there is no way finding out which culture is chosen.
Mar 15, 2008 08:03 AM|farazsk11|LINK
Well ASP.NET initializes the language settings by examining HTTP headers sent by the browsers and when it couldn't find any valid match it will move on to the default culture (as we have discussed earlier). The language then assigned to the current thread
on InitializeCulture, the page life cycle is designed in way that InitializeCulture will be called everytime before Load event just to make sure if any of the rendered control require to be changed according to the assigned culture.
Another article you can find here :)
Mar 15, 2008 09:48 AMemail@example.com|LINK
Well ASP.NET initializes the language settings by examining HTTP headers sent by the browsers and when it couldn't find any valid match it will move on to the default culture (as we have discussed earlier).
I understand this process, and can say what would be selected if you give me the culture and list of files available. But I'd love to know how do I find it during runtime? I can get the preffered language from the accept-language header, but how with the
available files? I don't want to hardcode which resource languages are available as this would require changing the code every time I want to add a new language...
Mar 15, 2008 12:04 PMfirstname.lastname@example.org|LINK
Okay, bad news here.
The only ASP.NET softcore thing is to force the applications to add special key to each resource file, which would contain the corresponding culture name, like
in Default.aspx.en-us.resources, have ThisCulture: "en-US",
in Default.aspx.fr-fr.resources, have ThisCulture: "fr-FR",
and then use GetLocalResourceObject to find out what's going on.
Otherwise, it's the ResourceManager's task to get the appropriate resource and I'm moving to the .NET Base Class Library forum to find out if it is possible to get the used language, or at least list of available languages.
Then I'd probably have to use reflection to get the ResourceManager for current page. :(
Thanks going through with me and further ideas still welcomed ;-)
Mar 15, 2008 12:23 PMemail@example.com|LINK
Well, there are two (and not very nice) ways how to enumerate the languages (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1389766&SiteID=1).
Plus, this has the disadvantage that you actually don't know what the default culture is.
So I have to go with the ThisCulture method...