@sofit/view-locale 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/commit-msg.js +0 -1
- package/coverage/jest/results.xml +14 -4
- package/dist/runner.js +9 -2
- package/dist/translations/common/database-errors.js +4 -0
- package/dist/translations/common/joi.js +38 -6
- package/lib/runner.ts +10 -2
- package/lib/tests/basic.spec.ts +5 -5
- package/lib/tests/joi.spec.ts +73 -0
- package/lib/translations/common/database-errors.ts +4 -0
- package/lib/translations/common/joi.ts +38 -6
- package/package.json +1 -1
package/.vscode/commit-msg.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
<testsuites name="Sofit view locale tests" tests="
|
|
2
|
-
<testsuite name="
|
|
1
|
+
<testsuites name="Sofit view locale tests" tests="8" failures="0" time="2.554">
|
|
2
|
+
<testsuite name="Joi tests" errors="0" failures="0" skipped="0" timestamp="2018-07-30T21:21:03" time="1.377" tests="4">
|
|
3
|
+
<testcase classname="Joi tests should return default message" name="Joi tests should return default message" time="0.006">
|
|
4
|
+
</testcase>
|
|
5
|
+
<testcase classname="Joi tests should return non label message" name="Joi tests should return non label message" time="0">
|
|
6
|
+
</testcase>
|
|
7
|
+
<testcase classname="Joi tests should return translated label message" name="Joi tests should return translated label message" time="0.001">
|
|
8
|
+
</testcase>
|
|
9
|
+
<testcase classname="Joi tests should return translated label index" name="Joi tests should return translated label index" time="0.001">
|
|
10
|
+
</testcase>
|
|
11
|
+
</testsuite>
|
|
12
|
+
<testsuite name="Vehicle locale test" errors="0" failures="0" skipped="0" timestamp="2018-07-30T21:21:03" time="1.443" tests="4">
|
|
3
13
|
<testcase classname="Vehicle locale test Should get translations with reach" name="Vehicle locale test Should get translations with reach" time="0.006">
|
|
4
14
|
</testcase>
|
|
5
15
|
<testcase classname="Vehicle locale test Should replace correctly with reach" name="Vehicle locale test Should replace correctly with reach" time="0.001">
|
|
6
16
|
</testcase>
|
|
7
|
-
<testcase classname="Vehicle locale test Should get translations with raw" name="Vehicle locale test Should get translations with raw" time="0">
|
|
17
|
+
<testcase classname="Vehicle locale test Should get translations with raw" name="Vehicle locale test Should get translations with raw" time="0.001">
|
|
8
18
|
</testcase>
|
|
9
|
-
<testcase classname="Vehicle locale test Should replace correctly with raw" name="Vehicle locale test Should replace correctly with raw" time="0
|
|
19
|
+
<testcase classname="Vehicle locale test Should replace correctly with raw" name="Vehicle locale test Should replace correctly with raw" time="0">
|
|
10
20
|
</testcase>
|
|
11
21
|
</testsuite>
|
|
12
22
|
</testsuites>
|
package/dist/runner.js
CHANGED
|
@@ -45,8 +45,15 @@ class Locale {
|
|
|
45
45
|
joi(detail) {
|
|
46
46
|
const accessKey = TRANSLATIONS.joi[detail.type];
|
|
47
47
|
if (accessKey) {
|
|
48
|
-
if (detail.context) {
|
|
49
|
-
detail.context.label
|
|
48
|
+
if (detail.context && (!(detail.context.key || '').startsWith('cf_'))) {
|
|
49
|
+
if (typeof detail.context.label === 'number') {
|
|
50
|
+
detail.context.label = this.reach(TRANSLATIONS.joi.index, {
|
|
51
|
+
index: (detail.context.label + 1).toString()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
detail.context.label = this.raw(detail.context.label);
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
return this.reach(TRANSLATIONS.joi[detail.type], detail.context);
|
|
52
59
|
}
|
|
@@ -8,5 +8,9 @@ exports.databaseErrors = {
|
|
|
8
8
|
unique_constraint: {
|
|
9
9
|
ptBR: 'Já existe um {{label}} com valor "{{value}}".',
|
|
10
10
|
es: 'Ya existe un {{label}} con valor "{{value}}".'
|
|
11
|
+
},
|
|
12
|
+
foreignkey_constraint: {
|
|
13
|
+
ptBR: 'Houve um erro ao salvar o registro. Um ou mais relacionamentos não foram encontrados.',
|
|
14
|
+
es: ''
|
|
11
15
|
}
|
|
12
16
|
};
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.joi = {
|
|
4
|
+
'index': {
|
|
5
|
+
ptBR: '{{index}}º valor',
|
|
6
|
+
es: '{{index}}er valor'
|
|
7
|
+
},
|
|
4
8
|
'string.base': {
|
|
5
|
-
ptBR: '
|
|
6
|
-
es: '
|
|
9
|
+
ptBR: '{{label}} precisa ser um texto.',
|
|
10
|
+
es: '{{label}} debe se uno texto.'
|
|
7
11
|
},
|
|
8
12
|
'number.base': {
|
|
9
|
-
ptBR: '
|
|
10
|
-
es: ''
|
|
13
|
+
ptBR: '{{label}} precisa ser numérico.',
|
|
14
|
+
es: '{{label}} debe ser numérico.'
|
|
11
15
|
},
|
|
12
16
|
'number.min': {
|
|
13
|
-
ptBR: '
|
|
14
|
-
es: ''
|
|
17
|
+
ptBR: '{{label}} precisa ter no mínimo {{limit}}.',
|
|
18
|
+
es: '{{label}} debe tener al menos {{limit}}.'
|
|
19
|
+
},
|
|
20
|
+
'number.integer': {
|
|
21
|
+
ptBR: '{{label}} precisa ser um número inteiro.',
|
|
22
|
+
es: '{{label}} debe ser un entero.'
|
|
23
|
+
},
|
|
24
|
+
'date.isoDate': {
|
|
25
|
+
ptBR: '{{label}} precisa ser uma data válida.',
|
|
26
|
+
es: '{{label}} debe ser una fecha válida.'
|
|
27
|
+
},
|
|
28
|
+
'array.base': {
|
|
29
|
+
ptBR: '{{label}} precisa ser um array.',
|
|
30
|
+
es: '{{label}} debe ser una matriz.'
|
|
31
|
+
},
|
|
32
|
+
'boolean.base': {
|
|
33
|
+
ptBR: '{{label}} precisa ser um booleano.',
|
|
34
|
+
es: '{{label}} debe ser un booleano.'
|
|
35
|
+
},
|
|
36
|
+
'any.allowOnly': {
|
|
37
|
+
ptBR: '{{label}} não contem um valor válido. Os valores permitidos são: {{valids}}.',
|
|
38
|
+
es: '{{label}} no contiene un valor válido. Los valores permitidos son: {{valids}}.'
|
|
39
|
+
},
|
|
40
|
+
'any.required': {
|
|
41
|
+
ptBR: '{{label}} é obrigatório.',
|
|
42
|
+
es: '{{label}} es obligatorio.'
|
|
43
|
+
},
|
|
44
|
+
'any.empty': {
|
|
45
|
+
ptBR: '{{label}} não permite valores vazios.',
|
|
46
|
+
es: '{{label}} no permite valores vacíos.'
|
|
15
47
|
}
|
|
16
48
|
};
|
package/lib/runner.ts
CHANGED
|
@@ -68,9 +68,17 @@ export class Locale {
|
|
|
68
68
|
|
|
69
69
|
if (accessKey) {
|
|
70
70
|
|
|
71
|
-
if (detail.context) {
|
|
71
|
+
if (detail.context && (!(detail.context.key || '').startsWith('cf_'))) {
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
if (typeof detail.context.label === 'number') {
|
|
74
|
+
|
|
75
|
+
detail.context.label = this.reach(TRANSLATIONS.joi.index, {
|
|
76
|
+
index: (detail.context.label as number + 1).toString()
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
|
|
80
|
+
detail.context.label = this.raw(detail.context.label as string);
|
|
81
|
+
}
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
return this.reach(TRANSLATIONS.joi[detail.type], detail.context as IReplaces);
|
package/lib/tests/basic.spec.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { i18n, Locale } from '../index';
|
|
|
3
3
|
describe('Vehicle locale test', () => {
|
|
4
4
|
|
|
5
5
|
const localeptBR = new Locale('ptBR');
|
|
6
|
-
const
|
|
6
|
+
const localeES = new Locale('es');
|
|
7
7
|
|
|
8
8
|
it('Should get translations with reach', () => {
|
|
9
9
|
|
|
10
10
|
expect(localeptBR.reach(i18n.gate.name))
|
|
11
11
|
.toEqual(i18n.gate.name.ptBR);
|
|
12
|
-
expect(
|
|
12
|
+
expect(localeES.reach(i18n.gate.name))
|
|
13
13
|
.toEqual(i18n.gate.name.es);
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -20,7 +20,7 @@ describe('Vehicle locale test', () => {
|
|
|
20
20
|
value: 'value'
|
|
21
21
|
})).toEqual('Já existe um label com valor "value".');
|
|
22
22
|
|
|
23
|
-
expect(
|
|
23
|
+
expect(localeES.reach(i18n.databaseErrors.unique_constraint, {
|
|
24
24
|
label: 'label2',
|
|
25
25
|
value: 'value2'
|
|
26
26
|
})).toEqual('Ya existe un label2 con valor "value2".');
|
|
@@ -30,7 +30,7 @@ describe('Vehicle locale test', () => {
|
|
|
30
30
|
|
|
31
31
|
expect(localeptBR.raw('databaseErrors.generic'))
|
|
32
32
|
.toEqual(i18n.databaseErrors.generic.ptBR);
|
|
33
|
-
expect(
|
|
33
|
+
expect(localeES.raw('databaseErrors.generic'))
|
|
34
34
|
.toEqual(i18n.databaseErrors.generic.es);
|
|
35
35
|
});
|
|
36
36
|
|
|
@@ -41,7 +41,7 @@ describe('Vehicle locale test', () => {
|
|
|
41
41
|
value: 'value'
|
|
42
42
|
})).toEqual('Já existe um label com valor "value".');
|
|
43
43
|
|
|
44
|
-
expect(
|
|
44
|
+
expect(localeES.raw('databaseErrors.unique_constraint', {
|
|
45
45
|
label: 'label2',
|
|
46
46
|
value: 'value2'
|
|
47
47
|
})).toEqual('Ya existe un label2 con valor "value2".');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Locale } from '../runner';
|
|
2
|
+
|
|
3
|
+
// tslint:disable:no-any
|
|
4
|
+
|
|
5
|
+
describe('Joi tests', () => {
|
|
6
|
+
|
|
7
|
+
const localeptBR = new Locale('ptBR');
|
|
8
|
+
const localeptES = new Locale('es');
|
|
9
|
+
|
|
10
|
+
it('should return default message', () => {
|
|
11
|
+
|
|
12
|
+
expect(localeptBR.joi({
|
|
13
|
+
type: 'nãoexisteesseerror'
|
|
14
|
+
} as any)).toEqual('There is no translation for joi type \'nãoexisteesseerror\'');
|
|
15
|
+
expect(localeptES.joi({
|
|
16
|
+
type: 'nãoexisteesseerror'
|
|
17
|
+
} as any)).toEqual('There is no translation for joi type \'nãoexisteesseerror\'');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return non label message', () => {
|
|
21
|
+
|
|
22
|
+
expect(localeptBR.joi({
|
|
23
|
+
type: 'string.base',
|
|
24
|
+
context: {
|
|
25
|
+
key: 'cf_1',
|
|
26
|
+
label: 'mararaia'
|
|
27
|
+
}
|
|
28
|
+
} as any)).toEqual('mararaia precisa ser um texto.');
|
|
29
|
+
expect(localeptES.joi({
|
|
30
|
+
type: 'string.base',
|
|
31
|
+
context: {
|
|
32
|
+
key: 'cf_1',
|
|
33
|
+
label: 'mararaia'
|
|
34
|
+
}
|
|
35
|
+
} as any)).toEqual('mararaia debe se uno texto.');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return translated label message', () => {
|
|
39
|
+
|
|
40
|
+
expect(localeptBR.joi({
|
|
41
|
+
type: 'string.base',
|
|
42
|
+
context: {
|
|
43
|
+
key: 'otra',
|
|
44
|
+
label: 'gate.name'
|
|
45
|
+
}
|
|
46
|
+
} as any)).toEqual('Nome precisa ser um texto.');
|
|
47
|
+
expect(localeptES.joi({
|
|
48
|
+
type: 'string.base',
|
|
49
|
+
context: {
|
|
50
|
+
key: 'otra',
|
|
51
|
+
label: 'gate.name'
|
|
52
|
+
}
|
|
53
|
+
} as any)).toEqual('Nombre debe se uno texto.');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return translated label index', () => {
|
|
57
|
+
|
|
58
|
+
expect(localeptBR.joi({
|
|
59
|
+
type: 'string.base',
|
|
60
|
+
context: {
|
|
61
|
+
key: 0,
|
|
62
|
+
label: 0
|
|
63
|
+
}
|
|
64
|
+
} as any)).toEqual('1º valor precisa ser um texto.');
|
|
65
|
+
expect(localeptES.joi({
|
|
66
|
+
type: 'string.base',
|
|
67
|
+
context: {
|
|
68
|
+
key: 0,
|
|
69
|
+
label: 0
|
|
70
|
+
}
|
|
71
|
+
} as any)).toEqual('1er valor debe se uno texto.');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -8,5 +8,9 @@ export const databaseErrors: ITranslation = {
|
|
|
8
8
|
unique_constraint: {
|
|
9
9
|
ptBR: 'Já existe um {{label}} com valor "{{value}}".',
|
|
10
10
|
es: 'Ya existe un {{label}} con valor "{{value}}".'
|
|
11
|
+
},
|
|
12
|
+
foreignkey_constraint: {
|
|
13
|
+
ptBR: 'Houve um erro ao salvar o registro. Um ou mais relacionamentos não foram encontrados.',
|
|
14
|
+
es: ''
|
|
11
15
|
}
|
|
12
16
|
};
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
import { ITranslation } from '../translation.interface';
|
|
2
2
|
|
|
3
3
|
export const joi: ITranslation = {
|
|
4
|
+
'index': {
|
|
5
|
+
ptBR: '{{index}}º valor',
|
|
6
|
+
es: '{{index}}er valor'
|
|
7
|
+
},
|
|
4
8
|
'string.base': {
|
|
5
|
-
ptBR: '
|
|
6
|
-
es: '
|
|
9
|
+
ptBR: '{{label}} precisa ser um texto.',
|
|
10
|
+
es: '{{label}} debe se uno texto.'
|
|
7
11
|
},
|
|
8
12
|
'number.base': {
|
|
9
|
-
ptBR: '
|
|
10
|
-
es: ''
|
|
13
|
+
ptBR: '{{label}} precisa ser numérico.',
|
|
14
|
+
es: '{{label}} debe ser numérico.'
|
|
11
15
|
},
|
|
12
16
|
'number.min': {
|
|
13
|
-
ptBR: '
|
|
14
|
-
es: ''
|
|
17
|
+
ptBR: '{{label}} precisa ter no mínimo {{limit}}.',
|
|
18
|
+
es: '{{label}} debe tener al menos {{limit}}.'
|
|
19
|
+
},
|
|
20
|
+
'number.integer': {
|
|
21
|
+
ptBR: '{{label}} precisa ser um número inteiro.',
|
|
22
|
+
es: '{{label}} debe ser un entero.'
|
|
23
|
+
},
|
|
24
|
+
'date.isoDate': {
|
|
25
|
+
ptBR: '{{label}} precisa ser uma data válida.',
|
|
26
|
+
es: '{{label}} debe ser una fecha válida.'
|
|
27
|
+
},
|
|
28
|
+
'array.base': {
|
|
29
|
+
ptBR: '{{label}} precisa ser um array.',
|
|
30
|
+
es: '{{label}} debe ser una matriz.'
|
|
31
|
+
},
|
|
32
|
+
'boolean.base': {
|
|
33
|
+
ptBR: '{{label}} precisa ser um booleano.',
|
|
34
|
+
es: '{{label}} debe ser un booleano.'
|
|
35
|
+
},
|
|
36
|
+
'any.allowOnly': {
|
|
37
|
+
ptBR: '{{label}} não contem um valor válido. Os valores permitidos são: {{valids}}.',
|
|
38
|
+
es: '{{label}} no contiene un valor válido. Los valores permitidos son: {{valids}}.'
|
|
39
|
+
},
|
|
40
|
+
'any.required': {
|
|
41
|
+
ptBR: '{{label}} é obrigatório.',
|
|
42
|
+
es: '{{label}} es obligatorio.'
|
|
43
|
+
},
|
|
44
|
+
'any.empty': {
|
|
45
|
+
ptBR: '{{label}} não permite valores vazios.',
|
|
46
|
+
es: '{{label}} no permite valores vacíos.'
|
|
15
47
|
}
|
|
16
48
|
};
|