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

The key is returned until language file is available #1018

Closed
pedrocatre opened this Issue Apr 28, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@pedrocatre

pedrocatre commented Apr 28, 2015

If we use {{::'NEXT_BTN' | translate}} and the language file is still being fetched we get the key 'NEXT_BTN'. And then when the language file is available nothing changes because it was one time binded.

Is there a way to change this behaviour so we get undefined? If I recall correctly angular's one time binding is smart enough to only one time bind after the results is no longer undefined.

@knalli

This comment has been minimized.

Member

knalli commented Apr 28, 2015

One time binding conflicts with the asynchronous pattern (here: loading of translations). You should be aware that in case of asynchronous loading your page will be blank.

While you can add a custom error handler returning always undefined, this will not solve your actual problem: Here a demo http://plnkr.co/edit/F9bsLhIOKCNpkPR6Xbrc?p=preview The issue is we are treating undefined as being no specific result (in case of a log handler).

So: No, both combinations are not possible right now.

@knalli knalli closed this Apr 28, 2015

@knalli knalli reopened this Apr 28, 2015

@pedrocatre

This comment has been minimized.

pedrocatre commented Apr 28, 2015

Ok thank you for the detailed explanation!

I guess for now the best choice is to have the translations in the code. I cannot afford two way data binding in the translations in one of the views that can have more than 100 form fields being displayed with several bindings :/ or I can fork and make the change, seems easy enough.

"treating undefined as being no specific result": would it make sense to make this behaviour configurable (or just change the default behaviour) given how one time binding works?

@knalli

This comment has been minimized.

Member

knalli commented Apr 28, 2015

Actually, 100 bindings aren't so bad. But this decision is up to you.

An alternative strategy could be the manual way avoiding filter and directive using the service directly.

app.controller('YourController', function ($translate) {
  var self = this;
  this.texts = {};
  // maybe listen for the first initial language laded (via event)
  $translate(['array', 'with', 'all', 'your-keys'])
    .then( function (translations) {self.texts = translations;});
});

"treating undefined as being no specific result": would it make sense to make this behaviour configurable

I actually do not know the consequences or the intention. The main idea of the handler was originally logging purpose (so undefined would be the noop).

So: Yes, an additional behavior setting could be added. Perhaps you make a PR? :)

Closing this.

@knalli knalli closed this Apr 28, 2015

@pedrocatre

This comment has been minimized.

pedrocatre commented Apr 28, 2015

I did not mean 100 bindings, I know that would be fine. I said more than 100 elements each with their own bindings. It is fine on my machine but on a slower machine running ie9 it has an impact.

Thanks again. For now I will just import the language files, in the short term it makes it even faster to load because it does not have to make an extra request for a file, and I only have two languages. If this changes down the line I'll probably make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment