NSIS:在.onInit(MUI2)中使用MessageBox的选定语言

时间:2013-01-13 16:54:08

标签: nsis

我尝试在.onInit方法中获取一个本地化的消息框,该消息框失败并显示以下代码:

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "German"

LangString Message ${LANG_ENGLISH} "This is a message."
LangString Message ${LANG_GERMAN} "Dies ist eine Nachricht"

Function .onInit
  !insertmacro MUI_LANGDLL_DISPLAY
  MessageBox MB_OK "$(Message)"
FunctionEnd

MessageBox始终显示相同的语言字符串。

1 个答案:

答案 0 :(得分:3)

问题是,语言是在 .onInit方法之后处理的。

解决方法可能是将.onInit方法中的自定义代码放到.onGUIInit方法中。

使用MUI2,完成如下:

!define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit

!include "MUI2.nsh"

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "German"

LangString Message ${LANG_ENGLISH} "This is a message."
LangString Message ${LANG_GERMAN} "Dies ist eine Nachricht"

Function .onInit
  !insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd

Function myGuiInit
  MessageBox MB_OK "$(Message)"
FunctionEnd

现在MessageBox应该显示正确的本地化消息。