ng-localize
Version:
> Localize your Angular apps
1 lines • 2.38 kB
JavaScript
!function(t,n,e){"use strict";function r(){function t(t,n,e){return o[t]={},angular.copy(n,o[t]),(e||null===l.active)&&i(t),l}function n(t){return t&&r(t),l}function e(){var t=[];for(var n in o)o.hasOwnProperty(n)&&t.push(n);return t}function r(t){angular.isArray(t)||(t=[t]);for(var n=0,e=t.length;e>n;n++){var r=t[n];if(i(t[n]))return!0;(-1!==r.indexOf("-")||-1!==r.indexOf("_"))&&(t.push(r.substring(0,Math.max(r.indexOf("-"),r.indexOf("_")))),e++)}return!1}function i(t){return t&&o[t]?(l.activeId=t,l.active=o[t],!0):!1}function a(t){return l.strictMode=!!t,l.strictMode}var o={},l={active:null,activeId:null,strictMode:!1};this.add=t,this.get=n,this.list=e,this.set=r,this.strict=a,this.$get=["$rootScope",function(i){return{add:t,get:n,list:e,set:function(){for(var t=arguments.length,n=Array(t),e=0;t>e;e++)n[e]=arguments[e];return r.apply(null,n)?(i.$broadcast("LocaleChange"),!0):!1},strict:a}}]}angular.module("localize.storage",[]).provider("LocalizeStorage",r)}(window,document),function(t,n,e){"use strict";function r(t,n){var e=n.get();return function(n){for(var r=arguments.length,i=Array(r>1?r-1:0),a=1;r>a;a++)i[a-1]=arguments[a];var o=e.active[n];if(!o){var l='No translation has been found for the id "'+n+'"';if(e.strictMode){var c=new Error;throw c.name="TranslationNotFoundException",c.message=l,c}t.warn(l),o=n}var u=o.replace(/\{(\d+)}/g,function(t,n){return i[n]});return u}}angular.module("localize.service",["localize.storage"]).service("localize",r),r.$inject=["$log","LocalizeStorage"]}(window,document),function(t,n,e){"use strict";function r(t){return function(){for(var n=arguments.length,e=Array(n),r=0;n>r;r++)e[r]=arguments[r];return t.apply(null,e)}}angular.module("localize.filter",["localize.service"]).filter("localize",r),r.$inject=["localize"]}(window,document),function(t,n,e){"use strict";function r(t,n,e,r,i){return{restrict:"AE",link:function(t,n,r){function a(){var t=[r.key].concat(o),a=i.apply(null,t);n="localizeHtml"in r?n.html(e.getTrustedHtml(a)):n.text(a)}var o=t.$eval(r.vars);angular.isArray(o)||(o=[o]);var l=t.$watchCollection(r.vars,function(t,n,e){angular.equals(t,n)||(o=t,a())}),c=t.$on("LocaleChange",a);n.on("$destroy",function(){l(),l=null,c(),c=null}),a()}}}angular.module("localize.directive",["localize.service"]).directive("localize",r),r.$inject=["$compile","$filter","$sce","$log","localize"]}(window,document);