Reputation: 2014
I have a web forms site that needs to be localized. I mean, it is localized, I just need to set the right language according to the domain. Something like:
protected override void InitializeCulture()
{
var i = Request.Url.Host.ToLower();
var domain = i.Substring(i.Length - 2, 2);
if (domain == "se")
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("sv-SE");
Thread.CurrentThread.CurrentUICulture = new
CultureInfo("sv-SE");
}
else if (domain == "dk")
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("da-DK");
Thread.CurrentThread.CurrentUICulture = new
CultureInfo("da-DK");
}
}
My first question is: Do I really have to call InitializeCulture()
on every single page for the right resources the be loaded?
Second question. I also have some global resources. If yes to first question, will they be set correctly as well?
Ps. uiCulture="auto"
and enableClientBasedCulture="true"
in webconfig will not be sufficient (long story).
Upvotes: 3
Views: 4345
Reputation: 2844
If the language in the application does not differ on a page to page basis then it make sense to reuse the code as answered here. Or better still use http module explained here.
Upvotes: 2
Reputation: 15400
Yes. What you are doing complies with the Microsoft-recommended method. And since your example determines what language to use based on the URL, then each page request may require a different language, so you just couldn't avoid doing this for each individual page.
As per your second question, yes, all resource loading depends on CurrentCulture
. So both local and global resources will be affected by your culture initialization.
Upvotes: 3