Custom asyncLoader options.key includes double quotes initially
otsakir opened this issue · 3 comments
Description
I've implemented a custom language loader. This accepts an options object when the language changes. The first time this happens using:
$translateProvider.preferredLanguage('en-US');
the language includes additional double quotes. So instead of it being en-US
it's "en-US"
.
When further changing languages everything works as expected.
Your environment
- version of angular-translate: 2.18.1
- version of angular: 1.7.8
- which browser and its version: both chromium 71.0.3578.98 (Official Build) Built on Ubuntu and Firefox 65.0
Steps to reproduce
I've used this custom language loader:
$translateProvider.useCookieStorage();
$translateProvider.preferredLanguage('en-US');
...
angular.module('mymodule').factory('asyncLoader', function ($q, $timeout, $http) {
return function (options) {
var deferred = $q.defer();
var translations;
var langUrl = document.translations[options.key];
$http.get(langUrl).then(function (response) {
deferred.resolve(response.data);
}, function (response) {
deferred.reject(options.key);
});
return deferred.promise;
};
});
Expected behaviour
options.key
should never include double quotes
Hello,
as we had already mentioned in the issue's template, we need a working and as minimal as possible demo covering your specific use case or issue.
Follow these steps:
- Please open this plnkr base.
- Fork it (at the top left).
- Ensure the version of AngularJS and angular-translate is correct.
- Ensure all angular-translate plugins are available; reduce and remove anything you can.
- Write a minimal as possible demo for your specific issue.
- Save and freeze. Provide us the final link to your demo.
Sorry @knalli, i can't provide what you ask for. But here is what i can provide since i've investigated a bit further:
It seems that it all boils down to cookieStorage. When i used angular-translate 2.6.1 + angular 1.4.7 it used to store into NG_TRANSLATE_LANG_KEY cookie value as '%22en-US%22'. I'm not sure whether this is an angular-cookie feature on has do with the older angular-translate.
When i moved to angular-translate 2.18.1 + angular 1.7.8, in the same browser with the same old cookies, the asyncLoader got these double quotes i've mentioned obviously because they were already in the stale cookie. When i clearer the cookie and refreshed the application behaves ok.
So, technically it's not really a bug but the behaviour is little problematic and it crushed the application in case when one upgrades angular + angular-translate.
Ok. I'll close this. Others don't have such issues.
Anyway: If the issue is really with the storage module, you will find out it's actually a simple put()
& get()
api which you can create/extend yourself easily. You can write and plug in your own custom module (using cookie or something else).
https://angular-translate.github.io/docs/#/guide/10_storages