杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2223|回复: 0

Inno Setuo 多国语言包制作

[复制链接]
发表于 2017-1-7 17:58:53 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
网络上普遍提到的方法是在 [Languages] 项目添加语言包,比如
  1. [Languages]
  2. Name: "en"; MessagesFile: "compiler:Default.isl"
  3. Name: "de"; MessagesFile: "compiler:LanguagesGerman.isl"
  4. Name: "zh_cn"; MessagesFile: "compiler:LanguagesChineseSimplified.isl"
  5. Name: "zh_tw"; MessagesFile: "compiler:LanguagesChineseTraditional.isl"
复制代码
这样子在开始安装的时候会有个语言选择页面,如下图
INNO-Choose-Language.png
然后以后在 [Tasks] 或者其他地方遇到的特定文本文本可以在前面加上 cm: 实现安装的时候自动切换到对应的语言,比如
  1. [Tasks]
  2. Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
  3. Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
复制代码

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

  2. NameAndVersion=%1 version %2
  3. AdditionalIcons=Additional icons:
  4. CreateDesktopIcon=Create a &desktop icon
  5. CreateQuickLaunchIcon=Create a &Quick Launch icon
  6. ProgramOnTheWeb=%1 on the Web
  7. UninstallProgram=Uninstall %1
  8. LaunchProgram=Launch %1
  9. AssocFileExtension=&Associate %1 with the %2 file extension
  10. AssocingFileExtension=Associating %1 with the %2 file extension...
  11. AutoStartProgramGroupDescription=Startup:
  12. AutoStartProgram=Automatically start %1
  13. AddonHostProgramNotFound=%1 could not be located in the folder you selected.%n%nDo you want to continue anyway?
复制代码
他们都是在上面的 [Languages] 添加的 isl 文件中定义好的,你可以直接拿来使用(CreateDesktopIcon、CreateQuickLaunchIcon、AdditionalIcons 这三个常量你都可以在上面找到)
现在的情形是
  1. [Tasks]
  2. Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
  3. Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
  4. Name: associateNxmFiles; Description: &Associate *.NXM files with {#MyAppSetupName}; GroupDescription: Other tasks:;
  5. Name: associateNxmUrls; Description: Associate NXM: &URLs with {#MyAppSetupName}; GroupDescription: Other tasks:;
  6. Name: associateFomodFiles; Description: &Associate *.FOMOD files with {#MyAppSetupName}; GroupDescription: Other tasks:;
  7. Name: associateOmodFiles; Description: &Associate *.OMOD files with {#MyAppSetupName}; GroupDescription: Other tasks:;
复制代码

后面的四个 Associate * files with 和 Other tasks 是英文的,如果把他们翻译成中文后,安装的时候又只显示中文(即使一开始选择的是英文)
NSIS 里面实现多国语言的方法除了添加语言文件,其他地方则通过定义每个语言的文本来实现,如
  1. ;-------------------------------- ;English Strings

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

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

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

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

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

而且我注意到上面 CreateDesktopIcon、CreateQuickLaunchIcon、AdditionalIcons 这几个文本都是在语言文件 isl 的 CustomMessage 中定义好的,于是按照一样的思路我尝试出了 INNO 实现多国语言的方法:
继续上面的例子,我只需要增加模块
  1. [CustomMessages]
  2. en.associateNxmFiles=&Associate *.NXM files with {#MyAppSetupName}
  3. ;de.associateNxmFiles=
  4. zh_cn.associateNxmFiles=&关联 *.NXM 文件
  5. zh_tw.associateNxmFiles=&關聯 *.NXM 文件
  6. en.associateNxmUrls=Associate NXM: &URLs with {#MyAppSetupName}
  7. ;de.associateNxmUrls=
  8. zh_cn.associateNxmUrls=关联 NXM: &链接
  9. zh_tw.associateNxmUrls=關聯 NXM: &鏈接
  10. en.associateFomodFiles=&Associate *.FOMOD files with {#MyAppSetupName}
  11. ;de.associateFomodFiles=
  12. zh_cn.associateFomodFiles=&关联 *.FOMOD 文件
  13. zh_tw.associateFomodFiles=&關聯 *.FOMOD 文件
  14. en.associateOmodFiles=&Associate *.OMOD files with {#MyAppSetupName}
  15. ;de.associateOmodFiles=
  16. zh_cn.associateOmodFiles=&关联 *.OMOD 文件
  17. zh_tw.associateOmodFiles=&關聯 *.OMOD 文件
  18. en.ReadyMemoTasks=Additional tasks:
  19. de.ReadyMemoTasks=Zusätzliche Aufgaben:
  20. zh_cn.ReadyMemoTasks=附加任务:
  21. zh_tw.ReadyMemoTasks=附加工作:
复制代码

然后把代码改成
  1. [Tasks]
  2. Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
  3. Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
  4. Name: associateNxmFiles; Description: "{cm:associateNxmFiles}"; GroupDescription: "{cm:ReadyMemoTasks}";
  5. Name: associateNxmUrls; Description: "{cm:associateNxmUrls}"; GroupDescription: "{cm:ReadyMemoTasks}";
  6. Name: associateFomodFiles; Description: "{cm:associateFomodFiles}"; GroupDescription: "{cm:ReadyMemoTasks}";
  7. 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]定义的自定义文本,一般来说有两个调用方式:
  • {cm:MessageName}或{cm:MessageName,Arguments}
  • 函数 CustomMessage(const MsgName: String): String;
而 INNO 多国语言包的实现只要你能掌握 CustomMessages 就能成功。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 20:01 , Processed in 0.132901 second(s), 25 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表