當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。