當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript TranslateService.getBrowserCultureLang方法代碼示例

本文整理匯總了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);
  }
開發者ID:epot,項目名稱:Gifter,代碼行數:31,代碼來源:i18n.service.ts

示例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);
    }
開發者ID:LilyFaFa,項目名稱:harbor,代碼行數:26,代碼來源:translate-init.service.ts

示例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);
        });
    }
開發者ID:wknet123,項目名稱:harbor,代碼行數:30,代碼來源:app.component.ts


注:本文中的@ngx-translate/core.TranslateService.getBrowserCultureLang方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。