本文整理匯總了TypeScript中ng2-translate.TranslateService.getBrowserLang方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TranslateService.getBrowserLang方法的具體用法?TypeScript TranslateService.getBrowserLang怎麽用?TypeScript TranslateService.getBrowserLang使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ng2-translate.TranslateService
的用法示例。
在下文中一共展示了TranslateService.getBrowserLang方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ngOnInit
ngOnInit() {
this.globalClickCallbackFn = this.renderer.listen(this.elementRef.nativeElement, 'click', (event: any) => {
console.log("全局監聽點擊事件>" + event);
});
this.translate.addLangs(["zh", "en"]);
this.translate.setDefaultLang('zh');
const browserLang = this.translate.getBrowserLang();
console.log("檢測到的瀏覽器語言>" + browserLang);
this.translate.use(browserLang.match(/zh|en/) ? browserLang : 'zh');
}
示例2: init
public init(refreshView: () => void): void {
console.debug("-- Registered Languages are: " + languages.join(", "));
this.translate.setDefaultLang(defaultLanguage);
this.translate.addLangs(additionalLanguages);
let initLang = this.translate.getBrowserLang();
if (languages.indexOf(initLang) === -1) {
initLang = defaultLanguage;
}
this.translate.use(initLang);
moment.locale(initLang);
console.debug("-- Using Language " + this.translate.currentLang);
this.refreshView = refreshView;
}
示例3: constructor
constructor(
private cache: CacheService,
private api: ApiService,
public loadingCtrl: LoadingController,
private translate: TranslateService
) {
this.enLgnTxt = {
"loader_config": "Configuration"
}
this.frLgnTxt = {
"loader_config": "Configuration"
}
this.lgnDetected = translate.getBrowserLang();
this.lgnDetected == "en" ? this.lgnUsed = this.enLgnTxt : this.lgnUsed = this.frLgnTxt;
this.lgnDetected != "en" && this.lgnDetected != "fr" ? this.lgnUsed = this.enLgnTxt : null;
}