ANgularJS 2.0+

ng2-translate 2.2.2

k9e4h 2016. 8. 25. 09:20


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. A 
    TranslationChangeEvent is an object with the properties lang: string & translations: any (an object containing your translations).


method


  • setDefaultLang(lang: string)
            Sets the default language to use as a fallback
  • use(lang: string): Observable<any>
            Changes the lang currently used
  • getTranslation(lang: string): Observable<any>
            Gets an object of translations for a given language with the current loader
  • setTranslation(lang: string, translations: Object, shouldMerge: boolean = false)
            Manually sets an object of translations for a given language, set shouldMerge to true if you want to append the translations instead of replacing them
  • addLangs(langs: Array<string>)
            Add new langs to the list
  • getLangs()
            현재 사용 가능한 언어 배열 반환
  • 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 the get method instead.
  • set(key: string, value: string, lang?: string)
            Sets the translated value of a key
  • reloadLang(lang: string): Observable<string|Object>
            Calls resetLang and retrieves the translations object for the current loader
  • resetLang(lang: string)
            Removes the current translations for this lang. /!\ You will have to call usereloadLang orgetTranslation again to be able to get translations
  • getBrowserLang(): 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 with params = { key: "value" }

  • getValue(target: any, key: stirng): any
            Gets a value from an object by composed key parser.getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'


If you're still using RC4, you should fix the version of ng2-translate to 2.2.2.



API 문서


반응형

'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