当前位置: 首页>>代码示例>>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;未经允许,请勿转载。