本文整理匯總了TypeScript中@ngx-translate/core.TranslateService.getBrowserCultureLang方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TranslateService.getBrowserCultureLang方法的具體用法?TypeScript TranslateService.getBrowserCultureLang怎麽用?TypeScript TranslateService.getBrowserCultureLang使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ngx-translate/core.TranslateService
的用法示例。
在下文中一共展示了TranslateService.getBrowserCultureLang方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: language
/**
* Sets the current language.
* Note: The current language is saved to the local storage.
* If no parameter is specified, the language is loaded from local storage (if present).
* @param language The IETF language code to set.
*/
set language(language: string) {
language =
language ||
localStorage.getItem(languageKey) ||
this.translateService.getBrowserCultureLang();
let isSupportedLanguage = includes(this.supportedLanguages, language);
// If no exact match is found, search without the region
if (language && !isSupportedLanguage) {
language = language.split('-')[0];
language =
this.supportedLanguages.find(supportedLanguage =>
supportedLanguage.startsWith(language)
) || '';
isSupportedLanguage = Boolean(language);
}
// Fallback if language is not supported
if (!isSupportedLanguage) {
language = this.defaultLanguage;
}
log.debug(`Language set to ${language}`);
this.translateService.use(language);
}
示例2: init
public init(config: i18nConfig = {}): void {
let selectedLang: string = config.defaultLang ? config.defaultLang : DEFAULT_LANG;
let supportedLangs: string[] = config.supportedLangs ? config.supportedLangs : DEFAULT_SUPPORTING_LANGS;
this.translateService.addLangs(supportedLangs);
this.translateService.setDefaultLang(selectedLang);
if (config.enablei18Support) {
//If user has selected lang, then directly use it
let langSetting: string = this.cookie.get(config.langCookieKey ? config.langCookieKey : DEFAULT_LANG_COOKIE_KEY);
if (!langSetting || langSetting.trim() === "") {
//Use browser lang
langSetting = this.translateService.getBrowserCultureLang().toLowerCase();
}
if (langSetting && langSetting.trim() !== "") {
if (supportedLangs && supportedLangs.length > 0) {
if (supportedLangs.find(lang => lang === langSetting)) {
selectedLang = langSetting;
}
}
}
}
this.translateService.use(selectedLang);
}
示例3: constructor
constructor(
private translate: TranslateService,
private cookie: CookieService,
private session: SessionService,
private appConfigService: AppConfigService,
private titleService: Title) {
translate.addLangs(supportedLangs);
translate.setDefaultLang(enLang);
//If user has selected lang, then directly use it
let langSetting = this.cookie.get("harbor-lang");
if (!langSetting || langSetting.trim() === "") {
//Use browser lang
langSetting = translate.getBrowserCultureLang().toLowerCase();
}
let selectedLang = this.isLangMatch(langSetting, supportedLangs) ? langSetting : enLang;
translate.use(selectedLang);
//Override page title
let key: string = "APP_TITLE.HARBOR";
if (this.appConfigService.isIntegrationMode()) {
key = "APP_TITLE.REG";
}
translate.get(key).subscribe((res: string) => {
this.titleService.setTitle(res);
});
}