in my project i have two supported languages (german – “de”, and english – “en”)
I have resource files like: Home.aspx.de.resx, Home.aspx.en.resx, Home.aspx.resx
is it possible to read dynamicly which languages are supported in current webproject?
I dont want to validate it manually if they are just “de” and “en” like I do in follow code:
if (langName != "en" || langName != "de")
{
ci = new CultureInfo("en");
this.Session["Culture"] = ci;
}
I would like to get access of webproject languages like: CultureInfo.(Who knows)...
If I will add a new language, f.E. “fr” I need again to add it manually into my logic.
my Application_AcquireRequestState method look like this:
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
if (HttpContext.Current.Session != null)
{
//Create culture info object
CultureInfo ci = (CultureInfo)this.Session["Culture"];
//Checking first if there is no value in session
//and set default language
//this can happen for first user's request
if (ci == null)
{
//Sets default culture to english invariant
string langName = "en";
//Try to get values from Accept lang HTTP header
if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length != 0)
{
//Gets accepted list
langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
}
if (langName != "en" || langName != "de")
{
ci = new CultureInfo("en");
this.Session["Culture"] = ci;
}
else
{
ci = new CultureInfo(langName);
this.Session["Culture"] = ci;
}
}
//Finally setting culture for each request
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
}
Can you try to load the culture for the specified language and if it does not exist then load the default? I have done that in one of my web apps. You would use something like this in the base page.
If you want to read available cultures from the server you can use
CultureInfo.GetCultures( CultureTypes.AllCultures );
and CultureInfo.GetCultures( CultureTypes.UserCustomCulture );