Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
juristr committed Sep 27, 2015
1 parent 5b6cc23 commit 27a241d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
75 changes: 75 additions & 0 deletions dist/angular-translate-loader-pluggable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports);
} else {
var mod = {
exports: {}
};
factory(mod.exports);
global.angularTranslateLoaderPluggable = mod.exports;
}
})(this, function (exports) {
'use strict';

angular.module('angular-translate-loader-pluggable', ['pascalprecht.translate']).provider('translatePluggableLoader', translatePluggableLoaderProvider);

function translatePluggableLoaderProvider() {
var loaders = [];
var translationTable = {};

this.useLoader = function (loaderName, options) {
loaders.push({
name: loaderName,
options: options
});

return this;
};

this.translations = function (language, translations) {
translationTable[language] = angular.extend({}, translationTable[language], translations);

return this;
};

this.$get = ["$q", "$injector", function ($q, $injector) {
return function (options) {
var deferred = $q.defer();

var loaderInstances = [];

// lookup in translation table
loaderInstances.push((function () {
var deferred = $q.defer();

deferred.resolve(translationTable[options.key]);

return deferred.promise;
})());

// lookup in loaders
for (var i = 0; i < loaders.length; i++) {
var loader = loaders[i];

// get the loader and resolve it, passing in the required options
var loaderPromise = $injector.get(loader.name)(angular.extend(options, loader.options));
loaderInstances.push(loaderPromise);
}

$q.all(loaderInstances).then(function (loaders) {
var result;

for (var i = 0; i < loaders.length; i++) {
result = angular.extend({}, result, loaders[i]);
}

deferred.resolve(result);
});

return deferred.promise;
};
}];
}
});
2 changes: 2 additions & 0 deletions dist/angular-translate-loader-pluggable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/angular-translate-loader-pluggable.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
"repository": {
"type": "git",
"url": "https://github.com/juristr/angular-translate-loader-pluggable.git"
}
}
},
"version": "1.0.3"
}

0 comments on commit 27a241d

Please sign in to comment.