Skip to content

Resources request pending while localize already called #143

@HJK181

Description

@HJK181

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions