Question about Globalization/Cultureinfo
-
Greetings all. I'm currently not using much localization seening as most of my webpages so far has been limited to one or two languages, however - I'm constantly trying to improve myself, and using the .net inbuilt globzliation seems to be a good way to go forth. So currently, I've started using it for numberformat and dateformat and the "two letter iso code". However, I've not really been able to find much information about how much overhead I bring into my webpages based on this. The way I do this is that I set the globalization infomation (cultureinfomation) in my global.asax, in the Application_BeginRequest event. Something along this line.... (vb.net code)
Dim objCultureInfo As Globalization.CultureInfo = New System.Globalization.CultureInfo("da-DK") Dim objDateTimeFormat As New Globalization.DateTimeFormatInfo objDateTimeFormat.ShortDatePattern = "dd-MM-yyyy" objCultureInfo.DateTimeFormat = objDateTimeFormat Dim objNumberFormat As New Globalization.NumberFormatInfo objNumberFormat.CurrencySymbol = "kr. " objNumberFormat.CurrencyDecimalDigits = 2 objNumberFormat.CurrencyDecimalSeparator = "," objNumberFormat.CurrencyGroupSeparator = "." objNumberFormat.NumberDecimalSeparator = "," objNumberFormat.NumberGroupSeparator = "." objCultureInfo.NumberFormat = objNumberFormat System.Threading.Thread.CurrentThread.CurrentCulture = objCultureInfo
(this is just some misc. code, it might not be real effective or anything, but that is secondary concern at the moment) Granted, the functionality of what I use it for is (currently) limited, but somehow it rubs me the wrong way having to do this same calculations each time a page is requested. I tried tieing this culture information into the session (Session_OnStart), but it gives me some unexpected results, most often that I only get the result I wants the first time, and afterwards it reset to default. Does anybody know of/have any ressources which discuss the overhead of Globlization and how to use it to best effect? Or am I on the right path with this, and using it in the "proper" event? Advice/comments? With regards. --------------------------- 127.0.0.1 - Sweet 127.0.0.1 -
Greetings all. I'm currently not using much localization seening as most of my webpages so far has been limited to one or two languages, however - I'm constantly trying to improve myself, and using the .net inbuilt globzliation seems to be a good way to go forth. So currently, I've started using it for numberformat and dateformat and the "two letter iso code". However, I've not really been able to find much information about how much overhead I bring into my webpages based on this. The way I do this is that I set the globalization infomation (cultureinfomation) in my global.asax, in the Application_BeginRequest event. Something along this line.... (vb.net code)
Dim objCultureInfo As Globalization.CultureInfo = New System.Globalization.CultureInfo("da-DK") Dim objDateTimeFormat As New Globalization.DateTimeFormatInfo objDateTimeFormat.ShortDatePattern = "dd-MM-yyyy" objCultureInfo.DateTimeFormat = objDateTimeFormat Dim objNumberFormat As New Globalization.NumberFormatInfo objNumberFormat.CurrencySymbol = "kr. " objNumberFormat.CurrencyDecimalDigits = 2 objNumberFormat.CurrencyDecimalSeparator = "," objNumberFormat.CurrencyGroupSeparator = "." objNumberFormat.NumberDecimalSeparator = "," objNumberFormat.NumberGroupSeparator = "." objCultureInfo.NumberFormat = objNumberFormat System.Threading.Thread.CurrentThread.CurrentCulture = objCultureInfo
(this is just some misc. code, it might not be real effective or anything, but that is secondary concern at the moment) Granted, the functionality of what I use it for is (currently) limited, but somehow it rubs me the wrong way having to do this same calculations each time a page is requested. I tried tieing this culture information into the session (Session_OnStart), but it gives me some unexpected results, most often that I only get the result I wants the first time, and afterwards it reset to default. Does anybody know of/have any ressources which discuss the overhead of Globlization and how to use it to best effect? Or am I on the right path with this, and using it in the "proper" event? Advice/comments? With regards. --------------------------- 127.0.0.1 - Sweet 127.0.0.1The overhead of globalization is quite small. Whenever a conversion is made, globalization is used anyway, only CurrentThread.CurrentCulture is used if you don't specify a culture or format provider. The complexity in globalization is in the methods used for conversion, the CultureInfo object itself is quite small. A new CultureInfo object is created for each thread, e.g. each page request, that's why you can't successfully set in Session_OnStart. You can set the culture in Application_BeginRequest, or if you only use it on some pages you can put the code in a class and call it from the pages that need it. --- b { font-weight: normal; }
-
The overhead of globalization is quite small. Whenever a conversion is made, globalization is used anyway, only CurrentThread.CurrentCulture is used if you don't specify a culture or format provider. The complexity in globalization is in the methods used for conversion, the CultureInfo object itself is quite small. A new CultureInfo object is created for each thread, e.g. each page request, that's why you can't successfully set in Session_OnStart. You can set the culture in Application_BeginRequest, or if you only use it on some pages you can put the code in a class and call it from the pages that need it. --- b { font-weight: normal; }