Commit e448e8cd authored by 吕兵川's avatar 吕兵川

[dev]2.18.4

parent 5c88f0d3
/*! /*!
* angular-translate - v2.13.1 - 2016-12-06 1 * angular-translate - v2.18.4 - 2021-01-14
* *
* Copyright (c) 2016 The angular-translate team, Pascal Precht; Licensed MIT * Copyright (c) 2021 The angular-translate team, Pascal Precht; Licensed MIT
*/ */
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
define([], function () { define([], function () {
return (factory()); return (factory());
}); });
} else if (typeof exports === 'object') { } else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but // Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports, // only CommonJS-like environments that support module.exports,
// like Node. // like Node.
...@@ -19,94 +19,94 @@ ...@@ -19,94 +19,94 @@
} }
}(this, function () { }(this, function () {
$translateStaticFilesLoader.$inject = ['$q', '$http']; $translateStaticFilesLoader.$inject = ['$q', '$http'];
angular.module('pascalprecht.translate') angular.module('pascalprecht.translate')
/** /**
* @ngdoc object * @ngdoc object
* @name pascalprecht.translate.$translateStaticFilesLoader * @name pascalprecht.translate.$translateStaticFilesLoader
* @requires $q * @requires $q
* @requires $http * @requires $http
* *
* @description * @description
* Creates a loading function for a typical static file url pattern: * Creates a loading function for a typical static file url pattern:
* "lang-en_US.json", "lang-de_DE.json", etc. Using this builder, * "lang-en_US.json", "lang-de_DE.json", etc. Using this builder,
* the response of these urls must be an object of key-value pairs. * the response of these urls must be an object of key-value pairs.
* *
* @param {object} options Options object, which gets prefix, suffix, key, and fileMap * @param {object} options Options object, which gets prefix, suffix, key, and fileMap
*/ */
.factory('$translateStaticFilesLoader', $translateStaticFilesLoader); .factory('$translateStaticFilesLoader', $translateStaticFilesLoader);
function $translateStaticFilesLoader($q, $http) {
'use strict';
return function (options) {
if (!options || (!angular.isArray(options.files) && (!angular.isString(options.prefix) || !angular.isString(options.suffix)))) {
throw new Error('Couldn\'t load static files, no files and prefix or suffix specified!');
}
function $translateStaticFilesLoader($q, $http) { if (!options.files) {
options.files = [{
prefix: options.prefix,
suffix: options.suffix
}];
}
'use strict'; var load = function (file) {
if (!file || (!angular.isString(file.prefix) || !angular.isString(file.suffix))) {
throw new Error('Couldn\'t load static file, no prefix or suffix specified!');
}
return function (options) { var fileUrl = [
file.prefix,
options.key,
file.suffix
].join('');
if (!options || (!angular.isArray(options.files) && (!angular.isString(options.prefix) || !angular.isString(options.suffix)))) { if (angular.isObject(options.fileMap) && options.fileMap[fileUrl]) {
throw new Error('Couldn\'t load static files, no files and prefix or suffix specified!'); fileUrl = options.fileMap[fileUrl];
} }
if (!options.files) {
options.files = [{
prefix: options.prefix,
suffix: options.suffix
}];
}
var load = function (file) { return $http(angular.extend({
if (!file || (!angular.isString(file.prefix) || !angular.isString(file.suffix))) { url: fileUrl,
throw new Error('Couldn\'t load static file, no prefix or suffix specified!'); method: 'GET'
}, options.$http))
.then(function(result) {
return result.data;
}, function () {
return $q.reject(options.key);
});
};
var promises = [],
length = options.files.length;
for (var i = 0; i < length; i++) {
promises.push(load({
prefix: options.files[i].prefix,
key: options.key,
suffix: options.files[i].suffix
}));
} }
var fileUrl = [ return $q.all(promises)
file.prefix, .then(function (data) {
options.key, var length = data.length,
file.suffix mergedData = {};
].join('');
if (angular.isObject(options.fileMap) && options.fileMap[fileUrl]) { for (var i = 0; i < length; i++) {
fileUrl = options.fileMap[fileUrl]; for (var key in data[i]) {
} mergedData[key] = data[i][key];
}
}
return $http(angular.extend({ return mergedData;
url: fileUrl, });
method: 'GET',
params: ''
}, options.$http))
.then(function(result) {
return result.data;
}, function () {
return $q.reject(options.key);
});
}; };
}
var promises = [], $translateStaticFilesLoader.displayName = '$translateStaticFilesLoader';
length = options.files.length; return 'pascalprecht.translate';
for (var i = 0; i < length; i++) {
promises.push(load({
prefix: options.files[i].prefix,
key: options.key,
suffix: options.files[i].suffix
}));
}
return $q.all(promises)
.then(function (data) {
var length = data.length,
mergedData = {};
for (var i = 0; i < length; i++) {
for (var key in data[i]) {
mergedData[key] = data[i][key];
}
}
return mergedData;
});
};
}
$translateStaticFilesLoader.displayName = '$translateStaticFilesLoader';
return 'pascalprecht.translate';
})); }));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment