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


TypeScript TranslateService.setDefaultLang方法代碼示例

本文整理匯總了TypeScript中@ngx-translate/core.TranslateService.setDefaultLang方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TranslateService.setDefaultLang方法的具體用法?TypeScript TranslateService.setDefaultLang怎麽用?TypeScript TranslateService.setDefaultLang使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ngx-translate/core.TranslateService的用法示例。


在下文中一共展示了TranslateService.setDefaultLang方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 http.get('manifest.webapp').subscribe((data: any) => {
   translate.setDefaultLang('en');
   if (data.hasOwnProperty('language')) {
     translate.setDefaultLang(data.language);
   }else {
     translate.setDefaultLang('en');
   }
 });
開發者ID:hisptz,項目名稱:scorecard,代碼行數:8,代碼來源:app.component.ts

示例2: constructor

  constructor(translate: TranslateService) {
    let userLang = navigator.language.split('-')[0]; // use navigator lang if available
    translate.setDefaultLang('en');

    translate.setTranslation('fr', {
      JS: 'Javascript',
      DEV: 'DĂŠveloppement',
      DATA: 'DonnĂŠes',
      INTE: 'Integration',
      HOME:'Accueil',
      PROJECTS:'Projets',
      TECHS:'Technologies',
      TOOLS:'Outils'
    });
    translate.setTranslation('en', {
      JS: 'Javascript',
      DEV: 'Development',
      DATA: 'Data',
      INTE: 'Integration',
      HOME:'Home',
      PROJECTS:'Projects',
      TECHS:'Technologies',
      TOOLS:'Tools'
    });

    // the lang to use, if the lang isn't available, it will use the current loader to get them
    translate.use(userLang);
  }
開發者ID:Nighthawk14,項目名稱:portfolio,代碼行數:28,代碼來源:app.module.ts

示例3: 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

示例4: 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

示例5: 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

示例6: constructor

  constructor(private translateService: TranslateService,
              private title: Title,
              private meta: Meta,
              private snackBar: MatSnackBar,
              private router: Router) {

    this.translateService = translateService;
    this.translateService.setDefaultLang('en');
    this.translateService.use('en');

    this.title.setTitle('Angular Example App');
    this.router.events.subscribe((event: any) => {
      if (event instanceof NavigationEnd) {
        switch (event.urlAfterRedirects) {
          case '/':
            this.meta.updateTag({
              name: 'description',
              content: 'Angular Example app with Angular CLI, Angular Material and more'
            });
            break;
          case '/' + AppConfig.routes.heroes:
            this.title.setTitle('Heroes list');
            this.meta.updateTag({
              name: 'description',
              content: 'List of super-heroes'
            });
            break;
        }
      }
    });

    this.checkBrowserFeatures();
  }
開發者ID:Xopoc,項目名稱:angular5-example-app,代碼行數:33,代碼來源:app.component.ts

示例7:

    this.platform.ready().then(async () => {
      let defaultLanguage;

      if (this.platform.is('ios') || this.platform.is('android')) {
        defaultLanguage = (await this.globalization.getPreferredLanguage()).value.slice(0, 2);
        this.statusBar.styleLightContent();
        this.splashScreen.hide();
      } else {
        defaultLanguage = navigator.language.slice(0, 2);
      }

      // we assume that availableLanguage[0] is default language if user language is not available
      if (environment.availableLanguage && environment.availableLanguage.length > 0) {
        if (environment.availableLanguage.indexOf(defaultLanguage) === -1) {
          defaultLanguage = environment.availableLanguage[0];
        }
      } else {
        // or 'fr' if array is empty
        defaultLanguage = 'fr';
      }

      this.translate.setDefaultLang(defaultLanguage);

      this.settings.loadSettings();
      this.onlineTreks.loadTreks();
    });
開發者ID:makinacorpus,項目名稱:Geotrek-mobile,代碼行數:26,代碼來源:app.component.ts

示例8: 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

示例9: constructor

  constructor(translate: TranslateService) {
    // this.language = translate.getBrowserLang();
    this.language = Platform.device.language.split("-")[0];
    // translate.addLangs(["en", "fr"]);
    translate.setDefaultLang("en"); // fallback

    translate.use(this.language.match(/en|es|fr|ru/) ? this.language : "en");
  }
開發者ID:xmlking,項目名稱:WearableHub,代碼行數:8,代碼來源:app.component.ts

示例10: 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


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