-
Notifications
You must be signed in to change notification settings - Fork 57
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
How can i use Localize in ready Function ? #57
Comments
I think it should be |
You can use it like that: this.async(function(){
this.localize('translation')
},100); |
@hyyan |
Thanks guys ! I will try it later. For example : See the showToast() function <script>
Polymer({
is: 'my-login',
ready: function() {
this.async(function() {
this.showToast("This is a message...");
},100);
},
otherFunction: function() {
this.showToast("This is a message...");
},
showToast: function(message) {
toast.show({text: message, duration: 5000});
}
});
</script> Thanks, |
Just replace the text message with |
Hi guys ! I tried this after your recommendation : toastMessage.show({horizontalAlign: 'right', verticalAlign: 'top', duration: 5000, text: this.async(function() { this.localize('login_failed'); },100)}); And I still have : Uncaught ReferenceError: this.localize is not defined(…) Loïc. |
@SheanYu this.async((function() {
toastMessage.show({
horizontalAlign: 'right',
verticalAlign: 'top',
duration: 5000,
text: this.localize('login_failed')
});
}).bind(this), 100); |
@davebaol Note that i'm in the ready function : ready: function() {
...
loginForm.addEventListener('iron-form-response', function(event) {
if (event.detail.response.error) {
this.async((function() {
toastMessage.show({
horizontalAlign: 'right',
verticalAlign: 'top',
duration: 5000,
text: this.localize('login_failed')
});
}).bind(this), 100);
} else {
...
}
});
...
}, |
@SheanYu |
With this : ready: function() {
...
loginForm.addEventListener('iron-form-response', function(event) {
if (event.detail.response.error) {
this.async((function() {
toastMessage.show({
horizontalAlign: 'right',
verticalAlign: 'top',
duration: 5000,
text: this.localize('login_failed')
});
}).bind(this), 100);
} else {
...
}
}).bind(this);
...
}, I got this error : Uncaught TypeError: Cannot read property 'bind' of undefined(…)
ready @ my-login.html:165
_invokeBehavior @ polymer-micro.html:455
_doBehavior @ polymer-micro.html:445
_readySelf @ polymer-mini.html:88
_ready @ polymer-mini.html:75
_tryReady @ polymer-mini.html:60
_initFeatures @ polymer.html:4053
createdCallback @ polymer-micro.html:202
window.Polymer @ polymer-micro.html:65
(anonymous function) @ my-login.html:124 |
@SheanYu loginForm.addEventListener('iron-form-response', (function(event) {
...
}).bind(this)); |
I'm having problems too with localize in the ready event. It says localize is not a function. The (ugly) async approach works most of the times, but sometimes 100ms is not enough and it fails. I know I can increase the timeout, but I think it would be better to have a solution to make it always work. I understand that resources may not yet be loaded, but I expect it to be another kind of error... |
I don't think it's a matter of resources not loaded yet |
@davebaol Me neither, I think it has something to do with the computed properties and the way Polymer handles them. But, why not make localize a regular function? |
@lluisgener |
@davebaol Or make the Polymer team invoke the ready event when computed properties have been initialized, if it's possible... |
It seems you can work around this issue using computed properties, like this:
|
So is there even any way of calling localize from within a polymer element, indifferent of in the ready() function or any other element function? As it is usual to process UI texts in functions, it is necessary to grab translations in the code and then pass it to the UI. Regards, |
Hm... sure, this is possible but creates an immense overhead (code size, complexity ...). This is just not possible for larger applications and can't be the solution the Polymer team wants to see. So I really hope they have another solution for us. :) |
I think that it's the way to go, because localize is a computed method to be able to change language during execution, and I think the better way to do it is with a calculated method, as it is. |
** Removed because of completely bullshit, sorry :D ** |
Doesn't |
I manage to resolve this way <link rel="import" href="../bower_components/app-localize-behavior/app-localize-behavior.html">
<dom-module id="x-custom">
<template>
<span> [[_greetings(name, localize)]]</span>
</template>
<script>
Polymer({
is: 'x-custom',
behaviors: [
Polymer.AppLocalizeBehavior
],
properties: {
name: String,
language: { type: String, value: 'zh-CN' }
},
attached: function() {
this.loadResources(this.resolveUrl('locales.json'));
},
_greetings: function(name, localize) {
return localize('hello')+ ' ' + name;
}
});
</script>
</dom-module> |
Hi :)
Localization behavior is working fine for me, but i don't know if i can use it in a ready function and how.
For exemple, for a login form, i want to show a toast with different informations in two language.
If login are good :
{{localize('login_succeeded', 'pseudo', event.detail.response.pseudo)}}
If login are wrong :
{{localize('login_failed')}}
If error :
{{localize('login_error')}}
My code :
locales.json
Thanks.
Greetings Loïc.
The text was updated successfully, but these errors were encountered: