-
Notifications
You must be signed in to change notification settings - Fork 1k
Returning multiple promises from a custom translation loader #70
Comments
Hey @danielbsig ! So, the problem here is, that you're returning an array of resolved values through You could either define loaders for your different sub apps, or we have to teach angular-translate to handle sets of promised values :) I think the latter would be a cool thing! |
But it won't work how its currently implemented, since the resolved data, which is actually a translation table, has to map to a corresponding language key. Now, when We only have the key which should be used in this case. |
Ah damn, just looked at your code again. Your loader tries to load translation tables for just one key, for sure. Okay, so I think we can implement this. Do you want to make a PR, or should I take care of it? |
Okay, that was easy. Landed in canary right here: 0e5d6d9 will make a minor release soonish! |
Landed in master Now do |
Lemme know if everything works as expected! |
Yes, this is the solution I came up with as well (although I have an additional check if this is an array of promises, as I see it the JSON file could theoretically contain an array of language definitions, but this is unlikely...) And this works... kind of, but not completely. I'm not sure why, there seems to be a timing issue here, since some elements do get translated, but others won't. I'm not sure if a $scope.apply() would be needed, I have to investigate this a bit further. I'm also having problems with loading json files which contain sub-definitions, i.e. something like this: { but this is another problem and shouldn't be a part of this issue :-) |
@danielbsig okay, so how about setting up a plunker with your exact problem, so I can take a look at it. Would love to help you out! |
Yep, that was next on my TODO list :-) |
Great, just post the plunk here when you're done |
Check this out: I may have made some errors, but at least this behaves in a similar way. |
Okay, taking a look at it now |
Here's the fix: http://plnkr.co/edit/1gtXwr?p=preview
|
It's line 20 in app.js by the way :) |
Ah thank you very much :-) I'm still a bit rusty when it comes to the concept of a promise. But this is then fully resolved! |
Awesome! |
I've implemented a custom translation loader, which basically loads a single .json file using $http, pretty much in the same way as in the plunker example (http://plnkr.co/edit/n6MEMU).
My application is made out of several individual "apps", and each app will maintain its own list of translated texts in their own files, so my code needs to take this into account. I've experimented with using $q.all() to create a single promise object out of a list of promise objects for each sub-app:
mainApp.factory('languageLoader', function ($http, $q) {
return function (options) {
});
Perhaps I'm making some mistake, and perhaps the library should be able to handle this, because if the code looks like this, then no translations work at all.
The text was updated successfully, but these errors were encountered: