Commit 90add01ad73c626fa267ba7fa790aca848ed7186

Authored by Victor Costa
1 parent 65c1878f
Exists in master and in 1 other branch dev-fixes

Translate texts in notification component

src/app/components/notification/notification.component.spec.ts
... ... @@ -17,7 +17,7 @@ describe("Components", () => {
17 17 let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
18 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 21 component.httpError(500, {});
22 22 expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
23 23 text: Notification.DEFAULT_HTTP_ERROR_MESSAGE,
... ... @@ -30,7 +30,7 @@ describe(&quot;Components&quot;, () =&gt; {
30 30 let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
31 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 34 component.httpError(500, null);
35 35 expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
36 36 text: Notification.DEFAULT_HTTP_ERROR_MESSAGE,
... ... @@ -43,7 +43,7 @@ describe(&quot;Components&quot;, () =&gt; {
43 43 let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
44 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 47 component.success("title", "message", 1000);
48 48 expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
49 49 type: "success"
... ... @@ -55,7 +55,7 @@ describe(&quot;Components&quot;, () =&gt; {
55 55 let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
56 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 59 component.success("title", "message");
60 60 expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
61 61 type: "success",
... ...
src/app/components/notification/notification.component.ts
1 1 import {Injectable, Inject} from "ng-forward";
2 2  
3 3 @Injectable()
4   -@Inject("$log", "SweetAlert")
  4 +@Inject("$log", "SweetAlert", "$translate")
5 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 15 public static DEFAULT_SUCCESS_TIMER = 1000;
11 16  
12 17 httpError(status: number, data: any): boolean {
... ... @@ -14,8 +19,8 @@ export class Notification {
14 19  
15 20 let message = (data || {}).message || Notification.DEFAULT_HTTP_ERROR_MESSAGE;
16 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 24 type: "error"
20 25 });
21 26 return true; // return true to indicate that the error was already handled
... ...
src/languages/en.json
... ... @@ -17,5 +17,7 @@
17 17 "auth.form.login": "Login / Email address",
18 18 "auth.form.password": "Password",
19 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 17 "auth.form.login": "Login / Email",
18 18 "auth.form.password": "Senha",
19 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 73 use: (lang?: string) => {
74 74 return lang ? Promise.resolve(lang) : "en";
75 75 },
76   - instant: () => { }
  76 + instant: (text: string) => { return text }
77 77 },
78 78 tmhDynamicLocale: {
79 79 get: () => { },
... ...