軟件添加語言包

若是開發的語言想用多語言的話能夠經過添加語言包的方式切換不一樣的語言。app

1. 加載語言包ide

 
/// <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. 語言包的獲取spa

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

3. 語言包的建立code

<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>
相關文章
相關標籤/搜索