TranslateService
properties
currentLang
현재 사용 중인 언어currentLoader
현재 사용 중인 Loader (static loader by default)onLangChange
언어 변경 감지 EventEmitter.
LangChangeEvent
는lang: string
과translations: any
를 property로 가진다.onTranslationChange
onLangChange와 동일
An EventEmitter to listen to translation change events. ATranslationChangeEvent
is an object with the propertieslang: string
&translations: any
(an object containing your translations).
method
setDefaultLang(lang: string)
Sets the default language to use as a fallbackuse(lang: string): Observable<any>
Changes the lang currently usedgetTranslation(lang: string): Observable<any>
Gets an object of translations for a given language with the current loadersetTranslation(lang: string, translations: Object, shouldMerge: boolean = false)
Manually sets an object of translations for a given language, setshouldMerge
to true if you want to append the translations instead of replacing themaddLangs(langs: Array<string>)
Add new langs to the listgetLangs()
현재 사용 가능한 언어 배열 반환get(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object>
key에 해당하는 value를 가져온다.instant(key: string|Array<string>, interpolateParams?: Object): string|Object
Gets the instant translated value of a key (or an array of keys).
This method is synchronous and the default file loader is asynchronous. You are responsible for knowing when your translations have been loaded and it is safe to use this method. If you are not sure then you should use theget
method instead.set(key: string, value: string, lang?: string)
Sets the translated value of a keyreloadLang(lang: string): Observable<string|Object>
Calls resetLang and retrieves the translations object for the current loaderresetLang(lang: string)
Removes the current translations for this lang. /!\ You will have to calluse
,reloadLang
orgetTranslation
again to be able to get translationsgetBrowserLang(): string | undefined
Returns the current browser lang if available, or undefined otherwise
TranslatePipe
You can call the TranslatePipe with some optional parameters that will be transpolated into the translation for the given key.
Parser
method
interpolate(expr: string, params?: any): string
Interpolates a string to replace parameters.This is a {{ key }}
==>This is a value
withparams = { key: "value" }
getValue(target: any, key: stirng): any
Gets a value from an object by composed keyparser.getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
I'm still using RC4, but I cannot use ng2-translate because I get errors?!
If you're still using RC4, you should fix the version of ng2-translate to 2.2.2.
'ANgularJS 2.0+' 카테고리의 다른 글
angular interval interceptor (수정중) (0) | 2016.09.06 |
---|---|
observable 관련 (수정중) (0) | 2016.09.06 |
[AngularJS 2.0] AngularJS 2.0 Tutorial 흐름 (2) | 2016.08.05 |
TypeScript (0) | 2016.08.03 |
[AngularJS 2.0] App Lifecycle (0) | 2016.08.03 |