cultureinfo

Change culture based on a link MVC4

与世无争的帅哥 提交于 2019-11-30 08:50:34
I have a curiosity related to culture change in MVC. I tried in 2 ways, but apparently I was wrong somewhere. In my Web.config I have : <globalization uiCulture="auto" culture="auto" /> This is how I tried to change the thread culture : <li>@Html.ActionLink("Eng", "ChangeCulture", "Home", new { lang="en-US"}, new { @class = "languageSelectorEnglish" })</li> First method I have the following controller : public void ChangeCulture(string lang) { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(lang); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);

When should I specify CurrentCulture or InvariantCulture and when should I leave it unspecified?

末鹿安然 提交于 2019-11-30 08:12:59
What is the best practice for specifying CurrentCulture or InvariantCulture and not specifying the culture at all? From what I have read, if you're doing serialization, for instance, you need InvariantCulture as a means of specifying a canonical representation of a data value. That's a relatively small percentage of culture-based string manipulations. I find it long, verbose, and ugly most of the time to specify it every time I do, say: var greeting = string.Format(CultureInfo.CurrentCulture, "Hello ", userName); However, my team recently turned FxCop on and now there's a push to always use

Double.Parse - Internationalization problem

痞子三分冷 提交于 2019-11-30 08:02:07
问题 This is driving me crazy. I have the following string in a ASP.NET 2.0 WebForm Page string s = "0.009"; Simple enough. Now, if my culture is Spanish - which is "es-ES" - and I try to convert the string to Double, I do the following: double d = Double.Parse(s, new CultureInfo("es-ES")); what I'd expect is 0,009. Instead, I get 9. I understand that .NET thinks it is a thousand separator, which in en-US is a comma, but shouldn't it take the culture info I'm passing to the parse method and apply

datetime.tostring month and day language

我是研究僧i 提交于 2019-11-30 06:55:54
问题 i have a list of email addresses of people that have different nationalities (for each person i have the iso code) when i send the email to all these people, in the text of the mail i need to to convert a datetime field to a string formatted in their specific culture. for this i'm doing CultureInfo ci = new CultureInfo(ISO); myStringDate = myDate.ToString(ci.DateTimeFormat.ShortDatePattern); and work perfect, but if i use LongDatePattern instead short, for displaying date like "Monday, 13

How to format the HH:mm:ss separators of a TimeSpan in a culture-aware manner?

二次信任 提交于 2019-11-30 03:51:37
问题 I'm working on an app that may be seen in many countries in the world. There are not many countries that show hours, minutes and seconds with something other than : as a seperator but there are a few and I want to make sure that times are formatted correctly for their region. DateTime is great at this but TimeSpan isn't. These snippets are from my immediate Window in Visual Studio 2010 using .Net 4 with my region set to Malayalam (India). The dateTime.Now call also reflects how time is shown

Best Practice - Format Multiple Currencies

こ雲淡風輕ζ 提交于 2019-11-30 00:21:01
What is best practice for the scenario listed below? We have an application which we would like to support multiple currencies. The software will respect the users locale and regional settings to dictate the correct number format, i.e. $10,000.00 or 10.000,00₴ etc. We would however like to be able to format different numbers based upon a currency ID (perhaps the three letter ISO4217 code). Our idea is to store a table in the database with each currency and then request from the user to select the currency symbol which will be used. The program will then format all numbers based upon the locale

DateTimeFormat.AbbreviatedMonthNames adding a dot at the end of month's name

[亡魂溺海] 提交于 2019-11-29 15:41:14
Last night we migrated our web services tier from physical Windows 2008 r2 to virtual Windows 2012. We are getting tons of events on ours logs about DateTime's invalid formats, strange as we double checked our regional settings. Long story short: CultureInfo.GetCultureInfo("es-MX").DateTimeFormat.AbbreviatedMonthNames Outputs (using LinqPad5): ene. feb. mar. on our new 2012 env while on 2008 ouptus: ene feb mar Our parsing is something like this: DateTime.Parse("18 ene 16",CultureInfo.GetCultureInfo("es-MX")) And while it worked wonders now it throws FormatException : The string was not

Execute task with the CurrentCulture set to the Task creator CurrentCulture

孤街醉人 提交于 2019-11-29 14:04:19
I've an application where we use Tasks. We also modified the cultureInfo(we use the EN-US language, but keep the date/number format), and we use .Net 4.0. The application has a lot of thread and task, and we have a factory for the creation of Task/Threads. For the thread, we have the following code, to ensure that every thread is launched with the correct CurrentCulture: //This is basically only the constructor, but it describe well how we create the Thread: public MonitoredThread(ThreadStart threadStart, string name, bool isBackground = false) { m_threadStart = threadStart; m_name = name; m

Why not all countries are presented in CultureInfo.GetCultures()?

こ雲淡風輕ζ 提交于 2019-11-29 13:29:17
I am using this standard code for populating list of countries: static void Main(string[] args) { List cultureList = new List(); CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures); foreach (CultureInfo culture in cultures) { try { RegionInfo region = new RegionInfo(culture.LCID); if (!(cultureList.Contains(region.EnglishName))) { cultureList.Add(region.EnglishName); Console.WriteLine(region.EnglishName); } } catch (ArgumentException ex) { // just ignore this continue; } } } I saw that some countries are missed. Just wondered what's the

Why doesn't DateTime.ToShortTimeString() respect the Short Time format in “Regional and Language Settings”?

岁酱吖の 提交于 2019-11-29 13:04:43
问题 I have run into an issue that is probably due to my mis-understanding of how the DateTime.ToShortTimeString() method works. When formatting time strings with this function, I was assuming that it would respect the "Short Time" setting in Windows 7's Format settings Control Panel -> Clock, Language and Region -> Region and Language -> Formats Tab. However .NET seems to select a short time format not based upon this setting but based upon the current culture: Region and Language -> Location ->