I have a webpage where I uses the App_LocalResources files, where I've translations for 2 languages.
This works really well. However, when I open my two pages I get a pretty strange problem. If I open the English version, my Danish URL is also English. If I open med Danish URL first, the English one is in Danish. If i CTRL+F5 it, it changes language.
You can see the result here:
- http://www.btcglobe.com/buybtc.aspx (English version)
- http://www.btcglobe.com/buybtc/da (Danish version)
This is really annoying, as it should load the appropriate language right away.
My code on the butbtc.aspx page is (I have also tried Page_Load):
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
SetupLanguage();
}
My SetupLanguage method is:
private void SetupLanguage()
{
if (!string.IsNullOrEmpty(CurrentLanguage))
{
if (CurrentLanguage == "da")
{
CultureInfo dkinfo = CultureInfo.CreateSpecificCulture("da-dk");
CultureInfo.DefaultThreadCurrentCulture = dkinfo;
CultureInfo.DefaultThreadCurrentUICulture = dkinfo;
Thread.CurrentThread.CurrentCulture = dkinfo;
Thread.CurrentThread.CurrentUICulture = dkinfo;
Page.Title = GetLocalResourceObject("PageTitleString").ToString();
return;
}
}
CultureInfo info = CultureInfo.CreateSpecificCulture("en-us");
CultureInfo.DefaultThreadCurrentCulture = info;
CultureInfo.DefaultThreadCurrentUICulture = info;
Thread.CurrentThread.CurrentCulture = info;
Thread.CurrentThread.CurrentUICulture = info;
}
My CurrentLanguage property is defined like this:
public string CurrentLanguage
{
get
{
var toolValue = Page.RouteData.Values["language"];
if (toolValue != null && !string.IsNullOrEmpty(toolValue.ToString()))
{
return toolValue.ToString();
}
return string.Empty;
}
}
If my route has any meaning, it is:
routes.MapPageRoute("Buy Bitcoins",
"buybtc/{language}",
"~/buybtc.aspx");