请把轻狂志网址 www.flighty.cn 加入收藏夹,其他俱为假冒,谨防被骗!赞助请点 这里!找东东请用右边的搜索 ===>
24 2014-12

NSIS:实现多语言安装卸载并定义语言相关字符串

作者:少轻狂 | 发布:2014-07-02 | 更新:2014-12-24 | 分类:部署 | Disposition | 热度:

这两天一位同学在留言上问多语言的问题,轻狂这两天比较忙,原本没想回复,但有感于这位同学的好学精神,还是抽时间写了一个示例脚本。当然还不太完善,不过只要有了思路,其他都不是问题了,对吧?

 

初步实现了:

根据选择的语言安装时显示不同的程序名称

根据选择的语言安装时释放不同的程序文件

根据选择的语言卸载时显示不同的程序名称及提示文字

 

直接贴出脚本,希望转载的同学注明出处——轻狂志www.flighty.cn。

!define PRODUCT_NAME ""
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.flighty.cn"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\myapp"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

SetCompressor lzma
RequestExecutionLevel admin

!include "MUI2.nsh"

!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; 语言选择窗口常量设置
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_INSTFILES

; 语言设置
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
; 语言相关字符串
LangString LNG_AppName ${LANG_ENGLISH} "flighty'app"
LangString LNG_AppName ${LANG_SIMPCHINESE} "轻狂的程序"
LangString UNINSTALL_CONFIRM ${LANG_ENGLISH} "Thank you very much! $(^Name) has been successfully removed."
LangString UNINSTALL_CONFIRM ${LANG_SIMPCHINESE} "非常感謝您的使用! $(^Name) 已成功地从您的计算机中移除。"


Name "$(LNG_AppName)"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show

Section "MainSection" SEC01
  StrCpy $0 $(LNG_AppName)
	${If} $0 == "flighty'app"
  	MessageBox MB_OK "ENGLISH"
	${Else}
  	MessageBox MB_OK "简体中文"
	${EndIf}
SectionEnd

Section -AdditionalIcons
  SetOutPath $INSTDIR
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateDirectory "$SMPROGRAMS\My application"
  CreateShortCut "$SMPROGRAMS\My application\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\My application\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd


Function .onInit
  !insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd

Section Uninstall
  Delete "$INSTDIR\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\uninst.exe"

  Delete "$SMPROGRAMS\My application\Uninstall.lnk"
  Delete "$SMPROGRAMS\My application\Website.lnk"

  RMDir "$SMPROGRAMS\My application"

  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  SetAutoClose true
SectionEnd

Function un.onInit
  !insertmacro MUI_UNGETLANGUAGE
FunctionEnd

Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(UNINSTALL_CONFIRM)"
FunctionEnd

 

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
  • 独木成林
    2014-12-29 22:20:28发表

    太长了。略过~

  • Alex
    2014-12-27 16:30:00发表

    正如我所看到的,很不错的BLOG

  • 寂寞
    2014-07-03 14:06:15发表

    第一时间看到博主的回复。立马就试了下。一下子就成功了,另外受博主的启发,加载中文字串以及根据语言判断的问题都解决了。感谢博主!真的很感谢!