wpf WPF应用程序本地化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12584781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Localization of WPF application
提问by TheJoeIaut
We are developing a WPF Application which should support multiple Languages. Since we have to support some languages none of the development team knows, we agreed on allow the users (Administrators) to enter the texts for those languages. What is the best way to do so ?
我们正在开发一个应该支持多种语言的 WPF 应用程序。由于我们必须支持一些开发团队都不知道的语言,因此我们同意允许用户(管理员)输入这些语言的文本。这样做的最佳方法是什么?
回答by Aghilas Yakoub
You can follow these steps
您可以按照以下步骤操作
1 Creating the Resource Files
1 创建资源文件
Add this file StringResources.xaml to Ressources directory. Sample is here:
将此文件 StringResources.xaml 添加到 Ressources 目录。样品在这里:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="close">Close</system:String>
</ResourceDictionary>
You can create several files, one for each language.
您可以创建多个文件,每种语言一个。
2 Adding the Resource (Call this when you start your application)
2 添加资源(启动应用程序时调用)
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
switch (Thread.CurrentThread.CurrentCulture.ToString())
{
case "en-US":
dict.Source = new Uri("..\Resources\StringResources.xaml", UriKind.Relative);
break;
case "fr-CA":
dict.Source = new Uri("..\Resources\StringResources.fr-CA.xaml", UriKind.Relative);
break;
default :
dict.Source = new Uri("..\Resources\StringResources.xaml",UriKind.Relative);
break;
}
this.Resources.MergedDictionaries.Add(dict);
}
3 Using the Resource, like this -
3 使用资源,像这样 -
<Button
x:Name="btnLogin"
Click="btnLogin_Click"
Content="{DynamicResource login}"
Grid.Row="3"
Grid.Column="0"
Padding="10" />
回答by SvenG
I have made very good experience with the WPFLocalizationExtension
我对WPFLocalizationExtension有很好的体验
It comes with loads of functionality (e.g binding to localized image ressources depending on the language) and the best: It's free. There are also some resx edit tools around that allow you to load and edit your resx localization files.
它带有大量的功能(例如根据语言绑定到本地化的图像资源)和最好的:它是免费的。还有一些 resx 编辑工具允许您加载和编辑您的 resx 本地化文件。

