PolymerElements / app-localize-behavior

Polymer behaviour to help internationalize your application
48 stars 55 forks source link

Resources request pending while localize already called #143

Open HJK181 opened 6 years ago

HJK181 commented 6 years ago

Description

I'm using the starter kit app where I pass the current language to all views within the shell. All views extend a mixin which loads the langauge resources for the current view in an observer of the language property:

 _languageChanged(currentLang, oldLang) {
        if (currentLang) {
          const viewName = this.getAttribute('name');
          this.loadResources(this.resolveUrl(`locales/${currentLang}/${viewName}.json`), currentLang);          
        }
      }

Now I find myself in situation where a call to this.localize returns undefined because the network request loading the language resources is still pending, while the view is being visible. The only solution I found so far is to wrap the whole view inside a

<template is="dom-if" if="{{resources}}">
 ...
</template>

And add an additional check to observers:

_currentChanged(visible, resources) {
  if (visible && resources) {
    this.localize(...)
 }
}

Isn't there a better solution then differing rendering until the locale resources are loaded?