域名将于6月份到期,并且不再续费,届时网站将无法访问。
6月份之前如果服务器到期将提前关闭网站,请改访问模组网社区

INNO 多国语言包制作

汉化 Nexus Mod Manager 才开始接触 INNO ,一直以来玩的都是 NSIS ,但是有些内容还是挺相似的,所以利用 NSIS 中多国语言的设置,这次顺便把 INNO 的多国语言设置也搞懂了(大致上,毕竟新手,测试得不多)。

网络上普遍提到的方法是在 [Languages] 项目添加语言包,比如

Show the Content

[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"
Name: "de"; MessagesFile: "compiler:Languages\German.isl"
Name: "zh_cn"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
Name: "zh_tw"; MessagesFile: "compiler:Languages\ChineseTraditional.isl"


这样子在开始安装的时候会有个语言选择页面,如下图
INNO选择安装语言

然后以后在 [Tasks] 或者其他地方遇到的特定文本文本可以在前面加上 cm: 实现安装的时候自动切换到对应的语言,比如

Show the Content

[Tasks] 
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

这些特定的文本有(从 Default.isl 中复制的)

Show the Content

[CustomMessages]

NameAndVersion=%1 version %2
AdditionalIcons=Additional icons:
CreateDesktopIcon=Create a &desktop icon
CreateQuickLaunchIcon=Create a &Quick Launch icon
ProgramOnTheWeb=%1 on the Web
UninstallProgram=Uninstall %1
LaunchProgram=Launch %1
AssocFileExtension=&Associate %1 with the %2 file extension
AssocingFileExtension=Associating %1 with the %2 file extension...
AutoStartProgramGroupDescription=Startup:
AutoStartProgram=Automatically start %1
AddonHostProgramNotFound=%1 could not be located in the folder you selected.%n%nDo you want to continue anyway?

他们都是在上面的 [Languages] 添加的 isl 文件中定义好的,你可以直接拿来使用(CreateDesktopIcon、CreateQuickLaunchIcon、AdditionalIcons 这三个常量你都可以在上面找到)

现在的情形是

Show the Content

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: associateNxmFiles; Description: &Associate *.NXM files with {#MyAppSetupName}; GroupDescription: Other tasks:;
Name: associateNxmUrls; Description: Associate NXM: &URLs with {#MyAppSetupName}; GroupDescription: Other tasks:;
Name: associateFomodFiles; Description: &Associate *.FOMOD files with {#MyAppSetupName}; GroupDescription: Other tasks:;
Name: associateOmodFiles; Description: &Associate *.OMOD files with {#MyAppSetupName}; GroupDescription: Other tasks:;

后面的四个 Associate * files with 和 Other tasks 是英文的,如果把他们翻译成中文后,安装的时候又只显示中文(即使一开始选择的是英文)

NSIS 里面实现多国语言的方法除了添加语言文件,其他地方则通过定义每个语言的文本来实现,如

Show the Content

;-------------------------------- ;English Strings

	VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "BOSS"
	VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "BOSS Development Team"
	VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "? 2009-2012 BOSS Development Team"
	VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Installer for BOSS 2.1.1"
	VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.1.1"

	LangString TEXT_MESSAGEBOX ${LANG_ENGLISH} "BOSS is already installed, and must be uninstalled before continuing. $\n$\nClick `OK` to remove the previous version or `Cancel` to cancel this upgrade."
	LangString TEXT_RUN ${LANG_ENGLISH} "Run BOSS"
	LangString TEXT_SHOWREADME ${LANG_ENGLISH} "View Readme"
	LangString TEXT_MAIN ${LANG_ENGLISH} "All BOSS's files, minus userlists and the BOSS.ini."
	LangString TEXT_USERFILES ${LANG_ENGLISH} "BOSS's userlist files and BOSS.ini file."

;-------------------------------- ;Simplified Chinese (简体中文) Strings

	VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "ProductName" "BOSS"
	VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "CompanyName" "BOSS Development Team"
	VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "LegalCopyright" "? 2009-2012 BOSS Development Team"
	VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "FileDescription" "BOSS 2.1.1安装包"
	VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "FileVersion" "2.1.1"

	LangString TEXT_MESSAGEBOX ${LANG_SIMPCHINESE} "检测到旧版BOSS,您需要先卸载旧版才能安装新版。$\n$\n单击“确定”卸载旧版本或者“取消”取消更新。"
	LangString TEXT_RUN ${LANG_SIMPCHINESE} "运行BOSS"
	LangString TEXT_SHOWREADME ${LANG_SIMPCHINESE} "查看说明"
	LangString TEXT_MAIN ${LANG_SIMPCHINESE} "所有BOSS文件(除userlist和BOSS.ini)"
	LangString TEXT_USERFILES ${LANG_SIMPCHINESE} "BOSS的userlist和BOSS.ini文件。"

而且我注意到上面 CreateDesktopIcon、CreateQuickLaunchIcon、AdditionalIcons 这几个文本都是在语言文件 isl 的 CustomMessage 中定义好的,于是按照一样的思路我尝试出了 INNO 实现多国语言的方法:

继续上面的例子,我只需要增加模块

Show the Content

[CustomMessages]
en.associateNxmFiles=&Associate *.NXM files with {#MyAppSetupName}
;de.associateNxmFiles= 
zh_cn.associateNxmFiles=&关联 *.NXM 文件
zh_tw.associateNxmFiles=&關聯 *.NXM 文件
en.associateNxmUrls=Associate NXM: &URLs with {#MyAppSetupName}
;de.associateNxmUrls= 
zh_cn.associateNxmUrls=关联 NXM: &链接
zh_tw.associateNxmUrls=關聯 NXM: &鏈接
en.associateFomodFiles=&Associate *.FOMOD files with {#MyAppSetupName}
;de.associateFomodFiles= 
zh_cn.associateFomodFiles=&关联 *.FOMOD 文件
zh_tw.associateFomodFiles=&關聯 *.FOMOD 文件
en.associateOmodFiles=&Associate *.OMOD files with {#MyAppSetupName}
;de.associateOmodFiles= 
zh_cn.associateOmodFiles=&关联 *.OMOD 文件
zh_tw.associateOmodFiles=&關聯 *.OMOD 文件
en.ReadyMemoTasks=Additional tasks:
de.ReadyMemoTasks=Zusätzliche Aufgaben:
zh_cn.ReadyMemoTasks=附加任务:
zh_tw.ReadyMemoTasks=附加工作:


然后把代码改成

Show the Content

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: associateNxmFiles; Description: "{cm:associateNxmFiles}"; GroupDescription: "{cm:ReadyMemoTasks}";
Name: associateNxmUrls; Description: "{cm:associateNxmUrls}"; GroupDescription: "{cm:ReadyMemoTasks}";
Name: associateFomodFiles; Description: "{cm:associateFomodFiles}"; GroupDescription: "{cm:ReadyMemoTasks}";
Name: associateOmodFiles; Description: "{cm:associateOmodFiles}"; GroupDescription: "{cm:ReadyMemoTasks}";


最终就可以实现在英文环境下显示 Associate *.NXM files with Nexus Mod Manager(上面 {#MyAppSetupName} 所代表的数值),而简体中文环境下显示 关联 *.NXM 文件

到这边,INNO 多国语言包应该是没有问题了(如果感兴趣的可以自己再翻阅说明文档里面 [CustomMessages] section 的介绍)。

另外,在 Messagebox 中使用 cm:xxx 好像会失效,比如我不能直接使用
mRes := MsgBox(‘{cm:DelteUserConfig}’, mbConfirmation, MB_YESNO or MB_DEFBUTTON2)
具体原因小白没搞明白,只是你这么做的话最后会直接把 {cm:DelteUserConfig} 输出,而不是输出 DelteUserConfig 对应的文本。

我试过不加单引号(即 MsgBox({cm:DelteUserConfig}, mbConfirmation, MB_YESNO or MB_DEFBUTTON2) )
或者改单引号为双引号(我猜想错误原因是定义的 en.DelteUserConfig=Do you want to remove all of {#MyAppSetupName}”s configuration files? Doing so will reset all of {#MyAppSetupName}”s settings. Either option will keep your mods intact. 里面已经出现了单引号)
但结果都会出错。

最后找出的实现方法是
mRes := MsgBox(CustomMessage(‘DelteUserConfig’), mbConfirmation, MB_YESNO or MB_DEFBUTTON2)
直接利用 CustomMessage 函数把  DelteUserConfig 对应的文本调出来。

所以,对于[CustomMessages]定义的自定义文本,一般来说有两个调用方式:

  1. {cm:MessageName}或{cm:MessageName,Arguments}
  2. 函数 CustomMessage(const MsgName: String): String;

而 INNO 多国语言包的实现只要你能掌握 CustomMessages 就能成功。

icedream

About icedream

其实我知道的东西很少,只是翻译了一些东西,悲催的是翻译过后很快就忘了。

,

Comments are closed.