码迷,mamicode.com
首页 > 其他好文 > 详细

Telerik 控件本地化

时间:2016-08-22 19:57:32      阅读:777      评论:0      收藏:0      [点我收藏+]

标签:

一共四种方式:

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:

 

参考:

本地化:

http://docs.telerik.com/devtools/wpf/common-localization.html#localization-using-custom-localization-manager

API地址:

http://docs.telerik.com/devtools/wpf/controls/raddatapager/localization.html#resource-keys

Telerik 控件本地化

标签:

原文地址:http://www.cnblogs.com/maanshancss/p/5796704.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!