cultureinfo

Change culture based on a link MVC4

跟風遠走 提交于 2019-11-29 12:42:50
问题 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

How to convert culture specific double using TypeConverter?

安稳与你 提交于 2019-11-29 11:58:33
I have a problem with the TypeConverter class. It works fine with CultureInvariant values but cannot convert specific cultures like English thousands separators. Below is a small test program that I cannot get to work. Here's the problem :) - ConvertFromString throws an exception with the following message "2,999.95 is not a valid value for Double." and with the inner exception "Input string was not in a correct format." . using System; using System.Globalization; using System.ComponentModel; class Program { static void Main() { try { var culture = new CultureInfo("en"); var typeConverter =

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

拟墨画扇 提交于 2019-11-29 11:16:52
问题 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,

DateTime.TryParseExact() rejecting valid formats

瘦欲@ 提交于 2019-11-29 10:30:50
问题 I'm parsing a DateTime value in an ASP.NET WebForms page and the date string keeps getting rejected by the DateTime.TryParseExact() method even though it clearly matches one of the supplied format strings. It seems to fail on my development machine at home but work on the production server, so I am thinking of local date settings being involved, but this error occurs even when I supply an IFormatProvider (CultureInfo) object as a parameter Here's the code: DateTime startDate; string[] formats

How to set Silverlight CurrentUICulture/CurrentCulture correctly?

一笑奈何 提交于 2019-11-29 10:25:35
I'm working on a SL5 app with C# and I'm looking to internationalize it. I found the following to set the UI culture: var culture = new CultureInfo(Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName); Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; Some controls like the DatePicker seem to pick this up. If I format any datetime by using the 'd' format string, I still get the default format "M/dd/yyyy" however. Exactly how does SL interpret culture and how can I set it correctly for the entire application? Thanks UPDATE: Found the

Finding weekend days based on culture

白昼怎懂夜的黑 提交于 2019-11-29 09:38:38
Is there a way to find the days that constitute a weekend or workweek based on different cultures using the .NET framework? For example, some Muslim countries have a workweek from Sunday through Thursday. The only thing i know is how to get the day the week starts. Perhaps this can help: CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek from System.Globalization , perhaps you find in this package something. There are several Calendar-Classses like JulianCalendar, HebrewCalendar and so on. It could be possible to find there what you want. No one had a solution for this so I wrote one.

Why do I get, “Culture is not supported” and What, if Anything, Should I Do about it?

冷暖自知 提交于 2019-11-29 09:27:20
I have a breakpoint on the "return" line here: [HttpGet] [Route("api/Test/{id1}/{id2}")] public NRBQEntity GetTestMessage(String id1, String id2) { return NRBQClient.GetTestMessage(id1, id2); } Although it does not crash the app, when I reach that point, I get, " Exception:Thrown: "Culture is not supported." (System.Globalization.CultureNotFoundException) A System.Globalization.CultureNotFoundException was thrown: "Culture is not supported." " Which culture is trying to be supported, why is it not supported, and what, if anything, should I do to support the culture? UPDATE Answer to sphanley:

Formatting numbers in different cultures

爱⌒轻易说出口 提交于 2019-11-29 07:58:11
Assuming an invariant culture , is it possible to define a different group separator in the format - than the comma? Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Console.WriteLine(String.Format("{0:#,##0}", 2295)); Output: 2,295 Desired output: 2.295 The invariant culture is a requirement because currencies from many different locales are being formatted with format strings, that have been user defined. Ie for Denmark they have defined the price format to be "{0:0},-", while for Ireland it might be "€{0:#,##0}". When you have different format strings, this does not mean

How to change Application Culture in wpf?

允我心安 提交于 2019-11-29 07:47:14
Here is my code. double value = double.Parse(Utility.GetParamValueOrDefault(omRecord.paramList[i].value, "0"),CultureInfo.CurrentCulture); this is the error i'm getting FormatException: Input string was not in a correct format i have read some threads of StackOverFlow saying i need to add into main() of my WPF application the following code. Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata( XmlLanguage

Double.Parse - Internationalization problem

半腔热情 提交于 2019-11-29 05:36:54
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 the correct format to the conversion? If I do double d = 0.009D; string formatted = d.ToString(new