Question T2408
Visible to All Users

Deselect languages in Translation tab

created 6 years ago

[Ticket cloned from T1270: Default localization]

Hi Gregory,

If I add any language on Translation tab , surveyModel.getUsedLocales() returns selected languages.
If I deselect language check box on translation tab an invoke surveyModel.getUsedLocales() it still returns same value.

I don't want deselected language to be fetched in surveyModel.getUsedLocales() method. How this can be achieved ?

Regards,
Yuvraj

Answers approved by surveyjs Support

created 6 years ago

Hello,

The getSelectedLocales method have been implemented in SurveyJS Creator, so you need to load survey-creator package v1.1.2 (or higher) from npm or our Azure CDN. Here is live sample in plunker where you can open Translation tab, select some languages and after that, for example, open developer console window (F12 key) and in console call creator.translationValue.getSelectedLocales() to get array of selected locales for demonstration purpose. Of course you can call getSelectedLocales the same way in right place in you code. Be free if you have any questions

Thanks, Alex
SurveyJS Team

    created 6 years ago

    Hello Yuvraj,
    Do you have any strings with this deselected locale in your Survey JSON? Could you please check?

    Thank you,
    Andrew
    SurveyJS Team

      Show previous comments (41)

        How to pass values of this.activelocale to onActiveTabChanged method. I am fetching value of this.activelocale from data base.

        for e.g value of this.activelocale will be ['en' , bg] . this.activelocale is instance variable.

          I have resolved this issue using => operator . Thanks for your help.

          Also I have added one flag which will help to set values of checkbox first time i clicked on translation tab. If I change value of checkbox & come back to translation tab from other tab I don't want to loose selected check box values.

          this.editor.onActiveTabChanged.add((sender, options) => {
          if (options.tabName == "translation") {
          if (!this.isTranTabInitialised) {
          sender.translation.setSelectedLocales(this.activelocale);
          this.isTranTabInitialised = true;
          }
          }
          });

            The standard approach is the following:

            JavaScript
            var self = this; this.editor.onActiveTabChanged.add((sender, options) => { if (options.tabName == "translation") { if (!self.isTranTabInitialised) { sender.translation.setSelectedLocales(self.activelocale); self.isTranTabInitialised = true; } } });

            Thank you,
            Andrew
            SurveyJS Team