-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extending Polymer.AppLocalizeBehavior #97
Comments
Have you tried loading the resources later, in |
Edit 27.06.2017: The issue happen when you don't lazy load your pages. I have the same problem than @sangron: undefined resources attribute. I implemented his code (I changed only names) to see what do we get when loading in Listening to app-localize-resources-loadedI used the event app-localize-resources-loaded to know when the resources are really loaded. I added few traces in the console to have an idea of the actual sequence: FormatMixin: connectedCallback() {
super.connectedCallback();
console.log("Add a listener to app-localize-resources-loaded");
this.addEventListener('app-localize-resources-loaded', function(e){
console.log('app-localize-resources-loaded', this.resources);
}.bind(this));
console.log('Calling this.loadResources()...');
this.loadResources(this.resolveUrl('/static/locales.json'));
}
static get properties() {
// ...
}
getLabel(a) {
console.log('getLabel() is called... this.resources is', this.resources);
var args = Array.prototype.slice.call(arguments);
var prop = args.join('');
var label = prop;
if(this.localize)
label = this.localize(prop);
return label;
} In the
|
@notwaldorf What is the status of this issue? Still not working here. |
The issue is trying to load the resources globally in the app using load resources. Child components load and are created before the network request is returning. When the network request does finally return the _computedLocalize function never gets triggered in the child component as the resources have been updated outside of the child component so it is not aware of the changes. One potential solution could be that any time _computeLocalize gets called and there is an existing ajax request to listen for the response of it and update then. That way all localizations should be triggered when the one ajax response occurs. |
I find myself having to do this in all localized elements:
This waits to construct any of the element's DOM until {{resources}} is non-empty/truthy. If I don't do this, I get localize() called before the resources are ready. I'm using PolymerElements/app-localize-behavior 2.0.1. |
Description
Creating a mixin/behavior to be extended by multiple elements, the
this.loadResources('/src/locales.json')
is not setting theresources
property, sothis.localize('res.key')
returnsundefined
Expected outcome
resources
being set with the object in the json fileActual outcome
resources
staysundefined
Steps to reproduce
formats-behavior.html
then in file legal-docs.html
and locales.json
I have debugged it and the constructor is being called, the json file is being loaded, confirming in the network tab in the devtools. But the
resource
property is not set.I have another app with this same pattern without problems, but it is using an earlier version of Polymer 2, so I am just guessing that something broke in recent changes.
Browsers Affected
The text was updated successfully, but these errors were encountered: