use instant translation (#382)

* use instant translation

* update code and tests

* fix tests
This commit is contained in:
Denys Vuika 2018-06-03 11:49:29 +01:00 committed by GitHub
parent 20ad62d035
commit aca73e2ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 92 deletions

View File

@ -108,11 +108,10 @@ export class NodeCopyDirective {
const undo = (numberOfCopiedItems > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : '';
const withUndo = (numberOfCopiedItems > 0) ? '_WITH_UNDO' : '';
this.translation.get(i18nMessageString, { success: numberOfCopiedItems, failed: failedItems }).subscribe(message => {
this.notification.openSnackMessageAction(message, undo, NodeActionsService[`SNACK_MESSAGE_DURATION${withUndo}`])
.onAction()
.subscribe(() => this.deleteCopy(newItems));
});
const message = this.translation.instant(i18nMessageString, { success: numberOfCopiedItems, failed: failedItems });
this.notification.openSnackMessageAction(message, undo, NodeActionsService[`SNACK_MESSAGE_DURATION${withUndo}`])
.onAction()
.subscribe(() => this.deleteCopy(newItems));
}
private deleteCopy(nodes: MinimalNodeEntity[]) {
@ -138,9 +137,8 @@ export class NodeCopyDirective {
i18nMessageString = 'APP.MESSAGES.ERRORS.PERMISSION';
}
this.translation.get(i18nMessageString).subscribe(message => {
this.notification.openSnackMessageAction(message, '', NodeActionsService.SNACK_MESSAGE_DURATION);
});
const message = this.translation.instant(i18nMessageString);
this.notification.openSnackMessageAction(message, '', NodeActionsService.SNACK_MESSAGE_DURATION);
}
);
}

View File

@ -65,24 +65,21 @@ export class NodeDeleteDirective {
.subscribe(
(data) => {
const processedData = this.processStatus(data);
const message = this.getDeleteMessage(processedData);
const withUndo = processedData.someSucceeded ? this.translation.instant('APP.ACTIONS.UNDO') : '';
this.getDeleteMessage(processedData)
.subscribe((message) => {
const withUndo = processedData.someSucceeded ? this.translation.translate.instant('APP.ACTIONS.UNDO') : '';
this.notification.openSnackMessageAction(message, withUndo, NodeDeleteDirective.DELETE_MESSAGE_DURATION)
.onAction()
.subscribe(() => this.restore(processedData.success));
this.notification.openSnackMessageAction(message, withUndo, NodeDeleteDirective.DELETE_MESSAGE_DURATION)
.onAction()
.subscribe(() => this.restore(processedData.success));
if (processedData.someSucceeded) {
this.content.nodeDeleted.next(null);
}
});
if (processedData.someSucceeded) {
this.content.nodeDeleted.next(null);
}
}
);
}
private restore(items): void {
private restore(items: any[]): void {
const batch = [];
items.forEach((item) => {
@ -95,12 +92,10 @@ export class NodeDeleteDirective {
const processedData = this.processStatus(data);
if (processedData.failed.length) {
this.getRestoreMessage(processedData)
.subscribe((message) => {
this.notification.openSnackMessageAction(
message, '' , NodeDeleteDirective.RESTORE_MESSAGE_DURATION
);
});
const message = this.getRestoreMessage(processedData);
this.notification.openSnackMessageAction(
message, '' , NodeDeleteDirective.RESTORE_MESSAGE_DURATION
);
}
if (processedData.someSucceeded) {
@ -178,39 +173,39 @@ export class NodeDeleteDirective {
);
}
private getRestoreMessage(status): Observable<string> {
private getRestoreMessage(status): string {
if (status.someFailed && !status.oneFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.NODE_RESTORE_PLURAL',
{ number: status.failed.length }
);
}
if (status.oneFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.NODE_RESTORE',
{ name: status.failed[0].name }
);
}
}
private getDeleteMessage(status): Observable<string> {
private getDeleteMessage(status): string {
if (status.allFailed && !status.oneFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.NODE_DELETION_PLURAL',
{ number: status.failed.length }
);
}
if (status.allSucceeded && !status.oneSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.NODE_DELETION.PLURAL',
{ number: status.success.length }
);
}
if (status.someFailed && status.someSucceeded && !status.oneSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.NODE_DELETION.PARTIAL_PLURAL',
{
success: status.success.length,
@ -220,7 +215,7 @@ export class NodeDeleteDirective {
}
if (status.someFailed && status.oneSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.NODE_DELETION.PARTIAL_SINGULAR',
{
success: status.success.length,
@ -230,14 +225,14 @@ export class NodeDeleteDirective {
}
if (status.oneFailed && !status.someSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.NODE_DELETION',
{ name: status.failed[0].name }
);
}
if (status.oneSucceeded && !status.someFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.NODE_DELETION.SINGULAR',
{ name: status.success[0].name }
);

View File

@ -128,20 +128,21 @@ export class NodeMoveDirective {
const initialParentId = this.nodeActionsService.getEntryParentId(this.selection[0].entry);
this.translation.get(
const messages = this.translation.instant(
[successMessage, partialSuccessMessage, failedMessage],
{ success: succeeded, failed: failures, partially: partiallySucceeded}).subscribe(messages => {
{ success: succeeded, failed: failures, partially: partiallySucceeded}
);
this.notification.openSnackMessageAction(
messages[successMessage]
+ beforePartialSuccessMessage + messages[partialSuccessMessage]
+ beforeFailedMessage + messages[failedMessage],
undo,
NodeActionsService[`SNACK_MESSAGE_DURATION${withUndo}`]
)
.onAction()
.subscribe(() => this.revertMoving(moveResponse, initialParentId));
});
// TODO: review in terms of i18n
this.notification.openSnackMessageAction(
messages[successMessage]
+ beforePartialSuccessMessage + messages[partialSuccessMessage]
+ beforeFailedMessage + messages[failedMessage],
undo,
NodeActionsService[`SNACK_MESSAGE_DURATION${withUndo}`]
)
.onAction()
.subscribe(() => this.revertMoving(moveResponse, initialParentId));
}
getErrorMessage(errorObject): string {
@ -207,10 +208,8 @@ export class NodeMoveDirective {
i18nMessageString = 'APP.MESSAGES.ERRORS.PERMISSION';
}
this.translation.get(i18nMessageString).subscribe(message => {
this.notification.openSnackMessage(
message, NodeActionsService.SNACK_MESSAGE_DURATION);
});
const message = this.translation.instant(i18nMessageString);
this.notification.openSnackMessage(message, NodeActionsService.SNACK_MESSAGE_DURATION);
}
);
}

View File

@ -78,7 +78,7 @@ describe('NodePermanentDeleteDirective', () => {
beforeEach(() => {
nodesService = alfrescoService.getInstance().nodes;
spyOn(translation, 'get').and.returnValue(Observable.of('message'));
spyOn(translation, 'instant').and.returnValue(Observable.of('message'));
spyOn(notificationService, 'openSnackMessage').and.returnValue({});
spyOn(dialog, 'open').and.returnValue({
@ -138,7 +138,7 @@ describe('NodePermanentDeleteDirective', () => {
tick();
expect(notificationService.openSnackMessage).toHaveBeenCalled();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR',
{ name: 'name1', failed: 2 }
);
@ -175,7 +175,7 @@ describe('NodePermanentDeleteDirective', () => {
tick();
expect(notificationService.openSnackMessage).toHaveBeenCalled();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL',
{ number: 2, failed: 2 }
);
@ -193,7 +193,7 @@ describe('NodePermanentDeleteDirective', () => {
tick();
expect(notificationService.openSnackMessage).toHaveBeenCalled();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR',
{ name: 'name1' }
);
@ -211,7 +211,7 @@ describe('NodePermanentDeleteDirective', () => {
tick();
expect(notificationService.openSnackMessage).toHaveBeenCalled();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR',
{ name: 'name1' }
);
@ -238,7 +238,7 @@ describe('NodePermanentDeleteDirective', () => {
tick();
expect(notificationService.openSnackMessage).toHaveBeenCalled();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL',
{ number: 2 }
);
@ -265,7 +265,7 @@ describe('NodePermanentDeleteDirective', () => {
tick();
expect(notificationService.openSnackMessage).toHaveBeenCalled();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL',
{ number: 2 }
);

View File

@ -116,15 +116,13 @@ export class NodePermanentDeleteDirective {
}
private purgeNotification(status): void {
this.getPurgeMessage(status)
.subscribe((message) => {
this.notification.openSnackMessage(message, 3000);
});
const message = this.getPurgeMessage(status);
this.notification.openSnackMessage(message, 3000);
}
private getPurgeMessage(status): Observable<string|any> {
private getPurgeMessage(status): string {
if (status.oneSucceeded && status.someFailed && !status.oneFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR',
{
name: status.success[0].name,
@ -134,7 +132,7 @@ export class NodePermanentDeleteDirective {
}
if (status.someSucceeded && !status.oneSucceeded && status.someFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL',
{
number: status.success.length,
@ -144,28 +142,28 @@ export class NodePermanentDeleteDirective {
}
if (status.oneSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR',
{ name: status.success[0].name }
);
}
if (status.oneFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR',
{ name: status.fail[0].name }
);
}
if (status.allSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL',
{ number: status.success.length }
);
}
if (status.allFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL',
{ number: status.fail.length }
);

View File

@ -84,7 +84,7 @@ describe('NodeRestoreDirective', () => {
nodesService = alfrescoService.getInstance().nodes;
coreApi = alfrescoService.getInstance().core;
spyOn(translation, 'get').and.returnValue(Observable.of('message'));
spyOn(translation, 'instant').and.returnValue(Observable.of('message'));
});
it('does not restore nodes if no selection', () => {
@ -209,7 +209,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.PARTIAL_PLURAL',
{ number: 2 }
);
@ -229,7 +229,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.NODE_EXISTS',
{ name: 'name1' }
);
@ -249,7 +249,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.GENERIC',
{ name: 'name1' }
);
@ -269,7 +269,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.LOCATION_MISSING',
{ name: 'name1' }
);
@ -296,7 +296,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.INFO.TRASH.NODES_RESTORE.PLURAL'
);
}));
@ -313,7 +313,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
expect(translation.get).toHaveBeenCalledWith(
expect(translation.instant).toHaveBeenCalledWith(
'APP.MESSAGES.INFO.TRASH.NODES_RESTORE.SINGULAR',
{ name: 'name1' }
);

View File

@ -190,11 +190,11 @@ export class NodeRestoreDirective {
);
}
private getRestoreMessage(): Observable<string|any> {
private getRestoreMessage(): string {
const { restoreProcessStatus: status } = this;
if (status.someFailed && !status.oneFailed) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.PARTIAL_PLURAL',
{
number: status.fail.length
@ -204,14 +204,14 @@ export class NodeRestoreDirective {
if (status.oneFailed && status.fail[0].statusCode) {
if (status.fail[0].statusCode === 409) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.NODE_EXISTS',
{
name: status.fail[0].entry.name
}
);
} else {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.GENERIC',
{
name: status.fail[0].entry.name
@ -221,7 +221,7 @@ export class NodeRestoreDirective {
}
if (status.oneFailed && !status.fail[0].statusCode) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.ERRORS.TRASH.NODES_RESTORE.LOCATION_MISSING',
{
name: status.fail[0].entry.name
@ -230,11 +230,11 @@ export class NodeRestoreDirective {
}
if (status.allSucceeded && !status.oneSucceeded) {
return this.translation.get('APP.MESSAGES.INFO.TRASH.NODES_RESTORE.PLURAL');
return this.translation.instant('APP.MESSAGES.INFO.TRASH.NODES_RESTORE.PLURAL');
}
if (status.allSucceeded && status.oneSucceeded) {
return this.translation.get(
return this.translation.instant(
'APP.MESSAGES.INFO.TRASH.NODES_RESTORE.SINGULAR',
{
name: status.success[0].entry.name
@ -246,13 +246,11 @@ export class NodeRestoreDirective {
private restoreNotification(): void {
const status = Object.assign({}, this.restoreProcessStatus);
const action = (status.oneSucceeded && !status.someFailed) ? this.translation.translate.instant('APP.ACTIONS.VIEW') : '';
const message = this.getRestoreMessage();
this.getRestoreMessage()
.subscribe((message) => {
this.notification.openSnackMessageAction(message, action, 3000)
.onAction()
.subscribe(() => this.navigateLocation(status.success[0].entry.path));
});
this.notification.openSnackMessageAction(message, action, 3000)
.onAction()
.subscribe(() => this.navigateLocation(status.success[0].entry.path));
}
private refresh(): void {

View File

@ -71,8 +71,8 @@ export class NodeVersionsDirective {
VersionManagerDialogAdapterComponent,
<any>{ data: { contentEntry }, panelClass: 'adf-version-manager-dialog', width: '630px' });
} else {
const translatedErrorMessage: any = this.translation.get('APP.MESSAGES.ERRORS.PERMISSION');
this.notification.openSnackMessage(translatedErrorMessage.value, 4000);
const translatedErrorMessage = this.translation.instant('APP.MESSAGES.ERRORS.PERMISSION');
this.notification.openSnackMessage(translatedErrorMessage, 4000);
this.nodeVersionError.emit();
}