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.
Related
I have used resource files for localization in design time support. The localized string will be retrieved for designer action items to be added in designer of a control. Here is the code which i used to get the current culture from the resource manager in design mode.
if (resourceManager != null)
{
CultureInfo currentUICulture = CultureInfo.CurrentUICulture;
if (resourceManager.GetResourceSet(currentUICulture, true, true) != null)
{
ResourceManager result = resourceManager;
return result;
}
}
and i have changed the current culture using below code in form level.
public Form1()
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");
CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
InitializeComponent();
}
My Issue - Changed culture for French is not retrieved at design time. Culture got is en-US all the time.
Does anyone know, how to change the culture to reflect at runtime in order to solve the above mentioned issue?
Regards,
Amal Raj
Consider these facts:
CultureInfo.CurrentUICulture returns current thread UI culture.
Your design-time in visual studio, is visual studio's run-time.
Constructor of your Form1 will not execute at design time. Its InitializeComponent methis will be just deserialized to initialize a an instance of its base class Form which is shown in VS designer.
Since your current thread is Visual Studio UI thread and it uses en-US in your system, so you will receive en-US in design time as current UI thread.
I need a few tips on how to change application launguage. (Windows 8.1)
So here is my code that I put under OnLaunched method, It gets the current preffered launguage. I am using Multilingual app toolkit. I have all the resource files.
But I have no idea what to do next.
var rootFrame1 = new Frame();
rootFrame1.Language = Windows.System.UserProfile.GlobalizationPreferences.Languages[0];
You have to set current CultureInfo properties in this way:
var culture = new CultureInfo("en-US");
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Some resources point to placing this code in Page constructor to react to your default language being changed
ResourceContext.GetForCurrentView().QualifierValues.MapChanged +=
(IObservableMap<string, string> sender, IMapChangedEventArgs<string> e) =>
{
ResourceManager.Current.DefaultContext.Reset();
};
Also, worth mentionig is that preferable method for changing language is setting Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride property.
This works not so good for Windows Phone 8.1, but some claim that this solved their issue on Windows 8.1.
I have a WPF application that I want it to be two languages. I duplicated my Resources.resx and built my two languages like this:
So when I first load my MainApplication I do this:
Properties.Resources.Culture = new CultureInfo("es-ES");
before the
InitializeComponent();
So everything is loaded in the desired language. Now I want to go the obvious step further, and I designed a Select language on my application:
Any idea on how to reload the interface for the different languages at execution time?
EDIT:
I found this link, and seems to work. But I have a problem. When I try to find the Resources x:key it launches an error... It says ResourceReferenceKeyNotFoundException. Go here to check my mistake.
You want to change the culture for the UI thread, this should work:
var culture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
I followed this interesting link.
I am setting the locale of my application using
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");
but my "Resource.en-GB.resx" is not loading. It works for en-US, but for en-GB completely ignores it and drops back to the default "Resource.resx" file.
Remove the configuration and should work.
[assembly: NeutralResourcesLanguage("en-GB")]
See the link http://msdn.microsoft.com/en-us/library/system.resources.neutralresourceslanguageattribute.aspx
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.