.Net Localization with Multiple Languages

I understand that when you set CurrentThread.CurrentUICulture like "da-DK" it will look for resource files in "da-DK" then "da" and then revert to invariant culture. This works well for desktop applications as operating systems are not usually multilingual. However, this is not required for websites.

Let's say I have a visitor whose browser insists that the user wants "da_DK", "de_DE" and "en_GB" ie Danish if it exists, then German and then English English as fallback.

Is there a way to accommodate this preference using .Net 4 localization?

And no, this is not a thought experiment. :)

EDIT

To be clear, the problem is not with the localization headers from the web request. The problem is setting CurrentThread.CurrentUICulture in such a way that it will check the resource files in order, not just check them.

Alternatively, you can check if CurrentUICulture has the appropriate resx files.

+3


source to share


1 answer


I think this is what you need:

HttpRequest.UserLanguages ​​()

Returns an array of user languages ​​in order of preference. It's probably a good idea to let them change whatever localization you apply against this information, however, unless their browser configuration accurately reflects what they really want.

Update:



To check if resources exist:

ResourceManager.GetResourceSet

You can set tryParents

to false here. The method will return null

if the resources do not exist. Then you can try the next preferred crop returned in the title.

0


source







All Articles