rsanchez
2017-03-19 280daa7f3f858ecfef9c91ffd5dea1007f021048
securis/src/main/webapp/src/app/common/i18n.ts
....@@ -2,6 +2,18 @@
22 import { ModuleWithProviders, NgModule, Inject, Injectable, Directive, ElementRef, HostListener, Input, Renderer } from '@angular/core';
33 declare var navigator:any;
44
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
+
517 // Use as reference: https://github.com/ngx-translate/core/tree/master/src
618 @Injectable()
719 export class LocaleService {
....@@ -50,9 +62,11 @@
5062 * It works similar to MessageFormat in Java
5163 */
5264 _format(str: string, ...params: string[]) {
53
-
54
- return str.replace(/\{(\d+)\}/g, function(match, index) {
55
- return params[index];
65
+ var ocur = 0;
66
+ return str.replace(/\{(\d*)\}/g, function(match, index) {
67
+ var idx = index === '' ? ocur : +index;
68
+ ocur += 1;
69
+ return params[idx];
5670 });
5771 };
5872
....@@ -98,9 +112,10 @@
98112 }
99113 // Enviar evento cuando el idioma cambia al $rootScope
100114
101
- if (arguments.length === 1) return trans_msg;
115
+ if (params.length === 0) return trans_msg;
102116 return this._format(trans_msg, ...params);
103117 }
118
+
104119
105120 }
106121
....@@ -134,3 +149,5 @@
134149 }
135150
136151
152
+
153
+