Menu

#539 Caption cannot use variable LangStrings

3.0 Series
closed-fixed
nobody
None
5
2017-06-05
2017-01-06
Marshall
No

Var mycaption
Caption $mycaption

Function .onInit
${If} $whichProduct == 1
StrCpy $mycaption $(Product1Caption)
${Else}
StrCpy $mycaption $(Product2Caption)
${EndIf}
FunctionEnd

In the above example, the titlebar is always in English, regardless of what language the user's system is and what the rest of the installer pages appear in.

I assume because LangStrings are not loaded until after .onInit.

However, because changes to $mycaption after .onInit are ignored, it is not possible to set a dynamic caption that respects multiple languages.

It would be better if $mycaption could be set during .onGUIInit

Further more, manually changing the title bar text using SendMessage is fruitless - because as each new page is loaded the title bar gets reset to the saved caption.

Perhaps all of this could be solved by adding a SetCaption instruction, which sets the saved caption and updates the title bar text at the same time?

I suspect the exact same problems affect Name, although I haven't tested.

Discussion

  • Marshall

    Marshall - 2017-03-28

    To clarify, the problem is when you change $LANGUAGE during .onInit and use variable captions - becuase changes to $LANGUAGE aren't picked up until after .onInit, at which point it is too late to change the captions.

     
  • idleberg

    idleberg - 2017-03-28

    You can always change the caption at runtime. IIRC, it works like this:

    SendMessage $HWNDPARENT ${WM_SETTEXT} 0 'STR:New caption title'

     

    Last edit: idleberg 2017-03-28
  • Marshall

    Marshall - 2017-03-28

    Unfortunately that has to be called on every single page and the change is visible by the end user - the old caption appears, then changes to the desired caption a split second later - the change is very noticeable, particularly on slower machines.

     
    • Anders

      Anders - 2017-03-31

      Set the caption to " " if you want to perform this hack.

       
  • idleberg

    idleberg - 2017-03-28

    Have you tried pre / show functions?

     
  • Marshall

    Marshall - 2017-03-28

    Yes

     
  • Anders

    Anders - 2017-03-31

    With a patch like

    Index: Source/exehead/Ui.c
    ===================================================================
    --- Source/exehead/Ui.c (revision 6834)
    +++ Source/exehead/Ui.c (working copy)
    @@ -581,7 +581,7 @@
             SetActiveCtl(m_hwndOK);
           }
    
    -      mystrcpy(g_tmp,g_caption);
    +      GetNSISString(g_tmp,LANG_CAPTION);
           GetNSISString(g_tmp+mystrlen(g_tmp),this_page->caption);
           my_SetWindowText(hwndDlg,g_tmp);
    

    it does seem to react to changes to $mycaption in .onGuiInit but I assume there is a reason why it is not coded this way. The background window will not be updated but that should be easy to fix.

     

    Last edit: Anders 2017-03-31
    • Anders

      Anders - 2017-05-16

      This fully reproduces the issue

      Var mycaption 
      Caption $mycaption
      LoadLanguageFile "${NSISDIR}\Contrib\Language Files\English.nlf"
      LangString Product1Caption 1033 "Foo"
      LangString Product2Caption 1033 "Bar"
      LangString ^NextBtn 1033 "EngNext"
      LoadLanguageFile "${NSISDIR}\Contrib\Language Files\Swedish.nlf"
      LangString Product1Caption 1053 "Bork"
      LangString Product2Caption 1053 "BorkBork!"
      LangString ^NextBtn 1053 "SweNext"
      !include LogicLib.nsh
      Function .onInit
      StrCpy $Language ${LANG_SWEDISH}
      ${If} 1 == 2
          StrCpy $mycaption $(Product1Caption)
      ${Else}
          StrCpy $mycaption $(Product2Caption)
      ${EndIf}
      FunctionEnd
      Function .onGuiInit
      StrCpy $mycaption $(Product2Caption) ; This works with the patch I suggested
      #StrCpy $mycaption whatever
      #MessageBox mb_ok "$(^Caption)=$mycaption"
      FunctionEnd
      Page Components
      Page Components
      Page InstFiles ;*/
      
       

      Last edit: Anders 2017-05-16
  • Anders

    Anders - 2017-06-05
    • status: open --> closed-fixed
     

Log in to post a comment.