A good memory as bad written. Next record, since there need to be able to see.
All Developer Express .NET product has localized resources, such as button properties, attributes describe the controls, menu items, and confirm the wrong information and so on, all of these resources strings can easily be translated into various languages.
Speaking before and after look at the following picture:
Speaking before
Speaking after
How to achieve the above finished it? Dev conclude finished in three general forms: one is to use resources already finished good package; is to use local object class, finished with a code; there is the bundle and the code in combination. Let's do a detailed explanation on the implementation of these three cases and their respective advantages and disadvantages.
First, the use of resources package finished
First, how to use the resource package finished
First, you need to download the existing resource pack (provided by the Resource Kit Hui Chinese are science and technology, the download link address www.devexpress.com/kb=A421 ) finished the required resources zh-CHS Chinese (Simplified), zh- CN China (Chinese), zh-TW Chinese (Taiwan) copied to the execution directory. Use CurrentThread.CurrentUICulture loads the resource bundles. Referring code is as follows:
Code
1static void Main()
2{
3 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
4 Application.Run(new Form1());
5}
6
Second, how to modify the Resource Kit
Dev has a resource bundle with the same strong name key component file StrongKey.snk. If you want to compile the resource file, you can do it, as long as you have a complete component source code, re-assign a strong name key file, get their own StrongKey.snk. Specific implementation can be found in MSDN Library.
1, from the installation StrongKey.snk copy source code directory "Program Files" Developer Express .NET vX.Y "Sources" DevExpress.Key "to the current resource package DevExpress.Key directory. (VX.Y current version Installation )
2, open the variable resource pack Localization.sln project, to be finished to find out the properties of localized according to the method mentioned below, of course, if you buy the source code can also view the source code inside the class Localization localization methods listed to you need to realize localization.
3, regenerate the resource file, then the corresponding Dll in DevExpress.DLL clip file.
Note: The use of existing resources localization package easy to use, but also the use of the most common, but the resources currently finished incomplete, they tend to modify the resource package. However StrongKey.snk strong name key file business can not provide, because that is their signature. If you recompile the package in the absence of their own resources StrongKey.snk circumstances, it would only be able to modify their own good resource file by means businesses to help re-compile.
Second, use local object localization
Dev each component has its corresponding or library-based localization. In fact, the localization process is very simple, first create a subclass inherits the base class corresponding to the localized (see table below), overloaded GetLocalizedString method, this method should return a specific string resource identifier string. Second, it is to call the class, instantiate static Active property corresponds to the class.
Control
Class
XtraBars
DevExpress.XtraBars.Localization.BarLocalizer
XtraCharts
DevExpress.XtraCharts.Localization.ChartLocalizer
XtraEditors Library
DevExpress.XtraEditors.Controls.Localizer
XtraGrid
DevExpress.XtraGrid.Localization.GridLocalizer
XtraLayout
DevExpress.XtraLayout.Localization.LayoutLocalizer
XtraNavBar
DevExpress.XtraNavBar.NavBarLocalizer
XtraPrinting Library
DevExpress.XtraPrinting.Localization.PreviewLocalizer
XtraPivotGrid
DevExpress.XtraPivotGrid.Localization.PivotGridLocalizer
XtraReports
DevExpress.XtraReports.Localization.ReportLocalizer
XtraScheduler
DevExpress.XtraScheduler.Localization.SchedulerLocalizer
XtraSpellChecker
DevExpress.XtraSpellChecker.Localization.SpellCheckerLocalizer
XtraTreeList
DevExpress.XtraTreeList.Localization.TreeListLocalizer
XtraVerticalGrid
DevExpress.XtraVerticalGrid.Localization.VGridLocalizer
Specific code implementation:
First, to achieve the above finished, you need to add the following code in the code:
Speaking Code
1 public class ChEditLocalizer : Localizer
2 { // 重载 GetLocalizedString 方法
3 public override string GetLocalizedString(StringId id)
4 { switch (id)
5 { // PictureEdit 菜单汉化
6 case StringId.PictureEditMenuCut: return "剪切";
7 case StringId.PictureEditMenuCopy: return "复制";
8 case StringId.PictureEditMenuPaste: return "粘贴";
9 case StringId.PictureEditMenuDelete: return "删除";
10 case StringId.PictureEditMenuLoad: return "加载";
11 case StringId.PictureEditMenuSave: return "保存";
12 // TextEdit 菜单汉化
13 case StringId.TextEditMenuCut: return "剪切";
14 case StringId.TextEditMenuCopy: return "复制";
15 case StringId.TextEditMenuPaste: return "粘贴";
16 case StringId.TextEditMenuDelete: return "删除";
17 case StringId.TextEditMenuSelectAll: return "全选";
18 case StringId.TextEditMenuUndo: return "返回";
19 // DateEdit 控件汉化
20 case StringId.DateEditToday: return "今天";
21 case StringId.DateEditClear: return "取消";
22 }
23 return "";
24 }
25}
26
27 public class MyTreeListLocalizer : TreeListLocalizer
28 {
29 public override string GetLocalizedString(TreeListStringId id)
30 {
31 switch (id)
32 {
33 //TreeList列菜单汉化
34 case TreeListStringId.MenuColumnSortAscending: return "升序";
35 case TreeListStringId.MenuColumnSortDescending: return "升序";
36 case TreeListStringId.MenuColumnBestFit: return "固定列";
37 case TreeListStringId.MenuColumnBestFitAllColumns: return "固定所有列";
38 case TreeListStringId.MenuColumnColumnCustomization: return "自定义列";
39 }
40 return "";
41 }
42 }
43
Second, once you ChEditLocalizer can be created and MyTreeListLocalizer corresponding to the Active set, reference to the following implementation:
Active
private void Form1_Load(object sender, EventArgs e)
{
Localizer.Active = new ChEditLocalizer();
TreeListLocalizer.Active = new MyTreeListLocalizer();
}
Note: The code allows users to customize the finished Chinese content, but once GetLocalizedString method overloading, it must be finished for the whole object class, a large amount of code. Of course, if you only want to attribute local Chinese, English other reservations, you can return empty Code:
return ""; modified to return base.GetLocalizedString (id);
Third, in combination with the code resource bundle
This method is interposed between the above two methods, both using the resource bundle, reducing the workload of localization code, and corrects the extra packet is not finished on the basis of the resources to meet the finished, but there are still resources such as packet replication XtraEditors Chinese and paste swap, it must be the case for members of the entire Chinese Localizer class. Specific implementations may append the following code at the same time when the application initialization:
Code
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
Localizer.Active = new ChEditLocalizer();
NOTE: If you purchased the source code, and have their own StrongKey.snk strong name key file, then modify each return value GetLocalizedString using recompile the source code Dll files directly control the corresponding source code to achieve direct Speaking of purposes, but it will also take a lot of work.
Reproduced in: https: //my.oschina.net/cookblack/blog/621392