From 38b0782c887f046426c31766901906c614d73140 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 14 Mar 2017 13:51:56 +0000
Subject: [PATCH] #3527 feature - Added pack form

---
 securis/src/main/webapp/src/app/common/i18n.ts |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/securis/src/main/webapp/src/app/common/i18n.ts b/securis/src/main/webapp/src/app/common/i18n.ts
index b8132e1..58f1411 100644
--- a/securis/src/main/webapp/src/app/common/i18n.ts
+++ b/securis/src/main/webapp/src/app/common/i18n.ts
@@ -5,13 +5,14 @@
 // Use as reference: https://github.com/ngx-translate/core/tree/master/src
 @Injectable()
 export class LocaleService {
-    get URL_TPL() {return  'src/lang/messages-{0}.json'};
+    get URL_TPL() {return  'src/lang/messages_{0}.json'};
     
+	private _devLang : string = 'en';
 	private _currentLang : string = null;
     private _messages : any = null;
     private _elements = new Array<ElementRef>();
     private constructor(private http: Http, @Inject('INITIAL_LANG') initLang: string) {
-		this._currentLang = initLang || this.getBrowserLang();
+		this.lang = initLang || this.getBrowserLang();
     }
     
     get lang() : string {
@@ -21,7 +22,7 @@
     set lang(newLang: string) {
         this._currentLang = newLang;
         this.http.get(this._format(this.URL_TPL, newLang)).subscribe((data) => {
-            this._messages = data;
+            this._messages = data.json();
             this.reloadTexts();
         }); 
     }
@@ -48,7 +49,7 @@
     /**
      * It works similar to MessageFormat in Java
      */
-    _format(str: string, ...params: Array<string>) {
+    _format(str: string, ...params: string[]) {
         
         return str.replace(/\{(\d+)\}/g, function(match, index) {
             return params[index];
@@ -78,7 +79,7 @@
      * $L.get('hello'); // This returns "hola"
      * $L.get('Hello {0}!!', 'John'); // This returns: "Hola John!!" if language is spanish
      */
-    get(msg: string) : string {
+    get(msg: string, ...params: string[] ) : string {
         if (msg == null) {
             return '';
         }
@@ -90,16 +91,15 @@
                 trans_msg = this._messages[msg];
             } else if (this._messages[msg.toLowerCase()]) {
                 trans_msg = this._messages[msg.toLowerCase()];
-            } else {
-                this._currentLang !== 'es' && console.error("Missing i18 key: " + msg);
+            } else { 
+                (this._currentLang !== this._devLang) && console.error("Missing i18 key: " + msg);
                 trans_msg = msg;
             }
         }
         // Enviar evento cuando el idioma cambia al $rootScope
         
         if (arguments.length === 1) return trans_msg;
-        var params = Array.prototype.slice.call(arguments, 1);
-        return this._format.apply(trans_msg, params);
+        return this._format(trans_msg, ...params);
     }
     
 }
@@ -108,6 +108,7 @@
 @Directive({ selector: '[i18n]' })
 export class I18nDirective {
     constructor(private el: ElementRef, private renderer: Renderer, private $L: LocaleService) {
+        console.log(el);
     }
 
 	ngAfterViewChecked() {
@@ -124,7 +125,6 @@
 })
 export class LocaleServiceModule {
     static withConfig(initLang?: string): ModuleWithProviders {
-        console.log('Init lang with ' + initLang);
         return {
             ngModule: LocaleServiceModule,
             providers: [

--
Gitblit v1.3.2