Archive: Detect Multiple Language's Bug


Detect Multiple Language's Bug
Sorry, my English is very very poor.

I found that "Regional Option" will make NSIS's to choose wrong Language during callback Function .onInit.

This will happened at all windows platform.

Screen Capture Enviroment:
OS - WinXP SP1 English Version
Languages for non-unicode programs - Always set to "Chinese(Taiwan)"
NSIS Version - 2.0 B4 (final)

Let me show you an example:

1.The good one ... almost ...
http://cpatch.org/witchfive/pastepic/l1.jpg

2.Just change "Regional Option" to "English"
http://cpatch.org/witchfive/pastepic/l2.jpg

3.Just change "Regional Option" to "Japanese"
http://cpatch.org/witchfive/pastepic/l3.jpg

4.Just change "Regional Option" to "Chinese (PRC)"
http://cpatch.org/witchfive/pastepic/l4.jpg

== LangTest.nsi ==
OutFile LangTest.exe
Name LangBugTests
XPStyle on

LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\TradChinese.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Japanese.nlf"

LangString IL ${LANG_ENGLISH} "EN Installer Language"
LangString IL ${LANG_TRADCHINESE} "TW Installer Language"
LangString IL ${LANG_SIMPCHINESE} "CN Installer Language"
LangString IL ${LANG_JAPANESE} "JP Installer Language"

LangString CL ${LANG_ENGLISH} "EN Please select a language."
LangString CL ${LANG_TRADCHINESE} "TW Please select a language."
LangString CL ${LANG_SIMPCHINESE} "CN Please select a language."
LangString CL ${LANG_JAPANESE} "JP Please select a language."

LangString PM ${LANG_ENGLISH} "EN"
LangString PM ${LANG_TRADCHINESE} "TW"
LangString PM ${LANG_SIMPCHINESE} "CN"
LangString PM ${LANG_JAPANESE} "JP"

Section Sec1Name sec1
SectionEnd

Function .onInit
LangDLL::LangDialog "$(IL)" "$(CL)" 4 $(PM)Eng 1033 $(PM)TW 1028 $(PM)CN 2052 $(PM)JP 1041
quit
FunctionEnd
==


Well, the only method I know of getting the user's setting of `Languages for non-Unicode programs' is GetACP(). Essentially, that's the only thing it needs to change. It just needs to change the code page for the conversion from/to Unicode. The only problem is that not all languages have a different code page. For example, ANSI - Central European (1250) is used for Polish, Czech, Romanian, Slovak and many more. ANSI - Latin I (1252) is used by even more languages. Given this situation, getting the user's default language is the best method I have found.


Sorry, my English is very very poor.

OK, I found this at NSIS Archie, and tested OK to get user's setting of "Languages for non-Unicode programs" exactly correct at all windows platform.

== code ==
System::Call 'kernel32::GetSystemDefaultLangID() i .r0'
IntOp $0 $0 & 0xFFFF
IntFMT $0 "%04X" $0
==

Unfortunally, I still can't change the Language detected by NSIS during callback function .onInit.

And after callback function .onInit finished, the Language could be correct by some tricker.

Besides, this bug make us getting wrong Language at those "Messages" proceed durning callback function .onInit, like LANGDLL, MessageBox, and something else.


The user might have selected a different language for himself, automatically selecting the system's language will not be wise. But if you really want to do it use:

System::Call 'kernel32::GetSystemDefaultLangID() i .a'

in .onInit before the call to LangDLL.

As for the messages in .onInit, the language selected in .onInit, if different than the one chosen by NSIS, only takes affect after .onInit.