【问题标题】:WPF Internationalization using .resx files and updating locale at runtime使用 .resx 文件并在运行时更新语言环境的 WPF 国际化
【发布时间】:2019-03-05 15:54:39
【问题描述】:

有人可以展示使用 .resx 文件为每个语言环境国际化 2 种不同语言的 WPF 应用程序的最佳解决方案吗? 我还希望能够动态切换语言环境并在运行时更改 xaml 文本组件的内容

【问题讨论】:

    标签: wpf internationalization runtime locale resx


    【解决方案1】:

    这里是一个链接,它逐步解释了您需要什么。 参考: 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" />
    

    后面的代码:

        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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-02
      • 2012-10-22
      • 1970-01-01
      • 2013-05-24
      相关资源
      最近更新 更多