| .. | .. |
|---|
| 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'; |
|---|
| 3 | 4 | declare var navigator:any; |
|---|
| 4 | 5 | |
|---|
| 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 | | - |
|---|
| 17 | 6 | // Use as reference: https://github.com/ngx-translate/core/tree/master/src |
|---|
| 7 | + |
|---|
| 18 | 8 | @Injectable() |
|---|
| 19 | 9 | export class LocaleService { |
|---|
| 20 | 10 | get URL_TPL() {return 'src/lang/messages_{0}.json'}; |
|---|
| .. | .. |
|---|
| 23 | 13 | private _currentLang : string = null; |
|---|
| 24 | 14 | private _messages : any = null; |
|---|
| 25 | 15 | 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'; |
|---|
| 27 | 18 | this.lang = initLang || this.getBrowserLang(); |
|---|
| 28 | 19 | } |
|---|
| 29 | 20 | |
|---|
| .. | .. |
|---|
| 115 | 106 | if (params.length === 0) return trans_msg; |
|---|
| 116 | 107 | return this._format(trans_msg, ...params); |
|---|
| 117 | 108 | } |
|---|
| 118 | | - |
|---|
| 119 | 109 | |
|---|
| 120 | 110 | } |
|---|
| 121 | | - |
|---|
| 122 | 111 | |
|---|
| 123 | 112 | @Directive({ selector: '[i18n]' }) |
|---|
| 124 | 113 | export class I18nDirective { |
|---|
| .. | .. |
|---|
| 134 | 123 | } |
|---|
| 135 | 124 | } |
|---|
| 136 | 125 | |
|---|
| 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 | + |
|---|
| 137 | 140 | @NgModule({ |
|---|
| 138 | | - providers: [ <any>LocaleService ] |
|---|
| 141 | + providers: [ ] |
|---|
| 139 | 142 | }) |
|---|
| 140 | 143 | export class LocaleServiceModule { |
|---|
| 141 | 144 | static withConfig(initLang?: string): ModuleWithProviders { |
|---|
| 142 | 145 | return { |
|---|
| 143 | 146 | ngModule: LocaleServiceModule, |
|---|
| 144 | | - providers: [ |
|---|
| 145 | | - { provide: 'INITIAL_LANG', useValue: initLang } |
|---|
| 147 | + providers: [ |
|---|
| 148 | + { provide: 'INITIAL_LANG', useValue: initLang }, |
|---|
| 149 | + LocaleService |
|---|
| 146 | 150 | ] |
|---|
| 147 | 151 | } |
|---|
| 148 | 152 | } |
|---|