Can someone show the best solution to internationalize a WPF application for 2 different languges using .resx files for each locale. I would also like the ability of switching locales at the fly and changing the content of xaml text components at runtime
1 Answers
1
votes
here is a link which explains step by step on what you need. reference: http://www.thebestcsharpprogrammerintheworld.com/2017/07/26/localizing-a-wpf-program-using-c/
XAML:
<Label Content="{x:Static properties:Resources.LabelAddress}" Height="28" HorizontalAlignment="Left" Margin="35,103,0,0" Name="labelAddress" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="119,26,0,0" Name="textBoxFName" VerticalAlignment="Top" Width="152" />
Code behind:
using System.Globalization;
using System.Configuration;
Properties.Resources.Culture = new CultureInfo(ConfigurationManager.AppSettings["Culture"]);
//To change the locale in runtime you need to set
public static void SetLanguage(string locale)
{
if (string.IsNullOrEmpty(locale)) locale = "en-US";
Properties.Resources.Culture= new System.Globalization.CultureInfo(locale);
}
AppConfig.cs:
<appSettings>
<add key="Culture" value="zh-CN" />
</appSettings>