YOLO
YOLO

Reputation: 3

How can i use Localize in Function or property polymerJS using app-localize-behavior

Localization behavior is working fine for me, but i don't know if i can use it in a ready function and how.

If I use {{localize('greeting')}} in html, Its working fine. But I need to use through function

initErrorMessage: function(loc) {
  return localize(loc);
},

And I need to use in property as well.

datePickerRangeArray: {
    type: Array,
    value: function() {
      return [
        {"key": "!h8", "val": this.localize('last8hrs')},
        {"key": "!h12", "val": this.localize('last12hrs')},
        {"key": "!h24", "val": this.localize('last24hrs')},
        {"key": "!h168", "val": this.localize('last48hrs')},
        {"key": "current-day", "val": this.localize('CurrentDay')},
        {"key": "previous-day", "val": this.localize('PreviousDay')}];
    }
  }

I am getting error on this. How to achieve this. Thanks in advance.

Upvotes: 0

Views: 226

Answers (2)

Ananth A
Ananth A

Reputation: 331

Use this.async function and initialize with empty object and add localization in attached function with async function.

datePickerRangeArray: {
    type: Array,
    value: {}
  }


attached: function(){
   this.async(function(){
     datePickerRangeArray = [
        {"key": "!h8", "val": this.localize('last8hrs')},
        {"key": "!h12", "val": this.localize('last12hrs')},
        {"key": "!h24", "val": this.localize('last24hrs')},
        {"key": "!h168", "val": this.localize('last48hrs')},
        {"key": "current-day", "val": this.localize('CurrentDay')},
        {"key": "previous-day", "val": this.localize('PreviousDay')}];
    },10);   
}

Upvotes: 0

a1626
a1626

Reputation: 2964

Prefer using it in attached instead of ready as Polymer does not guarantee attributes', children's availability in ready callback.

Upvotes: 0

Related Questions