- NSIS Discussion
- function for showing diff translated strings
Archive: function for showing diff translated strings
coco_vc
3rd May 2006 16:40 UTC
function for showing diff translated strings
Hi all,
I have in .onInit to do different checks and in case smth fails I have to show MsgBoxes in the specific language. For this I do the ${Switch} $LANGUAGE trick. So I have several times the same code, for instance:
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
StrCpy $msg "${OLDER_VERSION_ALREADY_INSTALLED_ENGLISH}"
${Break}
${Case} ${LANG_FRENCH}
StrCpy $msg "${OLDER_VERSION_ALREADY_INSTALLED_FRENCH}"
${Break}
${Default} ; if we forget one language, show the english msgbox
StrCpy $msg "${OLDER_VERSION_ALREADY_INSTALLED_ENGLISH}"
${Break}
${EndSwitch}
and
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
StrCpy $msg "${NEED_TO_BE_ADMIN_LANG_ENGLISH}"
${Break}
${Case} ${LANG_FRENCH}
StrCpy $msg "${NEED_TO_BE_ADMIN_LANG_FRENCH}"
${Break}
${Default} ; if we forget one language, show the english msgbox
StrCpy $msg "${NEED_TO_BE_ADMIN_LANG_ENGLISH}"
${Break}
${EndSwitch}
and so on.
Those chunks of code look the same with the exception of the define which are in the above sample: OLDER_VERSION_ALREADY_INSTALLED_ENGLISH, OLDER_VERSION_ALREADY_INSTALLED_FRENCH, NEED_TO_BE_ADMIN_LANG_ENGLISH, NEED_TO_BE_ADMIN_LANG_FRENCH
Is there a way to create smth like a function and as a parameter to pass for instance OLDER_VERSION_ALREADY_INSTALLED_ or NEED_TO_BE_ADMIN_LANG_ so that I don't have the same code written over and over again? (and in this way for a new language I just have to add one line in the function not to change in each piece of code)
Thx,
Viv
Afrow UK
4th May 2006 09:06 UTC
!macro OLDER_VERSION_ALREADY_INSTALLED Language
${Case} ${LANG_${Language}}
StrCpy $msg "${OLDER_VERSION_ALREADY_INSTALLED_${Language}}"
${Break}
!macroend
!macro NEED_TO_BE_ADMIN Language
${Case} ${LANG_${Language}}
StrCpy $msg "${NEED_TO_BE_ADMIN_LANG_${Language}}"
${Break}
!macroend
...
${Switch} $LANGUAGE
!insertmacro OLDER_VERSION_ALREADY_INSTALLED ENGLISH
!insertmacro OLDER_VERSION_ALREADY_INSTALLED FRENCH
${Default} ; if we forget one language, show the english msgbox
StrCpy $msg "${OLDER_VERSION_ALREADY_INSTALLED_ENGLISH}"
${Break}
${EndSwitch}
...
${Switch} $LANGUAGE
!insertmacro NEED_TO_BE_ADMIN ENGLISH
!insertmacro NEED_TO_BE_ADMIN FRENCH
${Default} ; if we forget one language, show the english msgbox
StrCpy $msg "${NEED_TO_BE_ADMIN_LANG_ENGLISH}"
${Break}
${EndSwitch}
-Stu
coco_vc
4th May 2006 12:27 UTC
Hi Stu,
Thanks for your reply. Still in your sample whenever I add a new language I have to add a line in _each_ chunk of code, in your sample in the last 2 chunks like:
!insertmacro OLDER_VERSION_ALREADY_INSTALLED NEW_LANGUAGE
respectivelly
!insertmacro NEED_TO_BE_ADMIN NEW_LANGUAGE
which is what I would like to avoid.
The algorithm I was thinking about would look smth like:
function call_MsgBox(a_define)
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
StrCpy $msg "${a_define_ENGLISH}"
${Break}
${Case} ${LANG_FRENCH}
StrCpy $msg "${a_define_FRENCH}"
${Break}
${Default} ; if we forget one language, show the english msgbox
StrCpy $msg "${a_define_ENGLISH}"
${Break}
${EndSwitch}
MessageBox MB_ICONEXCLAMATION|MB_OK "$msg"
end function
and when calling the function would be smth like:
call_MsgBox(OLDER_VERSION_ALREADY_INSTALLED)
and
call_MsgBox(NEED_TO_BE_ADMIN)
which means whenever a new language is added the _only_ place I would have to change is in the first chunk of code by just adding:
${Case} ${LANG_NEW_LANGUAGE}
StrCpy $msg "${{a_define_NEW_LANGUAGE}"
${Break}
Is smth like this possible?
Thx,
Viv
coco_vc
5th May 2006 19:42 UTC
I didn't get any answer to this one. Does this mean this is not possible? or does this mean that no NSIS-guru has yet read this post? or maybe I wasn't clear enough with my question?
Thx,
Viv
Afrow UK
5th May 2006 20:14 UTC
There is no simple way.
-Stu
kichik
6th May 2006 12:12 UTC
You can't do it with a function, but you can create a macro from your switch.
coco_vc
8th May 2006 10:56 UTC
Thx guys for your answer.
> but you can create a macro from your switch.
Does this mean I would have to change only in one place when a new language is added? Or the solution you are talking about is similar with Stu's suggestion? (which btw is nice, but I am trying to get rid of the fact that I have to change in several similar places when I add a new language)
Thx,
Viv
kichik
8th May 2006 20:21 UTC
Yes, one place. It's a combination of Afrow's macros and your pseudo-function. Instead of your function, you'll have:
!macro lang_define var name
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
StrCpy ${var} "${${name}_ENGLISH}"
${Break}
${Case} ${LANG_FRENCH}
StrCpy ${var} "${${name}_FRENCH}"
${Break}
${Default} ; if we forget one language, show the english msgbox
StrCpy ${var} "${${name}_ENGLISH}"
${Break}
${EndSwitch}
!macroend
Then you can use it like this:
!insertmacro lang_define $0 somelangdefine
MessageBox MB_OK $0
You only have to a few lines for each new language, all in one place.
coco_vc
9th May 2006 14:11 UTC
Yes, it's exactly what I wanted and works just fine :) Thx a lot!
Viv