汉化嘛,照说已经有源代码了,汉化是比较简单的事情,不过如果直接修改源代码的话,下次再升级可能会不太好搞,所以一般情况下我不喜欢乱改源代码,而且还有更好的方式汉化。
我是写winform的,插入的控件也不是特别多,好像需要汉化的只有显示的XtraMessageBox.Show下面的“是”“否”“确定”“取消”什么的这些东东需要汉化了。
我相信大家一看到下面这个重写的函数应该就明白差不多了,我只把我需要的几个按钮给替换成中文就好了。
2 namespace LocalizationCHS
3 {
4 public class DevExpressXtraEditorsLocalizationCHS : Localizer
5 {
6 public override string GetLocalizedString(StringId id)
7 {
8 switch (id)
9 {
10 case StringId.None: return "" ;
11 case StringId.CaptionError: return " 错误 " ;
12 case StringId.InvalidValueText: return " 无效数值 " ;
13 case StringId.CheckChecked: return " 已选 " ;
14 case StringId.CheckUnchecked: return " 未选 " ;
15 case StringId.CheckIndeterminate: return " Indeterminate " ;
16 case StringId.DateEditToday: return " 今天 " ;
17 case StringId.DateEditClear: return " 清除 " ;
18 case StringId.OK: return " 确定 " ;
19 case StringId.Cancel: return " 取消 " ;
20 case StringId.NavigatorFirstButtonHint: return " First " ;
21 case StringId.NavigatorPreviousButtonHint: return " Previous " ;
22 case StringId.NavigatorPreviousPageButtonHint: return " Previous Page " ;
23 case StringId.NavigatorNextButtonHint: return " Next " ;
24 case StringId.NavigatorNextPageButtonHint: return " Next Page " ;
25 case StringId.NavigatorLastButtonHint: return " Last " ;
26 case StringId.NavigatorAppendButtonHint: return " Append " ;
27 case StringId.NavigatorRemoveButtonHint: return " Delete " ;
28 case StringId.NavigatorEditButtonHint: return " Edit " ;
29 case StringId.NavigatorEndEditButtonHint: return " End Edit " ;
30 case StringId.NavigatorCancelEditButtonHint: return " Cancel Edit " ;
31 case StringId.NavigatorTextStringFormat: return " Record {0} of {1} " ;
32 case StringId.PictureEditMenuCut: return " Cut " ;
33 case StringId.PictureEditMenuCopy: return " Copy " ;
34 case StringId.PictureEditMenuPaste: return " Paste " ;
35 case StringId.PictureEditMenuDelete: return " Delete " ;
36 case StringId.PictureEditMenuLoad: return " Load " ;
37 case StringId.PictureEditMenuSave: return " Save " ;
38 case StringId.PictureEditOpenFileFilter: return " Bitmap Files (*.bmp)|*.bmp| " +
39 " Graphics Interchange Format (*.gif)|*.gif| " +
40 " JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg| " +
41 " Icon Files (*.ico)|*.ico| " +
42 " All Picture Files |*.bmp;*.gif;*.jpg;*.jpeg;*.ico;*.png;*.tif| " +
43 " All Files |*.* " ;
44 case StringId.PictureEditSaveFileFilter: return " Bitmap Files (*.bmp)|*.bmp| " +
45 " Graphics Interchange Format (*.gif)|*.gif| " +
46 " JPEG File Interchange Format (*.jpg)|*.jpg " ;
47 case StringId.PictureEditOpenFileTitle: return " Open " ;
48 case StringId.PictureEditSaveFileTitle: return " Save As " ;
49 case StringId.PictureEditOpenFileError: return " Wrong picture format " ;
50 case StringId.PictureEditOpenFileErrorCaption: return " Open error " ;
51 case StringId.PictureEditCopyImageError: return " Could not copy image " ;
52 case StringId.LookUpEditValueIsNull: return " [EditValue is null] " ;
53 case StringId.LookUpInvalidEditValueType: return " Invalid LookUpEdit EditValue type. " ;
54 case StringId.LookUpColumnDefaultName: return " Name " ;
55 case StringId.MaskBoxValidateError: return " The entered value is incomplete. Do you want to correct it?\r\n\r\n " +
56 " Yes - return to the editor and correct the value.\r\n " +
57 " No - leave the value as is.\r\n " +
58 " Cancel - reset to the previous value.\r\n " ;
59 case StringId.UnknownPictureFormat: return " Unknown picture format " ;
60 case StringId.DataEmpty: return " No image data " ;
61 case StringId.NotValidArrayLength: return " Not valid array length. " ;
62 case StringId.ImagePopupEmpty: return " (Empty) " ;
63 case StringId.ImagePopupPicture: return " (Picture) " ;
64 case StringId.ColorTabCustom: return " Custom " ;
65 case StringId.ColorTabWeb: return " Web " ;
66 case StringId.ColorTabSystem: return " System " ;
67 case StringId.CalcButtonMC: return " MC " ;
68 case StringId.CalcButtonMR: return " MR " ;
69 case StringId.CalcButtonMS: return " MS " ;
70 case StringId.CalcButtonMx: return " M+ " ;
71 case StringId.CalcButtonSqrt: return " sqrt " ;
72 case StringId.CalcButtonBack: return " Back " ;
73 case StringId.CalcButtonCE: return " CE " ;
74 case StringId.CalcButtonC: return " C " ;
75 case StringId.CalcError: return " Calculation Error " ;
76 case StringId.TabHeaderButtonPrev: return " Scroll Left " ;
77 case StringId.TabHeaderButtonNext: return " Scroll Right " ;
78 case StringId.TabHeaderButtonClose: return " 关闭 " ;
79 case StringId.XtraMessageBoxOkButtonText: return " 确定 " ;
80 case StringId.XtraMessageBoxCancelButtonText: return " 取消 " ;
81 case StringId.XtraMessageBoxYesButtonText: return " 是 " ;
82 case StringId.XtraMessageBoxNoButtonText: return " 否 " ;
83 case StringId.XtraMessageBoxAbortButtonText: return " 终止 " ;
84 case StringId.XtraMessageBoxRetryButtonText: return " 重试 " ;
85 case StringId.XtraMessageBoxIgnoreButtonText: return " 忽略 " ;
86 case StringId.TextEditMenuUndo: return " &Undo " ;
87 case StringId.TextEditMenuCut: return " Cu&t " ;
88 case StringId.TextEditMenuCopy: return " &Copy " ;
89 case StringId.TextEditMenuPaste: return " &Paste " ;
90 case StringId.TextEditMenuDelete: return " &Delete " ;
91 case StringId.TextEditMenuSelectAll: return " Select &All " ;
92 case StringId.FilterShowAll: return " (Select All) " ;
93 case StringId.FilterGroupAnd: return " And " ;
94 case StringId.FilterGroupNotAnd: return " Not And " ;
95 case StringId.FilterGroupNotOr: return " Not Or " ;
96 case StringId.FilterGroupOr: return " Or " ;
97 case StringId.FilterClauseAnyOf: return " Is any of " ;
98 case StringId.FilterClauseBeginsWith: return " Begins with " ;
99 case StringId.FilterClauseBetween: return " Is between " ;
100 case StringId.FilterClauseBetweenAnd: return " and " ;
101 case StringId.FilterClauseContains: return " Contains " ;
102 case StringId.FilterClauseEndsWith: return " Ends with " ;
103 case StringId.FilterClauseEquals: return " Equals " ;
104 case StringId.FilterClauseGreater: return " Is greater than " ;
105 case StringId.FilterClauseGreaterOrEqual: return " Is greater than or equal to " ;
106 case StringId.FilterClauseIsNotNull: return " Is not blank " ;
107 case StringId.FilterClauseIsNull: return " Is blank " ;
108 case StringId.FilterClauseLess: return " Is less than " ;
109 case StringId.FilterClauseLessOrEqual: return " Is less than or equal to " ;
110 case StringId.FilterClauseLike: return " Is like " ;
111 case StringId.FilterClauseNoneOf: return " Is none of " ;
112 case StringId.FilterClauseNotBetween: return " Is not between " ;
113 case StringId.FilterClauseDoesNotContain: return " Does not contain " ;
114 case StringId.FilterClauseDoesNotEqual: return " Does not equal " ;
115 case StringId.FilterClauseNotLike: return " Is not like " ;
116 case StringId.FilterEmptyEnter: return " <enter a value> " ;
117 case StringId.FilterEmptyParameter: return " <enter a parameter> " ;
118 case StringId.FilterMenuAddNewParameter: return " Add a new parameter ... " ;
119 case StringId.FilterEmptyValue: return " <empty> " ;
120 case StringId.FilterMenuConditionAdd: return " Add Condition " ;
121 case StringId.FilterMenuGroupAdd: return " Add Group " ;
122 case StringId.FilterMenuClearAll: return " Clear All " ;
123 case StringId.FilterMenuRowRemove: return " Remove Group " ;
124 case StringId.FilterToolTipNodeAdd: return " Adds a new condition to this group " ;
125 case StringId.FilterToolTipNodeRemove: return " Removes this condition " ;
126 case StringId.FilterToolTipNodeAction: return " Actions " ;
127 case StringId.FilterToolTipValueType: return " Compare with a value / another field's value " ;
128 case StringId.FilterToolTipElementAdd: return " Adds a new item to the list " ;
129 case StringId.FilterToolTipKeysAdd: return " (Use the Insert or Add key) " ;
130 case StringId.FilterToolTipKeysRemove: return " (Use the Delete or Subtract key) " ;
131 case StringId.ContainerAccessibleEditName: return " Editing control " ;
132 case StringId.FilterCriteriaToStringGroupOperatorAnd: return " And " ;
133 case StringId.FilterCriteriaToStringGroupOperatorOr: return " Or " ;
134 case StringId.FilterCriteriaToStringUnaryOperatorBitwiseNot: return " ~ " ;
135 case StringId.FilterCriteriaToStringUnaryOperatorIsNull: return " Is Null " ;
136 case StringId.FilterCriteriaToStringUnaryOperatorMinus: return " - " ;
137 case StringId.FilterCriteriaToStringUnaryOperatorNot: return " Not " ;
138 case StringId.FilterCriteriaToStringUnaryOperatorPlus: return " + " ;
139 case StringId.FilterCriteriaToStringBinaryOperatorBitwiseAnd: return " & " ;
140 case StringId.FilterCriteriaToStringBinaryOperatorBitwiseOr: return " | " ;
141 case StringId.FilterCriteriaToStringBinaryOperatorBitwiseXor: return " ^ " ;
142 case StringId.FilterCriteriaToStringBinaryOperatorDivide: return " / " ;
143 case StringId.FilterCriteriaToStringBinaryOperatorEqual: return " = " ;
144 case StringId.FilterCriteriaToStringBinaryOperatorGreater: return " > " ;
145 case StringId.FilterCriteriaToStringBinaryOperatorGreaterOrEqual: return " >= " ;
146 case StringId.FilterCriteriaToStringBinaryOperatorLess: return " < " ;
147 case StringId.FilterCriteriaToStringBinaryOperatorLessOrEqual: return " <= " ;
148 case StringId.FilterCriteriaToStringBinaryOperatorLike: return " Like " ;
149 case StringId.FilterCriteriaToStringBinaryOperatorMinus: return " - " ;
150 case StringId.FilterCriteriaToStringBinaryOperatorModulo: return " % " ;
151 case StringId.FilterCriteriaToStringBinaryOperatorMultiply: return " * " ;
152 case StringId.FilterCriteriaToStringBinaryOperatorNotEqual: return " <> " ;
153 case StringId.FilterCriteriaToStringBinaryOperatorPlus: return " + " ;
154 case StringId.FilterCriteriaToStringBetween: return " Between " ;
155 case StringId.FilterCriteriaToStringIn: return " In " ;
156 case StringId.FilterCriteriaToStringIsNotNull: return " Is Not Null " ;
157 case StringId.FilterCriteriaToStringNotLike: return " Not Like " ;
158 case StringId.FilterCriteriaToStringFunctionIif: return " Iif " ;
159 case StringId.FilterCriteriaToStringFunctionIsNull: return " IsNull " ;
160 case StringId.FilterCriteriaToStringFunctionLen: return " Len " ;
161 case StringId.FilterCriteriaToStringFunctionLower: return " Lower " ;
162 case StringId.FilterCriteriaToStringFunctionNone: return " None " ;
163 case StringId.FilterCriteriaToStringFunctionSubstring: return " Substring " ;
164 case StringId.FilterCriteriaToStringFunctionTrim: return " Trim " ;
165 case StringId.FilterCriteriaToStringFunctionUpper: return " Upper " ;
166 case StringId.FilterCriteriaToStringFunctionCustom: return " Custom " ;
167 case StringId.FilterCriteriaToStringFunctionLocalDateTimeThisYear:
168 case StringId.FilterCriteriaToStringFunctionLocalDateTimeThisMonth:
169 case StringId.FilterCriteriaToStringFunctionLocalDateTimeLastWeek:
170 case StringId.FilterCriteriaToStringFunctionLocalDateTimeThisWeek:
171 case StringId.FilterCriteriaToStringFunctionLocalDateTimeYesterday:
172 case StringId.FilterCriteriaToStringFunctionLocalDateTimeToday:
173 case StringId.FilterCriteriaToStringFunctionLocalDateTimeNow:
174 case StringId.FilterCriteriaToStringFunctionLocalDateTimeTomorrow:
175 case StringId.FilterCriteriaToStringFunctionLocalDateTimeDayAfterTomorrow:
176 case StringId.FilterCriteriaToStringFunctionLocalDateTimeNextWeek:
177 case StringId.FilterCriteriaToStringFunctionLocalDateTimeTwoWeeksAway:
178 case StringId.FilterCriteriaToStringFunctionLocalDateTimeNextMonth:
179 case StringId.FilterCriteriaToStringFunctionLocalDateTimeNextYear:
180 return id.ToString().Substring( " FilterCriteriaToStringFunctionLocalDateTime " .Length);
181 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalBeyondThisYear:
182 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalLaterThisYear:
183 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalLaterThisMonth:
184 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalNextWeek:
185 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalLaterThisWeek:
186 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalTomorrow:
187 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalToday:
188 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalYesterday:
189 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalEarlierThisWeek:
190 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalLastWeek:
191 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalEarlierThisMonth:
192 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalEarlierThisYear:
193 case StringId.FilterCriteriaToStringFunctionIsOutlookIntervalPriorThisYear:
194 return " Is " + id.ToString().Substring( " FilterCriteriaToStringFunctionIsOutlookInterval " .Length);
195 case StringId.FilterCriteriaInvalidExpression:
196 return " The specified expression contains invalid symbols (line {0}, character {1}). " ;
197 case StringId.FilterCriteriaInvalidExpressionEx:
198 return " The specified expression is invalid. " ;
199 case StringId.Apply: return " Apply " ;
200 case StringId.PreviewPanelText: return " Preview: " ;
201 case StringId.TransparentBackColorNotSupported: return " This control does not support transparent background colors " ;
202 case StringId.FilterOutlookDateText:
203 return " Show all|Show Empty|Filter by a specific date:|Beyond this year|Later this year|Later this month|Next week| " +
204 " Later this week|Tomorrow|Today|Yesterday|Earlier this week|Last week|Earlier this month|Earlier this year| " +
205 " Prior to this year " ;
206 case StringId.FilterDateTextAlt:
207 return " Show all|Show Empty|Filter by a specific date:|Beyond|||Next week|Today|This week|This month|Earlier|{0:yyyy}, {0:MMMM} " ;
208 case StringId.FilterDateTimeConstantMenuCaption:
209 return " DateTime constants " ;
210 case StringId.FilterDateTimeOperatorMenuCaption:
211 return " DateTime operators " ;
212 }
213 return "" ;
214 }
215 }
216 }
217
这些代码可以直接放在winform项目里,也可以作为一个单独的DLL存放了。
然后再把这句加入到Winform的Form_load第一行里就可以了
DevExpress.XtraEditors.Controls.Localizer.Active = new LocalizationCHS.DevExpressXtraEditorsLocalizationCHS();
有人可能要问我上面重写的函数是怎么来的。很简单,直接在Devexpress(DXperience) 10.1.6源代码里搜索就有了。找到了COPY一份出来,然后把需要的内容改成中文就好了。
我的汉化方式只适合于小量的汉化, 不适合规模太大的。
如果在现成完整的
Devexpress 在设计的时候已经有一套比较完善的多语言方案了。官方也有相关的下载,但我没有用到,以后用到的可能性也不是太大,所以我没有研究,大家可以去官方多看看。
还有一套现成的比较完整的方案是fosoyo.com提供的。我是花钱买来的,不是我舍不得钱,只是人家自己搞点东西....不能肆意的糟蹋嘛。