Usage of multiple loaders
Is it possible to use both custom loader and static files loader at the same time?
Hello, @senthanal. It is impossible to use multiple loaders at the same time. But you can use the static files loader internally inside a custom loader.
So, in the custom loader, deferred.resolve( mergedData ); where mergedData is combining responses of custom loader's and static file loader's?
Yes, something like that.
I've done that. I merged both static files response and also custom loader's response. I see also angular translate's internal $translationTable[key] is updated.
Here, I've a different issue. The translations implemented via directive is showing translation ids instead of values but translations implemented via filter are working properly. Further strange stuff, this happens after every hard reload. Just normal reload does works properly for both directive and filter based translations. Anything, am doing wrong here?
Thanks :)
Further investigation.
if (!promiseToWaitFor) {
// no promise to wait for? okay. Then there's no loader registered
// nor is a one pending for language that comes from storage.
// We can just translate.
determineTranslation(translationId, interpolateParams, interpolationId, defaultTranslationText).then(deferred.resolve, deferred.reject);
} else {
promiseToWaitFor.then(function () {
determineTranslation(translationId, interpolateParams, interpolationId, defaultTranslationText).then(deferred.resolve, deferred.reject);
}, deferred.reject);
}
determineTranslation from this code is not invoked for every hard reload. The normal reload(F5) calls determineTranslation from this code and translations via directive is working. I now, am writting wierd. Its just my desparation resolve this issue. Anyways, thanks for the fast responses.
It looks like I'm unable to help you with this issue at the moment. Maybe @knalli or @tspaeth will be able to say something.
However, as I remember, there were some issues about reloading before. Maybe, this one is somehow related to them.
Anyways thanks. do you remember that issue? may be I find some useful information there....
@senthanal, no, unfortunately I don't remember them.
Please provide a Demo with your setup.
@DWand @senthanal hi, Can you please elaborate on how to get the response from the static loader in order to merge it inside the custom loader? Thanks!
@roy650 Hi, As mentioned before by @DWand, we can't use both loaders(static and custom) approach. So, in my case, I removed static loaders and used only custom loaders. Follows just an idea on how to merge translations from different resources.
var deferred = $q.defer(); // to work with promises .... var languageLoaderPromises = []; // Collects translation loaders promises .... languageLoaderPromises.push($http.get(...)); // Loads translations from a resource ..... languageLoaderPromises.push($http.get(...)); // Loads translations from another resource .... $q.all(languageLoaderPromises).then(function(response) { // Merge responses from both resources var data = {}; for(var i in response){ angular.extend(data, angular.isArray(response[i].data) ? response[i].data[0] : response[i].data); } deferred.resolve(data); });
return deferred.promise;
Its just an idea. There could be other solutions. This worked for me :)
Hope it helps! happy coding!!
@senthanal looks great! For now, we'll probably use something like that, so - Thanks!
Still, for future reference... @DWand mentioned that it would be possible to merge with the result from the static loader... And it would be great if he gave us a clue on how to achieve that.
On a more general note - my use case for the custom loader is for an ability to load the translations from a web resource and to be able to fall back to an alternative resource, should a web connection not be available (it's a hybrid-mobile-app, so the alternative is a local resource) - so if you have any other ideas for accomplishing that, I'd appreciate it.
Thanks anyway for the reply!!
I had a similar issue, where I have a series of potentially independent angular modules which use angular-translate for doing the localization. Each module should be free to use its own angular-translate loader, so one may directly pass the translations to $translate while other modules may use the partial loader and so on. In the end, when instantiated within a single application they should all play together nicely.
So I created this custom loader: https://github.com/juristr/angular-translate-loader-pluggable. Maybe it can help you with your use case as well. Let me know :smile:
@juristr Thank you for pointing out. Great plugin!
I'll close this.