Skip to content
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

parser.flattenObject is called too often #47

Closed
ribizli opened this issue Feb 29, 2016 · 5 comments
Closed

parser.flattenObject is called too often #47

ribizli opened this issue Feb 29, 2016 · 5 comments

Comments

@ribizli
Copy link
Contributor

ribizli commented Feb 29, 2016

As the language definition JSON object can get complex, it is a performance penalty to always flatten this JSON, any time a translate.get (or translate.instant) is called.

I'd recommend the other way: parsing the key (split by dot) and try to address the JSON field recursively.

E.g. (just a dummy demonstration):

let key = 'keyA.keyB.keyC';
let keys = key.split('.');
let value;
try {
  value = obj;
  for (let i = 0; i < keys.length; i++) {
    value = value[key[i]];
  }
} catch (e) {
  value = '!!!not found';
}
@ocombe
Copy link
Member

ocombe commented Feb 29, 2016

Hmm interesting yes, I'll take a look at this. If you want to do a PR you can :)

@ribizli
Copy link
Contributor Author

ribizli commented Feb 29, 2016

During the PR I recognized that the bundles/ng2-translate.js is also checked in. I think it is unneeded, since prepublish creates this file for npm, right?

@ocombe
Copy link
Member

ocombe commented Feb 29, 2016

Well it's nice to have it on github if people need it for plunkr (or something like that).

@ribizli
Copy link
Contributor Author

ribizli commented Feb 29, 2016

@ocombe
Copy link
Member

ocombe commented Feb 29, 2016

Ahh nice, I didn't know that one.
When I have the time I'll add a plunkr that people can fork for issues, I'll use that, thanks.

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

No branches or pull requests

2 participants