5

Is there anyway to include file by mention it with variable? I mean

StrCpy $1 "bla.nsh"
!include $1

?

or maybe getting value of variable that called by another variable such as:

StrCpy $1 "EN"
StrCpy $2 ${LANG_${1}_WELCOME_MESSAGE}

?

Thanks.

user2269104
  • 207
  • 2
  • 7

2 Answers2

4

Variables can only be used at runtime (running on the end-users machine), you need to use defines:

!define foo "bar"
!include "${foo}.nsh"

Edit:

You should be using the LangString instruction if you want to add custom translated strings, you can access a langstring at runtime with $(mystringid).

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Got it, but what about my second question? how can I use variable value calling with variable-in-variable (second code i gave) – user2269104 Aug 18 '13 at 20:40
  • StrCpy $2 "foo $1 bar" – Anders Aug 18 '13 at 21:35
  • You didnt got me. I mean, if $1 contain for ex. "EN" and i have define called `LANG_EN_WELCOME` how can i get the define with $1? i mean something like ${LANG_${1}_WELCOME} but its doesnt work for me. – user2269104 Aug 18 '13 at 21:45
  • You have to use a define for EN, I already told you, variables cannot be used at compile-time. Syntax: $thisIsAVar ${thisIsADefine} ${thisIs${DefineInside}ADefine} – Anders Aug 19 '13 at 01:30
  • ok, so maybe you can help me, i want to make my translation for few sentences by user system language.. how can i? – user2269104 Aug 19 '13 at 06:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35790/discussion-between-user2269104-and-anders) – user2269104 Aug 19 '13 at 19:00
3

Actually, Anders right. Think about that, when the compiler compiling your code, it need to know which files it need to include with your EXE file.

About the variable, you can use only with defines. again, because when you are compiling, the compiler will compile all the needed (in use) variables / defines, and you can't tell him use one that never been declared.. its little different from server side languages because here you are compiling and pack your code into EXE file which is assembled in your computer.

Idan Gozlan
  • 3,173
  • 3
  • 30
  • 47