1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('../base/Base');
|
7 |
|
8 | module.exports = class Message extends Base {
|
9 |
|
10 | constructor (message, params, source, language) {
|
11 | super({
|
12 | message,
|
13 | params,
|
14 | source,
|
15 | language
|
16 | });
|
17 | }
|
18 |
|
19 | addParams (params) {
|
20 | this.params = Object.assign(this.params || {}, params);
|
21 | return this;
|
22 | }
|
23 |
|
24 | translate (i18n, language) {
|
25 | return this.source
|
26 | ? i18n.translate(this.message, this.params, this.source, this.language || language)
|
27 | : i18n.format(this.message, this.params, this.language || language);
|
28 | }
|
29 |
|
30 | toString () {
|
31 | return this.message;
|
32 | }
|
33 | }; |
\ | No newline at end of file |