From 90add01ad73c626fa267ba7fa790aca848ed7186 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 15 Mar 2016 16:43:37 -0300 Subject: [PATCH] Translate texts in notification component --- src/app/components/notification/notification.component.spec.ts | 8 ++++---- src/app/components/notification/notification.component.ts | 15 ++++++++++----- src/languages/en.json | 4 +++- src/languages/pt.json | 4 +++- src/spec/mocks.ts | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/components/notification/notification.component.spec.ts b/src/app/components/notification/notification.component.spec.ts index cb5f881..22e7fd6 100644 --- a/src/app/components/notification/notification.component.spec.ts +++ b/src/app/components/notification/notification.component.spec.ts @@ -17,7 +17,7 @@ describe("Components", () => { let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); sweetAlert.swal = jasmine.createSpy("swal"); - let component: Notification = new Notification(helpers.mocks.$log, sweetAlert); + let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.$translate); component.httpError(500, {}); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ text: Notification.DEFAULT_HTTP_ERROR_MESSAGE, @@ -30,7 +30,7 @@ describe("Components", () => { let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); sweetAlert.swal = jasmine.createSpy("swal"); - let component: Notification = new Notification(helpers.mocks.$log, sweetAlert); + let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.$translate); component.httpError(500, null); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ text: Notification.DEFAULT_HTTP_ERROR_MESSAGE, @@ -43,7 +43,7 @@ describe("Components", () => { let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); sweetAlert.swal = jasmine.createSpy("swal"); - let component: Notification = new Notification(helpers.mocks.$log, sweetAlert); + let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.$translate); component.success("title", "message", 1000); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ type: "success" @@ -55,7 +55,7 @@ describe("Components", () => { let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); sweetAlert.swal = jasmine.createSpy("swal"); - let component: Notification = new Notification(helpers.mocks.$log, sweetAlert); + let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.$translate); component.success("title", "message"); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ type: "success", diff --git a/src/app/components/notification/notification.component.ts b/src/app/components/notification/notification.component.ts index bdae482..3f8a513 100644 --- a/src/app/components/notification/notification.component.ts +++ b/src/app/components/notification/notification.component.ts @@ -1,12 +1,17 @@ import {Injectable, Inject} from "ng-forward"; @Injectable() -@Inject("$log", "SweetAlert") +@Inject("$log", "SweetAlert", "$translate") export class Notification { - constructor(private $log: ng.ILogService, private SweetAlert: any) { } + constructor( + private $log: ng.ILogService, + private SweetAlert: any, + private $translate: angular.translate.ITranslateService + ) { } - public static DEFAULT_HTTP_ERROR_MESSAGE = "Something went wrong!"; + public static DEFAULT_HTTP_ERROR_TITLE = "notification.http-error.default.title"; + public static DEFAULT_HTTP_ERROR_MESSAGE = "notification.http-error.default.message"; public static DEFAULT_SUCCESS_TIMER = 1000; httpError(status: number, data: any): boolean { @@ -14,8 +19,8 @@ export class Notification { let message = (data || {}).message || Notification.DEFAULT_HTTP_ERROR_MESSAGE; this.SweetAlert.swal({ - title: "Oops...", - text: message, + title: this.$translate.instant(Notification.DEFAULT_HTTP_ERROR_TITLE), + text: this.$translate.instant(message), type: "error" }); return true; // return true to indicate that the error was already handled diff --git a/src/languages/en.json b/src/languages/en.json index ae094bb..c0761f7 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -17,5 +17,7 @@ "auth.form.login": "Login / Email address", "auth.form.password": "Password", "auth.form.login_button": "Login", - "navbar.content_viewer_actions.new_post": "New Post" + "navbar.content_viewer_actions.new_post": "New Post", + "notification.http-error.default.message": "Something went wrong!", + "notification.http-error.default.title": "Oops..." } diff --git a/src/languages/pt.json b/src/languages/pt.json index 00d2e7f..5c0c43d 100644 --- a/src/languages/pt.json +++ b/src/languages/pt.json @@ -17,5 +17,7 @@ "auth.form.login": "Login / Email", "auth.form.password": "Senha", "auth.form.login_button": "Login", - "navbar.content_viewer_actions.new_post": "Novo Artigo" + "navbar.content_viewer_actions.new_post": "Novo Artigo", + "notification.http-error.default.message": "Algo deu errado!", + "notification.http-error.default.title": "Oops..." } diff --git a/src/spec/mocks.ts b/src/spec/mocks.ts index b806695..efbbe50 100644 --- a/src/spec/mocks.ts +++ b/src/spec/mocks.ts @@ -73,7 +73,7 @@ export var mocks = { use: (lang?: string) => { return lang ? Promise.resolve(lang) : "en"; }, - instant: () => { } + instant: (text: string) => { return text } }, tmhDynamicLocale: { get: () => { }, -- libgit2 0.21.2