当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript TranslateService.getBrowserLang方法代码示例

本文整理汇总了TypeScript中@ngx-translate/core.TranslateService.getBrowserLang方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TranslateService.getBrowserLang方法的具体用法?TypeScript TranslateService.getBrowserLang怎么用?TypeScript TranslateService.getBrowserLang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@ngx-translate/core.TranslateService的用法示例。


在下文中一共展示了TranslateService.getBrowserLang方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  constructor(
    private iconReg: MatIconRegistry,
    private sanitizer: DomSanitizer,
    translate: TranslateService
    ) {

    translate.addLangs(['en', 'pt', 'fr', 'es']);
    translate.setDefaultLang('pt');

    const browserLang = translate.getBrowserLang();
    translate.use(browserLang.match(/en|pt|es|fr/) ? browserLang : 'pt');

    iconReg.addSvgIcon('chat', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_chat.svg'));
    iconReg.addSvgIcon('check', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_check.svg'));
    iconReg.addSvgIcon('close', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_close.svg'));
    iconReg.addSvgIcon('complete', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_complete.svg'));
    iconReg.addSvgIcon('contract', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_contract.svg'));
    iconReg.addSvgIcon('expand', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_expand.svg'));
    iconReg.addSvgIcon('grid', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_grid.svg'));
    iconReg.addSvgIcon('left-arrow', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_left_arrow.svg'));
    iconReg.addSvgIcon('message', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_message.svg'));
    iconReg.addSvgIcon('pause', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_pause.svg'));
    iconReg.addSvgIcon('play', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_play.svg'));
    iconReg.addSvgIcon('refresh', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_refresh.svg'));
    iconReg.addSvgIcon('right-arrow', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_right_arrow.svg'));
    iconReg.addSvgIcon('send', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_send.svg'));
    iconReg.addSvgIcon('share', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_share.svg'));
    iconReg.addSvgIcon('warning', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_warning.svg'));
    iconReg.addSvgIcon('satisfied', sanitizer.bypassSecurityTrustResourceUrl('./assets/icons/ic_satisfied.svg'));
  }
开发者ID:dev-maple,项目名称:flipping-book-angular,代码行数:30,代码来源:app.component.ts

示例2: constructor

    /**
     * Master-component of all apps.
     *
     * Inits the translation service, the operator, the login data and the constants.
     *
     * Handles the altering of Array.toString()
     *
     * @param translate To set the default language
     * @param operator To call the constructor of the OperatorService
     * @param loginDataService to call the constructor of the LoginDataService
     * @param constantService to call the constructor of the ConstantService
     * @param servertimeService executes the scheduler early on
     * @param themeService used to listen to theme-changes
     * @param countUsersService to call the constructor of the CountUserService
     * @param configService to call the constructor of the ConfigService
     * @param loadFontService to call the constructor of the LoadFontService
     */
    public constructor(
        translate: TranslateService,
        appRef: ApplicationRef,
        servertimeService: ServertimeService,
        operator: OperatorService,
        loginDataService: LoginDataService,
        constantsService: ConstantsService, // Needs to be started, so it can register itself to the WebsocketService
        themeService: ThemeService,
        countUsersService: CountUsersService, // Needed to register itself.
        configService: ConfigService,
        loadFontService: LoadFontService
    ) {
        // manually add the supported languages
        translate.addLangs(['en', 'de', 'cs']);
        // this language will be used as a fallback when a translation isn't found in the current language
        translate.setDefaultLang('en');
        // get the browsers default language
        const browserLang = translate.getBrowserLang();
        // try to use the browser language if it is available. If not, uses english.
        translate.use(translate.getLangs().includes(browserLang) ? browserLang : 'en');
        // change default JS functions
        this.overloadArrayToString();

        appRef.isStable
            .pipe(
                filter(s => s),
                take(1)
            )
            .subscribe(() => servertimeService.startScheduler());
    }
开发者ID:emanuelschuetze,项目名称:OpenSlides,代码行数:47,代码来源:app.component.ts

示例3: constructor

 constructor(private httpClient: HttpClient, public translate: TranslateService) {
   
   translate.addLangs(['en', 'pl']);
   translate.setDefaultLang('pl');
   
   const browserLang = translate.getBrowserLang();
   translate.use(browserLang.match(/en|pl/) ? browserLang : 'pl');
 }
开发者ID:gacikjakub,项目名称:BattleShips,代码行数:8,代码来源:app.component.ts

示例4: constructor

 constructor(
     private translate: TranslateService,
     public router: Router
     ) {
         this.translate.addLangs(['en', 'fr', 'ur', 'es', 'it', 'fa', 'de', 'zh-CHS']);
         this.translate.setDefaultLang('en');
         const browserLang = this.translate.getBrowserLang();
         this.translate.use(browserLang.match(/en|fr|ur|es|it|fa|de|zh-CHS/) ? browserLang : 'en');
 }
开发者ID:kondanarayana,项目名称:customview,代码行数:9,代码来源:login.component.ts

示例5: constructor

  constructor(private translation: TranslateService) {
    this.year = CONSTANTS.years[0];

    translation.addLangs(['en', 'nl', 'pt', 'ru']);
    translation.setDefaultLang('en');

    let browserLang = translation.getBrowserLang();
    translation.use(browserLang.match(/en|nl|pt|ru/) ? browserLang : 'en');
    this.translate = translation;
  }
开发者ID:stevermeister,项目名称:dutch-tax-income-calculator2,代码行数:10,代码来源:app.component.ts

示例6: getSelectedLanguage

export function getSelectedLanguage(translateService: TranslateService): string {
  let storedLanguage: string = sessionStorage.getItem(TRANSLATE_STORAGE_KEY);
  // Check if the lenguage has been stored else if the language wasnt stored, then use browser default if supported
  if (storedLanguage && translateService.getLangs().indexOf(storedLanguage) > -1) {
    return storedLanguage;
  } else if (translateService.getLangs().indexOf(translateService.getBrowserLang()) > -1) {
    return translateService.getBrowserLang();
  }
  // If everything fails, then use default lang
  return translateService.getDefaultLang();
}
开发者ID:Teradata,项目名称:covalent,代码行数:11,代码来源:translate.ts

示例7: resolve

 locationInitialized.then(() => {
     const defaultLanguage = config.getLanguage('default');
     const browserLanguage = translate.getBrowserLang()
     translate.setDefaultLang(defaultLanguage);
     translate.use(browserLanguage || defaultLanguage).subscribe(() => {
         console.info(`Successfully initialized '${browserLanguage || defaultLanguage}' language.'`);
     }, () => {
         console.error(`Problem with '${browserLanguage || defaultLanguage}' language initialization.'`);
     }, () => {
         resolve(null);
     });
 });
开发者ID:pinkasey,项目名称:activegan,代码行数:12,代码来源:index.ts

示例8: getOrSetCurrentLanguage

 /**
  * Get the current language or set it
  */
 getOrSetCurrentLanguage() {
   let language = localStorage.getItem('userLanguage');
   // If there is already a language choosen
   if (language && language.length > 0) {
     this._translateService.use(language);
   } else { // Set default language
     const browserLang = this._translateService.getBrowserLang();
     language = browserLang.match(/en|cs|it|nl|fr|pl|de|es|fi|pt|ro|el|hu|nn|dk/) ? browserLang : 'fr';
     this._translateService.use(language);
   }
   this.selectedLanguage = language;
 }
开发者ID:Rachoor,项目名称:pia,代码行数:15,代码来源:languages.service.ts

示例9: defaultLanguage

    private defaultLanguage() {
        const isValid = (language: string) => LANGUAGES.indexOf(language) > -1;

        const persistedLanguage = this.cookieService.get(LANGUAGE_KEY);
        if (isValid(persistedLanguage)) {
            return persistedLanguage;
        }
        const browserLanguage = this.translateService.getBrowserLang();
        if (isValid(browserLanguage)) {
            return browserLanguage;
        }

        return LANGUAGES[0];
    }
开发者ID:alv-ch,项目名称:job-room,代码行数:14,代码来源:jobroom2-language.service.ts

示例10: constructor

    /**
     * Master-component of all apps.
     *
     * Inits the translation service, the operator, the login data and the constants.
     *
     * Handles the altering of Array.toString()
     *
     * @param translate To set the default language
     * @param operator To call the constructor of the OperatorService
     * @param loginDataService to call the constructor of the LoginDataService
     * @param constantService to call the constructor of the ConstantService
     * @param servertimeService executes the scheduler early on
     * @param themeService used to listen to theme-changes
     * @param countUsersService to call the constructor of the CountUserService
     * @param configService to call the constructor of the ConfigService
     * @param loadFontService to call the constructor of the LoadFontService
     * @param dataStoreUpgradeService
     * @param update Service Worker Updates
     */
    public constructor(
        translate: TranslateService,
        appRef: ApplicationRef,
        servertimeService: ServertimeService,
        router: Router,
        operator: OperatorService,
        loginDataService: LoginDataService,
        constantsService: ConstantsService, // Needs to be started, so it can register itself to the WebsocketService
        themeService: ThemeService,
        spinnerService: SpinnerService,
        countUsersService: CountUsersService, // Needed to register itself.
        configService: ConfigService,
        loadFontService: LoadFontService,
        dataStoreUpgradeService: DataStoreUpgradeService, // to start it.
        update: UpdateService,
        prioritizeService: PrioritizeService,
        pingService: PingService
    ) {
        // manually add the supported languages
        translate.addLangs(['en', 'de', 'cs']);
        // this language will be used as a fallback when a translation isn't found in the current language
        translate.setDefaultLang('en');
        // get the browsers default language
        const browserLang = translate.getBrowserLang();
        // try to use the browser language if it is available. If not, uses english.
        translate.use(translate.getLangs().includes(browserLang) ? browserLang : 'en');
        // change default JS functions
        this.overloadArrayToString();
        // Show the spinner initial
        spinnerService.setVisibility(true, translate.instant('Loading data. Please wait...'));

        appRef.isStable
            .pipe(
                // take only the stable state
                filter(s => s),
                take(1)
            )
            .subscribe(() => servertimeService.startScheduler());

        // Subscribe to hide the spinner if the application has changed.
        appRef.isStable
            .pipe(
                filter(s => s),
                auditTime(1000)
            )
            .pipe(take(2))
            .subscribe(() => {
                spinnerService.setVisibility(false);
            });
    }
开发者ID:CatoTH,项目名称:OpenSlides,代码行数:69,代码来源:app.component.ts


注:本文中的@ngx-translate/core.TranslateService.getBrowserLang方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。