简体   繁体   English

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

[英]NSIS: Use selected language for MessageBox in .onInit (MUI2)

I try to get a localized message box in the .onInit method which fails with the following code:我尝试在 .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

The MessageBox always shows the same language string. MessageBox 始终显示相同的语言字符串。

The Problem is, that the language is processed after the .onInit method.问题是,语言是.onInit 方法之后处理的。

A workaround for this could be to put the custom code from the .onInit method to the .onGUIInit method.一种解决方法是将自定义代码从 .onInit 方法放到 .onGUIInit 方法中。

With MUI2 this is done as follows:使用 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

Now the MessageBox should show the correctly localized message.现在 MessageBox 应该显示正确本地化的消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM