软件添加语言包

如果开发的语言想用多语言的话可以通过添加语言包的方式切换不同的语言。

1. 加载语言包


/// <summary>
/// 语言包选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LangList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  try
    {
         LoadLanguageFile("pack://application:,,,/CustomLanguage;component/Chinese.xaml");
         LanguageChanged = false;

         UpdateLanguageHandler?.Invoke();

         if (CurrentDevice?.DeviceProtocol != null)
               CurrentDevice.DeviceProtocol.UpdateDisplayItems();

               UavProtocol protocol = CurrentDevice?.DeviceProtocol;
               m_frameGoogle.FreshLatLngJmpDes();
     }
     catch (Exception ex)
     {
          LogHelper.ErrorLog(LogStr, ex);
     }
}

void LoadLanguageFile(string languagefileName)
{
      Application.Current.Resources.MergedDictionaries[0] = new ResourceDictionary()
      {
           Source = new Uri(languagefileName, UriKind.RelativeOrAbsolute)
       };
}
View Code

 

2. 语言包的获取

strMsg = (string)FindResource("PUB_STR_IS_REMOVE_CURRENT_DEVICE");

3. 语言包的创建

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib">
    <s:String x:Key="WatchWord">智引未来,创新无限</s:String>
</ResourceDictionary>

  

posted on 2019-11-01 17:00  清修客  阅读(825)  评论(0)    收藏  举报

导航