-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-translate-loader-url.js
68 lines (60 loc) · 1.92 KB
/
angular-translate-loader-url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*!
* angular-translate - v2.18.1 - 2018-05-19
*
* Copyright (c) 2018 The angular-translate team, Pascal Precht; Licensed MIT
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define([], function () {
return (factory());
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
factory();
}
}(this, function () {
$translateUrlLoader.$inject = ['$q', '$http'];
angular.module('pascalprecht.translate')
/**
* @ngdoc object
* @name pascalprecht.translate.$translateUrlLoader
* @requires $q
* @requires $http
*
* @description
* Creates a loading function for a typical dynamic url pattern:
* "locale.php?lang=en_US", "locale.php?lang=de_DE", "locale.php?language=nl_NL" etc.
* Prefixing the specified url, the current requested, language id will be applied
* with "?{queryParameter}={key}".
* Using this service, the response of these urls must be an object of
* key-value pairs.
*
* @param {object} options Options object, which gets the url, key and
* optional queryParameter ('lang' is used by default).
*/
.factory('$translateUrlLoader', $translateUrlLoader);
function $translateUrlLoader($q, $http) {
'use strict';
return function (options) {
if (!options || !options.url) {
throw new Error('Couldn\'t use urlLoader since no url is given!');
}
return $http(angular.extend({
url: options.url + '/' + options.key + '.json',
method: 'GET'
}, options.$http))
.then(function(result) {
return result.data;
}, function () {
return $q.reject(options.key);
});
};
}
$translateUrlLoader.displayName = '$translateUrlLoader';
return 'pascalprecht.translate';
}));