本文整理汇总了TypeScript中ng2-translate.TranslateService类的典型用法代码示例。如果您正苦于以下问题:TypeScript TranslateService类的具体用法?TypeScript TranslateService怎么用?TypeScript TranslateService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TranslateService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(private translate: TranslateService, private cookie: CookieService, private balanceService: BalanceService) {
this.translate.setDefaultLang('en');
const language = this.cookie.get('language');
if (language) {
this.translate.use(language);
}
}
示例2: constructor
constructor(private translate: TranslateService,
public dialog: MdDialog) {
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use('en');
}
示例3: constructor
constructor(private _translate: TranslateService) {
var userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
// this language will be used as a fallback when a translation isn't found in the current language
_translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
_translate.use(userLang);
}
示例4: initMenuItems
public initMenuItems() {
this.items = [
{
label: this._translateService.instant("NAVIGATION-BAR-COMPONENT_MENU-ITEM_SHIPMENT-LIST"),
routerLink: ["/shipments"]
},
{
label: this._translateService.instant("NAVIGATION-BAR-COMPONENT_MENU-ITEM_TASK-LIST"),
routerLink: ["/tasks"]
},
{
label: this._translateService.instant("NAVIGATION-BAR-COMPONENT_MENU-ITEM_MASTER-DATA"),
items: [
{
label: this._translateService.instant("NAVIGATION-BAR-COMPONENT_MENU-ITEM_CUSTOMER-LIST"),
routerLink: ["/customers"]
},
{
label: this._translateService.instant("NAVIGATION-BAR-COMPONENT_MENU-ITEM_AIRPORTS-LIST"),
routerLink: ["/airports"]
}
]
}
];
}
示例5: newInvitation
newInvitation(organizerUid: string) {
this.sendNotification(
organizerUid,
this.translateService.instant('NOTIFICATIONS.NEW_INVITATION.TITLE'),
this.translateService.instant('NOTIFICATIONS.NEW_INVITATION.TEXT'),
{}
);
}
示例6: acceptInvitation
acceptInvitation(invitation: Invitation) {
this.sendNotification(
invitation.user_uid,
this.translateService.instant('NOTIFICATIONS.INVITATION_ACCEPTED.TITLE'),
this.translateService.instant('NOTIFICATIONS.INVITATION_ACCEPTED.TEXT'),
{}
);
}
示例7: switch
this.cleanHttpErrorListener = eventManager.subscribe('eshopApp.httpError', (response) => {
let i;
const httpResponse = response.content;
switch (httpResponse.status) {
// connection refused, server not reachable
case 0:
this.addErrorAlert('Server not reachable', 'error.server.not.reachable');
break;
case 400:
const arr = Array.from(httpResponse.headers._headers);
const headers = [];
for (i = 0; i < arr.length; i++) {
if (arr[i][0].endsWith('app-error') || arr[i][0].endsWith('app-params')) {
headers.push(arr[i][0]);
}
}
headers.sort();
let errorHeader = null;
let entityKey = null;
if (headers.length > 1) {
errorHeader = httpResponse.headers.get(headers[0]);
entityKey = httpResponse.headers.get(headers[1]);
}
if (errorHeader) {
const entityName = translateService.instant('global.menu.entities.' + entityKey);
this.addErrorAlert(errorHeader, errorHeader, { entityName });
} else if (httpResponse.text() !== '' && httpResponse.json() && httpResponse.json().fieldErrors) {
const fieldErrors = httpResponse.json().fieldErrors;
for (i = 0; i < fieldErrors.length; i++) {
const fieldError = fieldErrors[i];
// convert 'something[14].other[4].id' to 'something[].other[].id' so translations can be written to it
const convertedField = fieldError.field.replace(/\[\d*\]/g, '[]');
const fieldName = translateService.instant('eshopApp.' +
fieldError.objectName + '.' + convertedField);
this.addErrorAlert(
'Field ' + fieldName + ' cannot be empty', 'error.' + fieldError.message, { fieldName });
}
} else if (httpResponse.text() !== '' && httpResponse.json() && httpResponse.json().message) {
this.addErrorAlert(httpResponse.json().message, httpResponse.json().message, httpResponse.json().params);
} else {
this.addErrorAlert(httpResponse.text());
}
break;
case 404:
this.addErrorAlert('Not found', 'error.url.not.found');
break;
default:
if (httpResponse.text() !== '' && httpResponse.json() && httpResponse.json().message) {
this.addErrorAlert(httpResponse.json().message);
} else {
this.addErrorAlert(JSON.stringify(httpResponse)); // Fixme find a way to parse httpResponse
}
}
});
示例8: selectLang
selectLang(event: any, lang: string) {
if (event !== null)
event.preventDefault();
// this language will be used as a fallback when a translation isn't found in the current language
this.trans.setDefaultLang("en");
// the lang to use, if the lang isn't available, it will use the current loader to get them
this.trans.use(lang);
// this.refreshText();
}
示例9:
participantList.forEach((participant_uid) => {
if (participant_uid !== currentUserUid) {
this.sendNotification(
participant_uid,
this.translateService.instant('NOTIFICATIONS.NEW_COMMENT.TITLE'),
this.translateService.instant('NOTIFICATIONS.NEW_COMMENT.TEXT', {text, name}),
{}
);
}
});
示例10: configureLanguage
private configureLanguage() {
// configure language for translation service
let userLang = navigator.language.split("-")[0];
userLang = /(de|en)/gi.test(userLang) ? userLang : "en";
this._translateService.setDefaultLang("en");
this._translateService.use(userLang).subscribe(
() => {
this._translationNotifierService.publishTranslationsLoaded();
}
);
}