Reputation: 39
The culture of windows form application doesn't change, despite using the correct code (I think of course).
In the Program.cs file in the win form application I try to change the current culture from en-US to fa-IR and I use these codes:
CultureInfo culture = CultureInfo.CreateSpecificCulture("Fa-IR");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
But after running the program, nothing happened. The current culture is still en-US!. Let me also say this, I don't change the culture program anywhere else.
Upvotes: 0
Views: 383
Reputation: 1
public static void InitializePersianCulture() {
var culture = new CultureInfo("fa-ir");
var info = culture.DateTimeFormat;
var calendar = new PersianCalendar();
info.Calendar = calendar;
var field = typeof(CultureInfo).GetField("Calendar", System.Reflection.BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
field.SetValue(culture, "fa-ir");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.CurrentCulture.DateTimeFormat = info;
CultureInfo.CurrentUICulture.DateTimeFormat = info;
}
Upvotes: 0
Reputation: 39
I thought that after changing the culture of the system, the language of the system should change as well. While I was wrong. By adding the following code I was able to change the Windows language to Farsi.
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(culture);
Upvotes: 0