|
| 1 | +/*! |
| 2 | + * angular-translate - v2.14.0 - 2017-02-11 |
| 3 | + * |
| 4 | + * Copyright (c) 2017 The angular-translate team, Pascal Precht; Licensed MIT |
| 5 | + */ |
| 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 () { |
| 10 | + return (factory()); |
| 11 | + }); |
| 12 | + } else if (typeof exports === 'object') { |
| 13 | + // Node. Does not work with strict CommonJS, but |
| 14 | + // only CommonJS-like environments that support module.exports, |
| 15 | + // like Node. |
| 16 | + module.exports = factory(); |
| 17 | + } else { |
| 18 | + factory(); |
| 19 | + } |
| 20 | +}(this, function () { |
| 21 | + |
| 22 | +$translateUrlLoader.$inject = ['$q', '$http']; |
| 23 | +angular.module('pascalprecht.translate') |
| 24 | +/** |
| 25 | + * @ngdoc object |
| 26 | + * @name pascalprecht.translate.$translateUrlLoader |
| 27 | + * @requires $q |
| 28 | + * @requires $http |
| 29 | + * |
| 30 | + * @description |
| 31 | + * Creates a loading function for a typical dynamic url pattern: |
| 32 | + * "locale.php?lang=en_US", "locale.php?lang=de_DE", "locale.php?language=nl_NL" etc. |
| 33 | + * Prefixing the specified url, the current requested, language id will be applied |
| 34 | + * with "?{queryParameter}={key}". |
| 35 | + * Using this service, the response of these urls must be an object of |
| 36 | + * key-value pairs. |
| 37 | + * |
| 38 | + * @param {object} options Options object, which gets the url, key and |
| 39 | + * optional queryParameter ('lang' is used by default). |
| 40 | + */ |
| 41 | +.factory('$translateUrlLoader', $translateUrlLoader); |
| 42 | + |
| 43 | +function $translateUrlLoader($q, $http) { |
| 44 | + |
| 45 | + 'use strict'; |
| 46 | + |
| 47 | + return function (options) { |
| 48 | + |
| 49 | + if (!options || !options.url) { |
| 50 | + throw new Error('Couldn\'t use urlLoader since no url is given!'); |
| 51 | + } |
| 52 | + |
| 53 | + var requestParams = {}; |
| 54 | + |
| 55 | + requestParams[options.queryParameter || 'lang'] = options.key; |
| 56 | + |
| 57 | + return $http(angular.extend({ |
| 58 | + url: options.url, |
| 59 | + params: requestParams, |
| 60 | + method: 'GET' |
| 61 | + }, options.$http)) |
| 62 | + .then(function(result) { |
| 63 | + return result.data; |
| 64 | + }, function () { |
| 65 | + return $q.reject(options.key); |
| 66 | + }); |
| 67 | + }; |
| 68 | +} |
| 69 | + |
| 70 | +$translateUrlLoader.displayName = '$translateUrlLoader'; |
| 71 | +return 'pascalprecht.translate'; |
| 72 | + |
| 73 | +})); |
0 commit comments