本文整理汇总了TypeScript中@ngx-translate/core.TranslateService.use方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TranslateService.use方法的具体用法?TypeScript TranslateService.use怎么用?TypeScript TranslateService.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngx-translate/core.TranslateService
的用法示例。
在下文中一共展示了TranslateService.use方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
this.storage.get("appLanguage").then((value) => {
if (value != null) {
this.translate.use(value);
} else {
this.translate.use("de");
this.storage.set("appLanguage","de");
}
});
示例2: 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;
}
示例3: 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);
}
示例4: ngOnInit
public ngOnInit() {
this.translate.use('en');
this.idle.setIdle(600);
this.idle.setTimeout(300);
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
this.keepalive.interval(180);
this.keepalive.request('/rest/keepalive');
this.keepalive.onPingResponse.subscribe((response: Response) => {
if (response.status === 401) {
window.location.href = '/rest/logout';
}
});
this.idle.watch();
this.idle.onTimeout.subscribe(() => {
console.log('Timed out');
window.location.href = '/rest/logout';
});
this.races = this.racesService.getRaces();
this.wsSubscription = this.ws.subscribeForMessages()
.subscribe((message: ConverstationMessage) => {
this.message = message;
});
this.connectedSubscription = this.ws.getConnectedPositions()
.subscribe((connected: Connected[]) => {
this.connected = connected;
});
}
示例5: 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);
}
示例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();
}
示例7: 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);
}
示例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);
});
}
示例9: it
it('should be able to reset a lang', (done: Function) => {
translate.use('en');
spyOn(http, 'expectOne').and.callThrough();
// this will request the translation from the backend because we use a static files loader for TranslateService
translate.get('TEST').subscribe((res: string) => {
expect(res).toEqual('This is a test');
expect(http.expectOne).toHaveBeenCalledTimes(1);
// reset the lang as if it was never initiated
translate.resetLang('en');
expect(translate.instant('TEST')).toEqual('TEST');
// use set timeout because no request is really made and we need to trigger zone to resolve the observable
setTimeout(() => {
translate.get('TEST').subscribe((res2: string) => {
expect(res2).toEqual('TEST'); // because the loader is "pristine" as if it was never called
expect(http.expectOne).toHaveBeenCalledTimes(1);
done();
});
}, 10);
});
// mock response after the xhr request, otherwise it will be undefined
http.expectOne('/assets/i18n/en.json').flush({"TEST": "This is a test"});
});
示例10: 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'));
}