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


TypeScript TranslateService.addLangs方法代码示例

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


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

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

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

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

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

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

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

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

示例9: constructor

    constructor(viewContainerRef: ViewContainerRef,
                private renderer: Renderer,
                private router: Router,
                private translate : TranslateService) {
        this.viewContainerRef = viewContainerRef;
        translate.addLangs(["ru", "cz", "en"]);
        translate.setTranslation("ru", RU);
        translate.setTranslation("en", EN);
        translate.setTranslation("cz", CZ);
        translate.setDefaultLang('ru');

        let browserLang = translate.getBrowserLang();
        translate.use(browserLang.match(/ru/) ? browserLang : 'ru');
    }
开发者ID:pozitivity,项目名称:demo,代码行数:14,代码来源:app.component.ts

示例10: constructor

    constructor(
        translate: TranslateService,
        sam: SamService,
        myChartService: ChartService,
    ) {
        translate.addLangs(['en', 'fr', 'ur']);
        translate.setDefaultLang('en');
        const browserLang = translate.getBrowserLang();
        translate.use(browserLang.match(/en|fr|ur/) ? browserLang : 'en');

        sam.init([
            { type: 'actions', serviceName: 'Chart', service: myChartService, init: false },
        ]);
    }
开发者ID:jdubray,项目名称:sam-samples,代码行数:14,代码来源:app.component.ts


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