delphi XE6 switch元件簡繁體問題

XE6的Switch元件增加了多國語系的功能,不過很遺憾的是它在中文的部份只認得zh,不會分辨zh_CN、zh_TW、zh_SG跟zh_HK。但是幸好Delphi是可以自己修正原始碼的 🙂

 

將 Program Files\Embarcadero\Studio\14.0\source\fmx下的

FMX.Styles.Switch.pas與FMX.Platform.Android.pas複製到自己專案的目錄下

 
FMX.Styles.Switch.pas
第42行修改如下
[pascal]
// 2014.5.29 by lin shou shan
// 修正switch文字只有簡體中文問題
//LocalizedStates: array [0..6] of TStatesForLocale = (
LocalizedStates: array [0..7] of TStatesForLocale = ( // by lin shou shan
(Locale: ‘en’; OnText: ‘ON’; OffText: ‘OFF’),
(Locale: ‘jp’; OnText: ‘ON’; OffText: ‘OFF’),
(Locale: ‘ja’; OnText: ‘ON’; OffText: ‘OFF’),
(Locale: ‘ko’; OnText: ‘ON’; OffText: ‘OFF’),
(Locale: ‘de’; OnText: ‘AN’; OffText: ‘AUS’),
(Locale: ‘fr’; OnText: ‘OUI’; OffText: ‘NON’),
//(Locale: ‘zh’; OnText: #25171#24320; OffText: #20851#38381) // by lin shou shan
(Locale: ‘zh_CN’; OnText: #25171#24320; OffText: #20851#38381), // by lin shou shan
(Locale: ‘zh_TW’; OnText: ‘開’; OffText: ‘關’) // by lin shou shan
);
[/pascal]
FMX.Platform.Android.pas
第3330行修改如下
[pascal]
function TPlatformAndroid.GetCurrentLangID: string;
var
Locale: JLocale;
begin
Locale := TJLocale.JavaClass.getDefault;
Result := JStringToString(Locale.toString); // 回傳 zh_TW 2014.5.29 lin shou shan
//Result := JStringToString(Locale.getISO3Language); // lin shou shan
//if Length(Result) > 2 then // lin shou shan
// Delete(Result, 3, MaxInt); // lin shou shan
end;
[/pascal]