一共四种方式:
- Localization using built-in resources
- Resource keys
- Localization using ResourceManager
- Localization using custom localization manager
1.使用自带的语言包
具体做法:
在app.xaml.cs 里面添加:
Thread.CurrentThread.CurrentCulture = new CultureInfo("de"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
目前已经多语言话的有 English,German,Spanish,French,Italian,Dutch,Turkish,可惜没有Chinesization
2.使用Resource Keys
Telerik 中可以本地化的控件多数都有一个 localization ,具体可以到api里面去查找,这里我举例 RadDataPager
Key Value
RadDataPagerEllipsisString | ... |
RadDataPagerOf | of |
RadDataPagerPage | Page |
从上图我们可以看到我们要汉化的对象key值具体方法:新增一个类继承于 LocalizationManager,然后重写 GetStringOverride 方法具体做法:
public class CustomLocalizationManager : LocalizationManager { private IDictionary<string, string> dictionary; public CustomLocalizationManager() { this.dictionary = new Dictionary<string, string>(); //这里我只写了一个例子,你可以根据自己的需要填写 this.dictionary["RadDataPagerPage"] = "Page啊"; } public override string GetStringOverride(string key) { string localized; if (this.dictionary.TryGetValue(key, out localized)) { return localized; } else { return base.GetStringOverride(key); } } }
在你的窗体代码文件里面,添加一行代码:
public partial class MainWindow : Window { /// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public MainWindow() { //这里重新定义了Manager LocalizationManager.Manager = new CustomLocalizationManager(); InitializeComponent(); } }
3.Localization Using ResourceManager
在Demo中 的路径: TelerikUIforWPF2015Demos\Examples\GridView\Localization 已经包含此方法例子,这里就不再上传代码
4.Localization Using Custom Localization Manager
If you want to translate your controls to a language different from the default available ones, you will need to create a custom LocalizationManager. To do so, create a class that derives from LocalizationManager and override its GetStringOverride() method. The logic is pretty simple - you just have to create a switch statement and return the correct translation for each resource key, as shown below:
参考:
本地化:
API地址:
http://docs.telerik.com/devtools/wpf/controls/raddatapager/localization.html#resource-keys