Getting error i18nLabels is undefined in Custom Widget

852
10
08-30-2021 08:41 AM
Danik-B
New Contributor III

I've created a custom widget in web appbuilder developer edition.  I can add it to an app within web appbuilder without issue but when I try to launch the app I get an "i18nLabels is undefined" error.

Has anyone encountered this?

0 Kudos
10 Replies
KenBuja
MVP Honored Contributor

What does your nls/strings.js file look like?

0 Kudos
Danik-B
New Contributor III

This is what I've got:

define({
  root: ({
    _widgetLabel: "Show Customers and Trade Area",
    _featureAction_showCustomers: "Show Customers",
    _featureAction_showTradeArea: "Show Trade Area"
  }),
  "ar": 0,
  "bs": 0,
  "cs": 0,
  "da": 0,
  "de": 0,
  "el": 0,
  "es": 0,
  "et": 0,
  "fi": 0,
  "fr": 0,
  "he": 0,
  "hr": 0,
  "it": 0,
  "id": 0,
  "ja": 0,
  "ko": 0,
  "lt": 0,
  "lv": 0,
  "nb": 0,
  "nl": 0,
  "pl": 0,
  "pt-br": 0,
  "pt-pt": 0,
  "ro": 0,
  "ru": 0,
  "sr": 0,
  "sv": 0,
  "th": 0,
  "tr": 0,
  "vi": 0,
  "zh-cn": 0,
  "zh-hk": 0,
  "zh-tw": 0
});
0 Kudos
KenBuja
MVP Honored Contributor

Try removing the parenthesis from "root". The documentation strings file looks like this

define({
    root:{
        label1: "I am a demo widget.",
        label2: "This is configurable."
    },
    "zh-cn": true    
});

 

I don't have any other languages in my app so far, so mine just looks like this.

define({
  root: {
    allSelections: "All selections",
    appliedChanges: "Successfully applied changes",
    appliedFailed: "Applied failed!",
    //etc
  }
  // add supported locales below:
  // , "zh-cn": true
});

. You don't need to add all the language options until you have created their appropriate strings files.

0 Kudos
Danik-B
New Contributor III

Still getting the error.  I only added all the language options because I was getting the error and thought I needed them.

As for the parenthesis in root.  I removed it but it did not change anything.  Funny thing is that I got that file from the CustomWidgetTemplate in samplewidgets.  They all seem to have those parenthesis but as you note the doc says otherwise.

0 Kudos
KenBuja
MVP Honored Contributor

Is your file structure like what's shown on this page?

How are you using the nls variables in you Widget.html or Widget.js files?

Here are the examples from my widget:

Widget.html

    <div data-dojo-attach-point="btnSignIn" id="signinbtn" class="jimu-btn apply"
         data-dojo-attach-event="onclick:signIn">
      ${nls.signin}
    </div>

Widget.js

resultMessage = this.nls.allSelections;
0 Kudos
Danik-B
New Contributor III

I have no variables in my nls/strings.js. Just the _widgetLabel and two _featureAction_.

I'm really not sure what is going on.  Thanks for your help though.

0 Kudos
KenBuja
MVP Honored Contributor

I mean how are you using _widgetLabel and the others in your app?

0 Kudos
Danik-B
New Contributor III

I'm not.  _widgetLabel is just the name of the widget as it appears in web appbuilder and the _featureAction_ labels is what shows up when you click a feature.  They are not strings used in the app.

0 Kudos
KenBuja
MVP Honored Contributor

So where are you getting the error about "i18nLabels"?

0 Kudos