Hi, i would like to make my page multilanguage, so i have made resource files and do smth like that in my Global.asax
public static CultureInfo ResolveCulture()
{
string[] languages = HttpContext.Current.Request.UserLanguages;
if (languages == null || languages.Length == 0)
return null;
try
{
string language = languages[0].ToLowerInvariant().Trim();
return CultureInfo.CreateSpecificCulture(language);
}
catch (ArgumentException e)
{
return null;
}
}
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
CultureInfo cui = ResolveCulture();
if (cui.TwoLetterISOLanguageName != "pl" && cui.TwoLetterISOLanguageName != "en")
{
cui = new CultureInfo("pl-PL");
}
System.Threading.Thread.CurrentThread.CurrentUICulture = cui;
System.Threading.Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(cui.TwoLetterISOLanguageName);
}
}
But first of all that method is called about 3 times per request(when i go to .../create etc.), so i do not know if thats good solution, because of perfomance and also it doesnt work on IE9- it is called more times then in other browsers plus in some call
ResolveCulture() returns null because string[] languages = HttpContext.Current.Request.UserLanguages is null.
Should i try to fix this(how? i find smth like setting AutoEventWireup to False but dont know if its good idea ) or mby try to implement my culture recognition mechanism in other way(again how?)
it works automaticly in mvc :) just put globalization in web.config make your resource files in the global resources files and it works
so main resource would be like resource.resx, dutch would be resource.nl-NL.resx, german like resource.de-DE.resx, etc... the only thing you might want to add is a language picker or something instead of automatic globalization
My resources are named: Resource.resx and Resource.pl.resx and they are in separate project from my Web project(but in one solution) and it doesnt work for me(on browser set to Polish language(pl) it get Resource.resx not Resource.pl.resx )
politech
Member
52 Points
63 Posts
globalization/internalization with resources
Jul 04, 2012 05:51 AM|LINK
Hi, i would like to make my page multilanguage, so i have made resource files and do smth like that in my Global.asax
public static CultureInfo ResolveCulture() { string[] languages = HttpContext.Current.Request.UserLanguages; if (languages == null || languages.Length == 0) return null; try { string language = languages[0].ToLowerInvariant().Trim(); return CultureInfo.CreateSpecificCulture(language); } catch (ArgumentException e) { return null; } } protected void Application_AcquireRequestState(object sender, EventArgs e) { CultureInfo cui = ResolveCulture(); if (cui.TwoLetterISOLanguageName != "pl" && cui.TwoLetterISOLanguageName != "en") { cui = new CultureInfo("pl-PL"); } System.Threading.Thread.CurrentThread.CurrentUICulture = cui; System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cui.TwoLetterISOLanguageName); } }But first of all that method is called about 3 times per request(when i go to .../create etc.), so i do not know if thats good solution, because of perfomance and also it doesnt work on IE9- it is called more times then in other browsers plus in some call ResolveCulture() returns null because string[] languages = HttpContext.Current.Request.UserLanguages is null.
Should i try to fix this(how? i find smth like setting AutoEventWireup to False but dont know if its good idea ) or mby try to implement my culture recognition mechanism in other way(again how?)
Thx,
global
sp00k
Participant
1916 Points
435 Posts
Re: globalization/internalization with resources
Jul 04, 2012 06:32 AM|LINK
it works automaticly in mvc :) just put globalization in web.config make your resource files in the global resources files and it works
so main resource would be like resource.resx, dutch would be resource.nl-NL.resx, german like resource.de-DE.resx, etc... the only thing you might want to add is a language picker or something instead of automatic globalization
more information here....
http://www.codecapers.com/post/How-to-Localize-an-ASPNET-MVC-Application.aspx
bkis1112
Participant
1061 Points
226 Posts
Re: globalization/internalization with resources
Jul 04, 2012 08:36 AM|LINK
refer this link: http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx
Trần Lê Thành Trung
politech
Member
52 Points
63 Posts
Re: globalization/internalization with resources
Jul 04, 2012 12:36 PM|LINK
I set
<system.web>
<globalization culture="auto" uiCulture="auto" />
...
</system.wb>
My resources are named: Resource.resx and Resource.pl.resx and they are in separate project from my Web project(but in one solution) and it doesnt work for me(on browser set to Polish language(pl) it get Resource.resx not Resource.pl.resx )
CPrakash82
All-Star
18314 Points
2851 Posts
Re: globalization/internalization with resources
Jul 04, 2012 02:08 PM|LINK
Application's AcquireRequestState event fire on every request even for static resources. The best way to do it is web.config file settings.
Thanks,
global
politech
Member
52 Points
63 Posts
Re: globalization/internalization with resources
Jul 04, 2012 05:56 PM|LINK
refere to my previous post please