TimeSeparator for fo-FO culture in C# .net - c#

I've instantiated the CultureInfo class with fo-FO (Faroese Island) culture. However, CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator is showing as: (colon) not . (dot). How to fix this error?
Below is the code:
CultureInfo ci = new CultureInfo("fo-FO");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
Console.WriteLine(DateTime.Now.ToString());
output
26-06-2012 15:15:17
Surprisingly, Time stamp alone is not converted , but it did converted Date part.
By setting the CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator = "." will solve the problem. But we are supporting multiple culture so i dont think it is a good idea to set TimeSeparator.
any pointer at the right direction is greatly appreciated.

Related

AWS lambda C# core CultureInfo ToString issue

I am trying to change the format of ToLongDateString to be in my local culture (da-DK).
For now I am doing the following, and if it can be done in a better way, then it will be very appreciated:
CultureInfo cCulture = new CultureInfo("da-DK");
string dateTimeStr = freeSeat.FreeDate.ToLongDateString().ToString(cCulture);
This works as expected on my local development environment, but when I deploy it to AWS lambda, I just get the English culture format. I am pretty sure the issue is that in AWS the C# core code is running on Linux.
I hope someone can give me some input how to solve this.
The ToLongDateString method returns a string formatted according to the current thread culture. Calling ToString method later is useless.
Do it like this:
CultureInfo cCulture = new CultureInfo("da-DK");
string format = cCulture.DateTimeFormat.LongDatePattern;
string dateTimeStr = freeSeat.FreeDate.ToString(format, cCulture);

CultureInfo InvariantCulture necessary?

I have added one localisation for my resource file. ResGeneral.resx and ResGeneral.cs.resx. My computer has czech environment so even Invariant culture uses the .cs.resx file. The projects default culture is set to Invariant.
Then I added a combo box with options loaded from the SupportedLanguages enum, which changes the selected lang index in config, so next time program is launched, the culture is changed to the selected index.
public enum SupportedLanguages
{
Invariant = 0,
English,
Czech
}
public static void ChangeLang(int lang)
{
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
switch (lang)
{
case 1:
cultureInfo = new CultureInfo("en");
break;
case 2:
cultureInfo = new CultureInfo("cs");
break;
}
CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = cultureInfo;
}
How should I approach this?
Can I specify that the clean .resx (en) is to be used with invariant always?
Is there reason to even use Invariant or can I set the default to "en"? Project owner fears that some machines might not have "en" culture installed, but I haven't found any info about that. Is that possible?
Is this even a problem? So what it auto uses Czech, if a German user launches it, I dont have a .de file, it uses the clean .resx and he sees english
What do you think? Thanks for answers.

Chinese localization does'nt work, shows english always

I'm working on WPF application and I have localized resources (en,fr,zh) in .resx files. Following test code is used to display the localized string. It works fine for english, french but fails in Chinese. In chinese it shows english text only. I tried using all variants of Chinese culture such as zh-CN, zh-Hans, zh-Hant and the "old" zh-CHS, zh-CHT but no luck.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// CultureInfo culture = CultureInfo.CreateSpecificCulture("zh-CHT");
CultureInfo culture = new CultureInfo("zh-CN");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
MessageBox.Show(Properties.Resources.address);
}
}
Resource fiels are named as Resources.resx, Resources.fr.resx, Resources.zh.resx
Any help would be appreciated,
Rajesh
It's because zh-CHS is Neutral Culture.
In ASP.NET 2.0 it\s not possible to set CurrentCulture to Neutral Culture like zh-CHS.
But you can set it to a Specific Culture like zh-CN.
If you need to use a Neutral Culture, like zh-CHS, you can set CurrentUICulture property instead. CurrentUICulture is the one that is responsible for getting text from Resource files.
CurrentCulture is responsible for Number, DateTime and Currency formatting.
BTW, in ASP.NET 4.0 you can set CurrentCulture to Neutral Culture, but not in v2.0.
In my code, where the site could run on either .NET 2 or .NET 4 I do it like this:
public static void SetCurrentCulture(string cultureName)
{
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName);
}
catch (Exception)
{
// Ignore if exception happens: In ASP.NET 2.0 setting CurrentCulture = Neutral culture (like zh-CHS) throws an exception:
// Culture 'zh-CHS' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture.
}
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);
HttpCookie cultureCookie = new HttpCookie("CultureCookie", cultureName);
HttpContext.Current.Response.Cookies.Set(cultureCookie);
}
I had a similar problem. The current culture was set at some point on start to zh-CN but was overwritten by English. Solution in my case- to install the Chinese language from Windows settings.

FAST ESP 5.3 SP4 - Turkish tr-tr fails

Im using dotnet search api for FAST ESP 5.3. Everything works fine except for culture tr-tr i.e cultureid=1055.
Getting exception as "Error parsing information" on executing the below line
qr = view.Search(query);
Can anybody please throw some light on this issue?
What & where to check whether my installed FAST ESP has turkish(tr-tr) support?
Your help is highly appreciated.
Thanks,
Arun
Finally resolved the issue as below through MS support:
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
qr = view.Search(query);
Thread.CurrentThread.CurrentCulture = originalCulture;

Changing the CurrentUICulture at runtime using locbaml method

Using the locbaml method, I've created a new resource dll and am trying to programatically change the CurrentCulture and CurrentUICulture on the fly, but it doesn't seem to be working.
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ar-SA");
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
Am I missing something obvious?
As far as I know, using the 'locbaml' metod you cannot switch languages on the fly, thus you have to setup Current[UI]Culture appropriately if needed before showing any UI.

Categories

Resources