Commit 90add01ad73c626fa267ba7fa790aca848ed7186
1 parent
65c1878f
Exists in
master
and in
1 other branch
Translate texts in notification component
Showing
5 changed files
with
21 additions
and
12 deletions
Show diff stats
src/app/components/notification/notification.component.spec.ts
@@ -17,7 +17,7 @@ describe("Components", () => { | @@ -17,7 +17,7 @@ describe("Components", () => { | ||
17 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); | 17 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); |
18 | sweetAlert.swal = jasmine.createSpy("swal"); | 18 | sweetAlert.swal = jasmine.createSpy("swal"); |
19 | 19 | ||
20 | - let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert); | 20 | + let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.$translate); |
21 | component.httpError(500, {}); | 21 | component.httpError(500, {}); |
22 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ | 22 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ |
23 | text: Notification.DEFAULT_HTTP_ERROR_MESSAGE, | 23 | text: Notification.DEFAULT_HTTP_ERROR_MESSAGE, |
@@ -30,7 +30,7 @@ describe("Components", () => { | @@ -30,7 +30,7 @@ describe("Components", () => { | ||
30 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); | 30 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); |
31 | sweetAlert.swal = jasmine.createSpy("swal"); | 31 | sweetAlert.swal = jasmine.createSpy("swal"); |
32 | 32 | ||
33 | - let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert); | 33 | + let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.$translate); |
34 | component.httpError(500, null); | 34 | component.httpError(500, null); |
35 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ | 35 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ |
36 | text: Notification.DEFAULT_HTTP_ERROR_MESSAGE, | 36 | text: Notification.DEFAULT_HTTP_ERROR_MESSAGE, |
@@ -43,7 +43,7 @@ describe("Components", () => { | @@ -43,7 +43,7 @@ describe("Components", () => { | ||
43 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); | 43 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); |
44 | sweetAlert.swal = jasmine.createSpy("swal"); | 44 | sweetAlert.swal = jasmine.createSpy("swal"); |
45 | 45 | ||
46 | - let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert); | 46 | + let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.$translate); |
47 | component.success("title", "message", 1000); | 47 | component.success("title", "message", 1000); |
48 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ | 48 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ |
49 | type: "success" | 49 | type: "success" |
@@ -55,7 +55,7 @@ describe("Components", () => { | @@ -55,7 +55,7 @@ describe("Components", () => { | ||
55 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); | 55 | let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); |
56 | sweetAlert.swal = jasmine.createSpy("swal"); | 56 | sweetAlert.swal = jasmine.createSpy("swal"); |
57 | 57 | ||
58 | - let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert); | 58 | + let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.$translate); |
59 | component.success("title", "message"); | 59 | component.success("title", "message"); |
60 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ | 60 | expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ |
61 | type: "success", | 61 | type: "success", |
src/app/components/notification/notification.component.ts
1 | import {Injectable, Inject} from "ng-forward"; | 1 | import {Injectable, Inject} from "ng-forward"; |
2 | 2 | ||
3 | @Injectable() | 3 | @Injectable() |
4 | -@Inject("$log", "SweetAlert") | 4 | +@Inject("$log", "SweetAlert", "$translate") |
5 | export class Notification { | 5 | export class Notification { |
6 | 6 | ||
7 | - constructor(private $log: ng.ILogService, private SweetAlert: any) { } | 7 | + constructor( |
8 | + private $log: ng.ILogService, | ||
9 | + private SweetAlert: any, | ||
10 | + private $translate: angular.translate.ITranslateService | ||
11 | + ) { } | ||
8 | 12 | ||
9 | - public static DEFAULT_HTTP_ERROR_MESSAGE = "Something went wrong!"; | 13 | + public static DEFAULT_HTTP_ERROR_TITLE = "notification.http-error.default.title"; |
14 | + public static DEFAULT_HTTP_ERROR_MESSAGE = "notification.http-error.default.message"; | ||
10 | public static DEFAULT_SUCCESS_TIMER = 1000; | 15 | public static DEFAULT_SUCCESS_TIMER = 1000; |
11 | 16 | ||
12 | httpError(status: number, data: any): boolean { | 17 | httpError(status: number, data: any): boolean { |
@@ -14,8 +19,8 @@ export class Notification { | @@ -14,8 +19,8 @@ export class Notification { | ||
14 | 19 | ||
15 | let message = (data || {}).message || Notification.DEFAULT_HTTP_ERROR_MESSAGE; | 20 | let message = (data || {}).message || Notification.DEFAULT_HTTP_ERROR_MESSAGE; |
16 | this.SweetAlert.swal({ | 21 | this.SweetAlert.swal({ |
17 | - title: "Oops...", | ||
18 | - text: message, | 22 | + title: this.$translate.instant(Notification.DEFAULT_HTTP_ERROR_TITLE), |
23 | + text: this.$translate.instant(message), | ||
19 | type: "error" | 24 | type: "error" |
20 | }); | 25 | }); |
21 | return true; // return true to indicate that the error was already handled | 26 | return true; // return true to indicate that the error was already handled |
src/languages/en.json
@@ -17,5 +17,7 @@ | @@ -17,5 +17,7 @@ | ||
17 | "auth.form.login": "Login / Email address", | 17 | "auth.form.login": "Login / Email address", |
18 | "auth.form.password": "Password", | 18 | "auth.form.password": "Password", |
19 | "auth.form.login_button": "Login", | 19 | "auth.form.login_button": "Login", |
20 | - "navbar.content_viewer_actions.new_post": "New Post" | 20 | + "navbar.content_viewer_actions.new_post": "New Post", |
21 | + "notification.http-error.default.message": "Something went wrong!", | ||
22 | + "notification.http-error.default.title": "Oops..." | ||
21 | } | 23 | } |
src/languages/pt.json
@@ -17,5 +17,7 @@ | @@ -17,5 +17,7 @@ | ||
17 | "auth.form.login": "Login / Email", | 17 | "auth.form.login": "Login / Email", |
18 | "auth.form.password": "Senha", | 18 | "auth.form.password": "Senha", |
19 | "auth.form.login_button": "Login", | 19 | "auth.form.login_button": "Login", |
20 | - "navbar.content_viewer_actions.new_post": "Novo Artigo" | 20 | + "navbar.content_viewer_actions.new_post": "Novo Artigo", |
21 | + "notification.http-error.default.message": "Algo deu errado!", | ||
22 | + "notification.http-error.default.title": "Oops..." | ||
21 | } | 23 | } |
src/spec/mocks.ts
@@ -73,7 +73,7 @@ export var mocks = { | @@ -73,7 +73,7 @@ export var mocks = { | ||
73 | use: (lang?: string) => { | 73 | use: (lang?: string) => { |
74 | return lang ? Promise.resolve(lang) : "en"; | 74 | return lang ? Promise.resolve(lang) : "en"; |
75 | }, | 75 | }, |
76 | - instant: () => { } | 76 | + instant: (text: string) => { return text } |
77 | }, | 77 | }, |
78 | tmhDynamicLocale: { | 78 | tmhDynamicLocale: { |
79 | get: () => { }, | 79 | get: () => { }, |