本文整理汇总了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'));
}
示例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());
}
示例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');
}
示例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');
}
示例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;
}
示例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();
}
示例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);
});
});
示例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;
}
示例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];
}
示例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);
});
}