rsanchez
2017-04-13 849f8f0acbe896cac7e531fee6895442382318cc
securis/src/main/webapp/src/app/common/i18n.ts
....@@ -1,20 +1,10 @@
1
-import { Http } from '@angular/http';
2
-import { ModuleWithProviders, NgModule, Inject, Injectable, Directive, ElementRef, HostListener, Input, Renderer } from '@angular/core';
1
+import { Http, HttpModule } from '@angular/http';
2
+import { ModuleWithProviders, NgModule, Inject, TypeProvider, Injectable, Directive, ElementRef, Renderer } from '@angular/core';
3
+import { BrowserModule } from '@angular/platform-browser';
34 declare var navigator:any;
45
5
-declare global {
6
- interface String {
7
- capitalize(): string;
8
- cap(): string;
9
- }
10
-}
11
-
12
-String.prototype.capitalize = function() {
13
- return this[0].toUpperCase() + this.slice(1);
14
-}
15
-String.prototype.cap = String.prototype.capitalize;
16
-
176 // Use as reference: https://github.com/ngx-translate/core/tree/master/src
7
+
188 @Injectable()
199 export class LocaleService {
2010 get URL_TPL() {return 'src/lang/messages_{0}.json'};
....@@ -23,7 +13,8 @@
2313 private _currentLang : string = null;
2414 private _messages : any = null;
2515 private _elements = new Array<ElementRef>();
26
- private constructor(private http: Http, @Inject('INITIAL_LANG') initLang: string) {
16
+ constructor(private http: Http, @Inject('INITIAL_LANG') initLang: string) {
17
+ var initLang = 'en';
2718 this.lang = initLang || this.getBrowserLang();
2819 }
2920
....@@ -115,10 +106,8 @@
115106 if (params.length === 0) return trans_msg;
116107 return this._format(trans_msg, ...params);
117108 }
118
-
119109
120110 }
121
-
122111
123112 @Directive({ selector: '[i18n]' })
124113 export class I18nDirective {
....@@ -134,15 +123,30 @@
134123 }
135124 }
136125
126
+
127
+
128
+declare global {
129
+ interface String {
130
+ capitalize(): string;
131
+ cap(): string;
132
+ }
133
+}
134
+String.prototype.capitalize = function() {
135
+ return this[0].toUpperCase() + this.slice(1);
136
+}
137
+String.prototype.cap = String.prototype.capitalize;
138
+
139
+
137140 @NgModule({
138
- providers: [ <any>LocaleService ]
141
+ providers: [ ]
139142 })
140143 export class LocaleServiceModule {
141144 static withConfig(initLang?: string): ModuleWithProviders {
142145 return {
143146 ngModule: LocaleServiceModule,
144
- providers: [
145
- { provide: 'INITIAL_LANG', useValue: initLang }
147
+ providers: [
148
+ { provide: 'INITIAL_LANG', useValue: initLang },
149
+ LocaleService
146150 ]
147151 }
148152 }