2 * angular-translate - v2.14.0 - 2017-02-11
4 * Copyright (c) 2017 The angular-translate team, Pascal Precht; Licensed MIT
6 (function (root, factory) {
7 if (typeof define === 'function' && define.amd) {
8 // AMD. Register as an anonymous module unless amdModuleId is set
9 define([], function () {
12 } else if (typeof exports === 'object') {
13 // Node. Does not work with strict CommonJS, but
14 // only CommonJS-like environments that support module.exports,
16 module.exports = factory();
22 $translateStaticFilesLoader.$inject = ['$q', '$http'];
23 angular.module('pascalprecht.translate')
26 * @name pascalprecht.translate.$translateStaticFilesLoader
31 * Creates a loading function for a typical static file url pattern:
32 * "lang-en_US.json", "lang-de_DE.json", etc. Using this builder,
33 * the response of these urls must be an object of key-value pairs.
35 * @param {object} options Options object, which gets prefix, suffix, key, and fileMap
37 .factory('$translateStaticFilesLoader', $translateStaticFilesLoader);
39 function $translateStaticFilesLoader($q, $http) {
43 return function (options) {
45 if (!options || (!angular.isArray(options.files) && (!angular.isString(options.prefix) || !angular.isString(options.suffix)))) {
46 throw new Error('Couldn\'t load static files, no files and prefix or suffix specified!');
51 prefix: options.prefix,
52 suffix: options.suffix
56 var load = function (file) {
57 if (!file || (!angular.isString(file.prefix) || !angular.isString(file.suffix))) {
58 throw new Error('Couldn\'t load static file, no prefix or suffix specified!');
67 if (angular.isObject(options.fileMap) && options.fileMap[fileUrl]) {
68 fileUrl = options.fileMap[fileUrl];
71 return $http(angular.extend({
75 .then(function(result) {
78 return $q.reject(options.key);
83 length = options.files.length;
85 for (var i = 0; i < length; i++) {
87 prefix: options.files[i].prefix,
89 suffix: options.files[i].suffix
93 return $q.all(promises)
94 .then(function (data) {
95 var length = data.length,
98 for (var i = 0; i < length; i++) {
99 for (var key in data[i]) {
100 mergedData[key] = data[i][key];
109 $translateStaticFilesLoader.displayName = '$translateStaticFilesLoader';
110 return 'pascalprecht.translate';