-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(language): add support language in lib (#13)
* feat(language): add support language in lib * Update fr.json * Update app.component.ts * Update en.json * Update fr.json * Update module.ts * Update language.service.spec.ts * Update language.service.ts
- Loading branch information
Showing
18 changed files
with
84 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { TranslateService } from 'ng2-translate'; | ||
import { Http, Response } from "@angular/http"; | ||
|
||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
declare function require(arg:string): any; | ||
|
||
@Injectable() | ||
export class LanguageService { | ||
|
||
constructor(public translate: TranslateService) { | ||
translate.setDefaultLang('en'); | ||
const browserLang = translate.getBrowserLang(); | ||
translate.use(browserLang.match(/en|fr/) ? browserLang : 'en'); | ||
constructor(private translate: TranslateService, | ||
private http: Http) { | ||
const lang = this.getLanguage(); | ||
|
||
const translation = require(`../../../assets/locale/${lang}.json`); | ||
this.translate.setTranslation(lang, translation, true); | ||
// this.readTranslation('/lib/assets/locale/', lang); | ||
|
||
this.translate.setDefaultLang('en'); | ||
this.translate.use(lang); | ||
} | ||
|
||
public getLanguage(): string { | ||
const browserLang = this.translate.getBrowserLang(); | ||
return browserLang.match(/en|fr/) ? browserLang : 'en'; | ||
} | ||
|
||
public readTranslation(prefix: string, lang: string = this.getLanguage()): any { | ||
return this.http.get(`${prefix}${lang}.json`) | ||
.map((res: Response) => res.json()) | ||
.subscribe((translation) => { | ||
this.translate.setTranslation(lang, translation, true); | ||
}); | ||
} | ||
|
||
public setTranslation(lang: string, translation: Object): void { | ||
this.translate.setTranslation(lang, translation, true); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters