本帖最后由 xayle 于 2012-10-7 15:12 编辑
这有个演示
#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
global $langdir = @scriptdir & "\lang\", $langlist, $local, $language, $OSLang
#Region ### START Koda GUI section ### Form=d:\aus\multiple languages\form1.kxf
$Form1 = GUICreate("", 300, 200)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem2 = GUICtrlCreateMenu("&View")
$MenuItem3 = GUICtrlCreateMenu("&Help")
$MenuItem4 = GUICtrlCreateMenu("&About")
$Languages = GUICtrlCreateCombo("Languages", 8, 8, 100, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
$Label1 = GUICtrlCreateLabel("Multiple Languages Test. Here is test content.", 8, 40, 280, 100)
$Label2 = GUICtrlCreateLabel("", 8, 152, 280, 120)
$Button1 = GUICtrlCreateButton("&Exit", 160, 6, 75, 24)
langcheck()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Languages
if $language <> GUICtrlRead($Languages) then
$language = GUICtrlRead($Languages)
$local = langcheck(1,GUICtrlRead($Languages))
regui()
endif
Case $Button1
Exit
EndSwitch
WEnd
Func regui()
WinSetTitle($Form1,"",t("Title"))
GUICtrlSetData($MenuItem1, t("MENU_File_Label"))
GUICtrlSetData($MenuItem2, t("MENU_View_Label"))
GUICtrlSetData($MenuItem3, t("MENU_Help_Label"))
GUICtrlSetData($MenuItem4, t("MENU_About_Label"))
GUICtrlSetData($Label1, t("LABEL_Label1"))
GUICtrlSetData($Button1, t("BUTTON_Exit"))
EndFunc
func t($t, $vars = "")
$return = iniread($langdir & $local & ".ini", "X.GUI", $t, "")
$return = stringreplace($return, "%n", @CRLF)
$return = stringreplace($return, "%t", @TAB)
for $i = 0 to ubound($vars)-1
$return = stringreplace($return, "%s", $vars[$i], 1)
next
return $return
endfunc
Func langlist()
$langstr = _FileListToArray($langdir, "*.ini")
for $i = 0 to ubound($langstr) - 1
$langlist &= stringtrimright($langstr[$i], 4) & "|"
next
GUICtrlSetData($Languages, $langlist, $language)
EndFunc
Func langcheck($n=0,$nl="")
$langsy = @OSLang
$langstr = _FileListToArray($langdir, "*.ini")
for $i = 1 to ubound($langstr) - 1
$langna = iniread($langdir & $langstr[$i], "X.GUI", "Language", "")
$langid = iniread($langdir & $langstr[$i], "X.GUI", "OSLang", "")
$langlo = stringtrimright($langstr[$i], 4)
If $n = 0 Then
If $langsy == $langid Then
$language = $langna
$local = $langlo
$OSLang = $langid
$Exist = 1
EndIf
$langlist &= $langna & "|"
ElseIf $n = 1 Then
If $nl == $langna Then Return $langlo
EndIf
next
If $OSLang = @OSLang Then
regui()
GUICtrlSetData($Label2, "Check Languages:" & $language)
Else
$local = "en-us"
$language = "English"
GUICtrlSetData($Label2, "Language file does not exist. default display in English.")
EndIf
GUICtrlSetData($Languages, "")
GUICtrlSetData($Languages, $langlist, $language)
EndFunc
上面的检测不到语言文件会显示默认的界面
语言文件存放在.\lang\下面
英文可以用ANSI编码, 其他语言建议用Unicode编码, 这样不会产生乱码.
en-us.ini[X.GUI]
Language="English"
OSLang="0409"
Title="Multiple Languages Test"
MENU_File_Label="&File"
MENU_View_Label="&View"
MENU_Help_Label="&Help"
MENU_About_Label="&About"
LABEL_Label1="This privacy statement applies to Microsoft.com and Microsoft websites, services and products that collect data and display these terms, as well as their offline product support services."
BUTTON_Exit = "&Exit"
zh-cn.ini[X.GUI]
Language="简体中文"
OSLang="0804"
Title="多国语言测试"
MENU_File_Label="文件(&F)"
MENU_View_Label="查看(&V)"
MENU_Help_Label="帮助(&H)"
MENU_About_Label="关于(&A)"
LABEL_Label1="此隐私声明适用于收集并显示这些条款的 Microsoft 网站、服务和产品,及其脱机产品支持服务。"
BUTTON_Exit = "退出(&E)"
zh-tw.ini[X.GUI]
Language="繁體中文"
OSLang="0404"
Title="多國語言測試"
MENU_File_Label="檔案(&F)"
MENU_View_Label="視圖(&V)"
MENU_Help_Label="幫助(&H)"
MENU_About_Label="關於(&A)"
LABEL_Label1="此隱私權聲明適用於收集並顯示這些條款的 Microsoft 網站、服務和產品,及其脫機產品支援服務。"
BUTTON_Exit = "退出(&E)"
|