- NSIS Discussion
- Extract file depending on language
Archive: Extract file depending on language
matricen
7th June 2003 03:31 UTC
Extract file depending on language
Here is a little newbie question. Is it possible to extract files with my Modern NSIS installer depenping on which language the user has choosen? - If, then how would it look like?
(My installer includes to different languages)
e.g.
SetOutPath "$INSTDIR\"
File "language1.txt"
File "language2.txt"
If user has chosen language1, then I only want the language1.txt to be extracted and not language2.txt. (Same thing other way around)
Sunjammer
7th June 2003 09:04 UTC
$LANGUAGE gets set to the language name so you could do: (not tested)
File "$LANGUAGE.txt"
kichik
7th June 2003 11:03 UTC
As $LANGUAGE is a runtime variable this will not work. You should use something like this:
StrCmp $LANGUAGE ${LANG_ENGLISH} 0 notEnglish
File "english file.txt"
notEnglish: StrCmp $LANGUAGE ${LANG_FRENCH} 0 notFrench
File "french file.txt"
notFrench:
Joel
7th June 2003 17:03 UTC
and...
Is there a way to detect the user's PC language?
MoNKi
7th June 2003 18:58 UTC
Lobo Lunar, I think that I found a way to detect the user language, please, test it with other languages, i only tested it with the spanish language.
OutFile "AutoLanguage.exe"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
Name "AutoLanguage English"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Spanish.nlf"
Name "AutoLanguage Spanish"
; Puts in stack the user LANG_ID
Function GetUserLangId
Push $R0
System::Call 'Kernel32::GetUserDefaultLCID(v) i() .r10'
IntOp $R0 $R0 & "2047"
Exch $R0
FunctionEnd
Function .onInit
Call GetUserLangId
Pop $R0
MessageBox MB_OK "User LANG_ID = $R0"
StrCmp $R0 ${LANG_SPANISH} 0 notSpanish
MessageBox MB_OK "Spanish"
Goto finishLang
notSpanish:
MessageBox MB_OK "English"
finishLang:
Abort
FunctionEnd
Section ""
SectionEnd
Joel
7th June 2003 19:10 UTC
Display in my machine (Windows ME):
User LANG_ID = 10
English
[edit]
OutFile "AutoLanguage.exe"
Name "DetectLanguage"
; Puts in stack the user LANG_ID
Function GetUserLangId
Push $R0
System::Call 'Kernel32::GetSystemDefaultLangID(v) i() .r10'
Exch $R0
FunctionEnd
Function .onInit
Call GetUserLangId
Pop $R0
MessageBox MB_OK "$R0"
;here mine return:
2058=LANG_SPANISH|SUBLANG_SPANISH_MEXICAN
Quit
FunctionEnd
Section ""
SectionEnd
Now, must compare with the tool in "${NSISDIR}\bin\MakeLangID.exe"
MoNKi
7th June 2003 19:26 UTC
In my windows xp it shows "User LANG_ID=1034" :(
I'll read MSDN more carefully for another way.
MoNKi
7th June 2003 20:01 UTC
I have read your edit now. Well, your way is better (but with GetUserDefaultLangID bacause a single user can change his default lang), now I get 3082 (SUBLANG_MODERN). We need to associate each SUBLANG with the "NORMAL". I think this can work:
; Puts in stack the user LANG_ID
Function GetUserLangId
Push $R0
System::Call 'Kernel32::GetUserDefaultLangID(v) i() .r10'
Exch $R0
FunctionEnd
Function ConvertLangIdToNeutral
Exch $R0
IntOp $R0 $R0 & "1023"
Exch $R0
FunctionEnd
Function .onInit
Call GetUserLangId
Call ConvertLangIdToNeutral
Pop $R0
MessageBox MB_OK "User NEUTRAL_LANG_ID = $R0"
Push ${LANG_SPANISH}
Call ConvertLangIdToNeutral
Pop $R1
StrCmp $R0 $R1 0 notSpanish
MessageBox MB_OK "Spanish"
Goto finishLang
notSpanish:
MessageBox MB_OK "Default Language"
finishLang:
Abort
FunctionEnd
deguix
7th June 2003 20:15 UTC
This convertion, MoNKi, give to me:
The return of GetUserLangId:
1046 | LANG_PORTUGUESE | SUBLANG_PORTUGUESE_BRAZILIAN
The return of ConvertLangIdToNeutral:
22 | LANG_PORTUGUESE | SUBLANG_NEUTRAL
MoNKi
7th June 2003 20:24 UTC
:up: Works!
Well if there is a .nlf for SUBLANG_PORTUGUESE_BRAZILIAN there is no need to use the function to convert it to neutral, but if there is no nlf file use it for a default portuguese file.
First compare your LANGID with all sublangs that are translated and then use the ConvertLangIdToNeutral to use a default for all non translated sublangs.
Joel
7th June 2003 20:38 UTC
Language Neutral=10
Spanish...seems to work :up: :)
[edit]
check this site of other countries codes:
http://www.science.co.il/Language-Lo....asp?s=decimal
[/edit]
MoNKi
7th June 2003 21:54 UTC
I have created a script that uses a macro, it should detect spanish, english, portuguese and portuguese_brazilian. Please deguix test it and tell me if it works with portuguese_brazilian. And if it works, can i upload to the archive the script or need somebody with admin rights?
MoNKi
7th June 2003 21:57 UTC
Sorry, forgot the attach
deguix
7th June 2003 22:57 UTC
Ok! Works!
And if it works, can i upload to the archive the script or need somebody with admin rights?
You can upload, registering in the Archive (to be with your name) or like anonymous (but can be changed by everyone).
Sunjammer
7th June 2003 23:01 UTC
You cannot upload files unless you have admin rights but this doesn't affect your ability to create pages of text including scripts and anything else you might want to write about :)
kichik
8th June 2003 14:26 UTC
The user's language is detected by NSIS, the closest language in the instsaller's language table is choosen and its ID is set in $LANGUAGE. If you want to get the language name use a LangString with the language's name as the value for each language. Example:
LangString language_name ${LANG_ENGLISH} "English"
LangString language_name ${LANG_FRENCH} "French"
# ...
If you want language names of languages that are not present in the installer use the code above.
MoNKi
8th June 2003 14:37 UTC
Kichik are you sure? If i delete the onInit function of the language.nsi example (I not select a language) it not detect that I am using spanish.
kichik
8th June 2003 14:47 UTC
Yes MoNKi, it should choose the current language the user is using. NSIS uses GetUserDefaultLangID. If it can't find a perfect match for both the main language and the sublanguage it looks for match in the main language alone. If it can't find a match there either it takes the first language - "the default language".
MoNKi
8th June 2003 14:48 UTC
NSIS says that my langid is 1033 (LANG_ENGLISH, SUBLANG_ENGLISH_US), Spanish is 1034, and i'm using SUBLANG_SPANISH_MODERN (3082).
I'm loading all language files, including spanish, and it don't works.
kichik
8th June 2003 15:42 UTC
Fixed in latest CVS version. It was broken since Ui.c version 1.14 and we are now at 1.149...
MoNKi
8th June 2003 15:48 UTC
Ok now works, thanks kichik. No need of complicated scripts.