诚心请教,如何让AU3编译的程序支持多语言?
同时支持简体,繁体,及英文,应该如何实现呢? 菜鸟前来围观,1.检测当前系统语言
2.调用对应的语言文件
所以关键在于第二步。
见过好多程序用ini格式的文件来存储
如
file = 文件
file = file
只是举个例子 可能需要用到正则表达式 用unicode写,判断系统使用对应的转码方式 请蛋蛋明示,或者能否给个示例呢 没环境,写不了,大概思路而已 本帖最后由 xayle 于 2012-10-7 02:19 编辑
需要在定义好一些关键字,然后读取对应语言的ini,改写这些关键字
语言文件需要保存为unicode格式才不会有乱码
也可以用数据库形式来调用,ini也行,反正就是一个思路,ini见得比较多一点,Au3里面有INI的函数,可以直接调用 本帖最后由 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
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
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
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)"
来看看思路,其实全用英文写不就得了。 学习学习{:face (310):} 可以参考 SciTE Jump 源代码(本论坛也有),里面有多国语言的实现。 特来学习一下。 没有作品,所以无需多国语言。
路过记号,谢谢看到了源码! 9楼的代码厉害啊,学习了~~
页:
[1]
2