@sofit/view-locale 0.3.0 → 0.3.1

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.
@@ -1,20 +1,20 @@
1
- <testsuites name="Sofit view locale tests" tests="8" failures="0" time="2.894">
2
- <testsuite name="Joi tests" errors="0" failures="0" skipped="0" timestamp="2018-08-01T14:46:59" time="1.59" tests="4">
3
- <testcase classname="Joi tests should return default message" name="Joi tests should return default message" time="0.006">
1
+ <testsuites name="Sofit view locale tests" tests="8" failures="0" time="2.569">
2
+ <testsuite name="Joi tests" errors="0" failures="0" skipped="0" timestamp="2018-08-13T13:48:05" time="1.416" tests="4">
3
+ <testcase classname="Joi tests should return default message" name="Joi tests should return default message" time="0.007">
4
4
  </testcase>
5
5
  <testcase classname="Joi tests should return non label message" name="Joi tests should return non label message" time="0.001">
6
6
  </testcase>
7
- <testcase classname="Joi tests should return translated label message" name="Joi tests should return translated label message" time="0.001">
7
+ <testcase classname="Joi tests should return translated label message" name="Joi tests should return translated label message" time="0">
8
8
  </testcase>
9
- <testcase classname="Joi tests should return translated label index" name="Joi tests should return translated label index" time="0">
9
+ <testcase classname="Joi tests should return translated label index" name="Joi tests should return translated label index" time="0.001">
10
10
  </testcase>
11
11
  </testsuite>
12
- <testsuite name="Vehicle locale test" errors="0" failures="0" skipped="0" timestamp="2018-08-01T14:46:59" time="1.683" tests="4">
13
- <testcase classname="Vehicle locale test Should get translations with reach" name="Vehicle locale test Should get translations with reach" time="0.007">
12
+ <testsuite name="Vehicle locale test" errors="0" failures="0" skipped="0" timestamp="2018-08-13T13:48:05" time="1.479" tests="4">
13
+ <testcase classname="Vehicle locale test Should get translations with reach" name="Vehicle locale test Should get translations with reach" time="0.006">
14
14
  </testcase>
15
- <testcase classname="Vehicle locale test Should replace correctly with reach" name="Vehicle locale test Should replace correctly with reach" time="0">
15
+ <testcase classname="Vehicle locale test Should replace correctly with reach" name="Vehicle locale test Should replace correctly with reach" time="0.001">
16
16
  </testcase>
17
- <testcase classname="Vehicle locale test Should get translations with raw" name="Vehicle locale test Should get translations with raw" time="0.001">
17
+ <testcase classname="Vehicle locale test Should get translations with raw" name="Vehicle locale test Should get translations with raw" time="0">
18
18
  </testcase>
19
19
  <testcase classname="Vehicle locale test Should replace correctly with raw" name="Vehicle locale test Should replace correctly with raw" time="0.001">
20
20
  </testcase>
package/dist/runner.d.ts CHANGED
@@ -9,4 +9,5 @@ export declare class Locale {
9
9
  reach(accessKey: IAccessKey, replaces?: IReplaces): string;
10
10
  raw(path: string, replaces?: IReplaces): string;
11
11
  joi(detail: IValidationErrorItem): string;
12
+ private setJoiLabel;
12
13
  }
package/dist/runner.js CHANGED
@@ -8,6 +8,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const TRANSLATIONS = __importStar(require("./translations"));
11
+ const TRANSLATION_NOT_FOUND = 'Translation not found';
11
12
  class Locale {
12
13
  constructor(language) {
13
14
  switch (language) {
@@ -32,7 +33,7 @@ class Locale {
32
33
  }
33
34
  return text;
34
35
  }
35
- return 'Translation not found';
36
+ return TRANSLATION_NOT_FOUND;
36
37
  }
37
38
  raw(path, replaces) {
38
39
  const paths = path.split('.');
@@ -47,24 +48,31 @@ class Locale {
47
48
  if (target) {
48
49
  return this.reach(target, replaces);
49
50
  }
50
- return 'Translation not found';
51
+ return TRANSLATION_NOT_FOUND;
51
52
  }
52
53
  joi(detail) {
53
54
  const accessKey = TRANSLATIONS.joi[detail.type];
54
55
  if (accessKey) {
55
- if (detail.context && (!(detail.context.key || '').startsWith('cf_'))) {
56
- if (typeof detail.context.label === 'number') {
57
- detail.context.label = this.reach(TRANSLATIONS.joi.index, {
58
- index: (detail.context.label + 1).toString()
59
- });
60
- }
61
- else {
62
- detail.context.label = this.raw(detail.context.label);
63
- }
64
- }
56
+ this.setJoiLabel(detail);
65
57
  return this.reach(TRANSLATIONS.joi[detail.type], detail.context);
66
58
  }
67
59
  return `There is no translation for joi type '${detail.type}'`;
68
60
  }
61
+ setJoiLabel(detail) {
62
+ if (detail.context && (!(detail.context.key || '').startsWith('cf_'))) {
63
+ if (typeof detail.context.label === 'number') {
64
+ detail.context.label = this.reach(TRANSLATIONS.joi.index, {
65
+ index: (detail.context.label + 1).toString(),
66
+ path: detail.path[0]
67
+ });
68
+ }
69
+ else {
70
+ detail.context.label = this.raw(detail.context.label);
71
+ }
72
+ if (detail.context.label === TRANSLATION_NOT_FOUND) {
73
+ detail.context.label = detail.context.key;
74
+ }
75
+ }
76
+ }
69
77
  }
70
78
  exports.Locale = Locale;
@@ -2,13 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.joi = {
4
4
  'index': {
5
- ptBR: '{{index}}º valor',
6
- es: '{{index}}er valor'
5
+ ptBR: '{{index}}º valor de {{path}}',
6
+ es: '{{index}}er valor de {{path}}'
7
7
  },
8
8
  'string.base': {
9
9
  ptBR: '{{label}} precisa ser um texto.',
10
10
  es: '{{label}} debe se uno texto.'
11
11
  },
12
+ 'string.email': {
13
+ ptBR: '{{label}} precisa ser um email válido.',
14
+ es: '{{label}}'
15
+ },
12
16
  'number.base': {
13
17
  ptBR: '{{label}} precisa ser numérico.',
14
18
  es: '{{label}} debe ser numérico.'
@@ -2,3 +2,4 @@ export { gate } from './modules/gate/gate';
2
2
  export { button } from './common/buttons';
3
3
  export { joi } from './common/joi';
4
4
  export { databaseErrors } from './common/database-errors';
5
+ export { company } from './modules/company/company';
@@ -8,3 +8,5 @@ var joi_1 = require("./common/joi");
8
8
  exports.joi = joi_1.joi;
9
9
  var database_errors_1 = require("./common/database-errors");
10
10
  exports.databaseErrors = database_errors_1.databaseErrors;
11
+ var company_1 = require("./modules/company/company");
12
+ exports.company = company_1.company;
@@ -0,0 +1,66 @@
1
+ export declare const company: {
2
+ name: {
3
+ ptBR: string;
4
+ es: string;
5
+ };
6
+ cnpj: {
7
+ ptBR: string;
8
+ es: string;
9
+ };
10
+ address: {
11
+ ptBR: string;
12
+ es: string;
13
+ };
14
+ address_num: {
15
+ ptBR: string;
16
+ es: string;
17
+ };
18
+ address_neighborhood: {
19
+ ptBR: string;
20
+ es: string;
21
+ };
22
+ address_state_id: {
23
+ ptBR: string;
24
+ es: string;
25
+ };
26
+ address_city_id: {
27
+ ptBR: string;
28
+ es: string;
29
+ };
30
+ address_complementary: {
31
+ ptBR: string;
32
+ es: string;
33
+ };
34
+ postal_code: {
35
+ ptBR: string;
36
+ es: string;
37
+ };
38
+ responsible: {
39
+ ptBR: string;
40
+ es: string;
41
+ };
42
+ cnae: {
43
+ ptBR: string;
44
+ es: string;
45
+ };
46
+ cnae_description: {
47
+ ptBR: string;
48
+ es: string;
49
+ };
50
+ secondary_cnae: {
51
+ ptBR: string;
52
+ es: string;
53
+ };
54
+ external_id: {
55
+ ptBR: string;
56
+ es: string;
57
+ };
58
+ alert_emails: {
59
+ ptBR: string;
60
+ es: string;
61
+ };
62
+ alert_users: {
63
+ ptBR: string;
64
+ es: string;
65
+ };
66
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.company = {
4
+ name: {
5
+ ptBR: 'Nome',
6
+ es: 'Nombre'
7
+ },
8
+ cnpj: {
9
+ ptBR: 'CNPJ/CPF',
10
+ es: 'CNPJ/CPF'
11
+ },
12
+ address: {
13
+ ptBR: 'Endereço',
14
+ es: 'Dirección'
15
+ },
16
+ address_num: {
17
+ ptBR: 'Nº',
18
+ es: 'Nº'
19
+ },
20
+ address_neighborhood: {
21
+ ptBR: 'Bairro',
22
+ es: 'Bario'
23
+ },
24
+ address_state_id: {
25
+ ptBR: 'UF',
26
+ es: 'Provincia'
27
+ },
28
+ address_city_id: {
29
+ ptBR: 'Cidade',
30
+ es: 'Ciudad'
31
+ },
32
+ address_complementary: {
33
+ ptBR: 'Complemento',
34
+ es: 'Complemento'
35
+ },
36
+ postal_code: {
37
+ ptBR: 'CEP',
38
+ es: 'Codico postal'
39
+ },
40
+ responsible: {
41
+ ptBR: 'Responsável',
42
+ es: 'Responsable'
43
+ },
44
+ cnae: {
45
+ ptBR: 'CNAE',
46
+ es: 'CNAE'
47
+ },
48
+ cnae_description: {
49
+ ptBR: 'Descrição do CNAE',
50
+ es: 'Descrición del CNAE'
51
+ },
52
+ secondary_cnae: {
53
+ ptBR: 'CNAE Secundário',
54
+ es: 'CNAE Segundario'
55
+ },
56
+ external_id: {
57
+ ptBR: 'Chave externa',
58
+ es: 'Clave externa'
59
+ },
60
+ alert_emails: {
61
+ ptBR: 'Emails para recebimento de alerta',
62
+ es: 'Emails para recebimiento de alerta'
63
+ },
64
+ alert_users: {
65
+ ptBR: 'Usuários para recebimento de alertas',
66
+ es: 'Usuarios para recebimento de alertas'
67
+ }
68
+ };
package/lib/runner.ts CHANGED
@@ -2,6 +2,8 @@ import { IValidationErrorItem } from './joi/joi.interface';
2
2
  import { IAccessKey, LANGUAGES } from './languages';
3
3
  import * as TRANSLATIONS from './translations';
4
4
 
5
+ const TRANSLATION_NOT_FOUND = 'Translation not found';
6
+
5
7
  export interface IReplaces {
6
8
  [key: string]: string;
7
9
  }
@@ -46,7 +48,7 @@ export class Locale {
46
48
  return text;
47
49
  }
48
50
 
49
- return 'Translation not found';
51
+ return TRANSLATION_NOT_FOUND;
50
52
  }
51
53
 
52
54
  public raw(path: string, replaces?: IReplaces): string {
@@ -71,7 +73,7 @@ export class Locale {
71
73
  return this.reach(target, replaces);
72
74
  }
73
75
 
74
- return 'Translation not found';
76
+ return TRANSLATION_NOT_FOUND;
75
77
  }
76
78
 
77
79
  public joi(detail: IValidationErrorItem) {
@@ -80,22 +82,33 @@ export class Locale {
80
82
 
81
83
  if (accessKey) {
82
84
 
83
- if (detail.context && (!(detail.context.key || '').startsWith('cf_'))) {
85
+ this.setJoiLabel(detail);
86
+
87
+ return this.reach(TRANSLATIONS.joi[detail.type], detail.context as IReplaces);
88
+ }
89
+
90
+ return `There is no translation for joi type '${detail.type}'`;
91
+ }
84
92
 
85
- if (typeof detail.context.label === 'number') {
93
+ private setJoiLabel(detail: IValidationErrorItem) {
86
94
 
87
- detail.context.label = this.reach(TRANSLATIONS.joi.index, {
88
- index: (detail.context.label as number + 1).toString()
89
- });
90
- } else {
95
+ if (detail.context && (!(detail.context.key || '').startsWith('cf_'))) {
91
96
 
92
- detail.context.label = this.raw(detail.context.label as string);
93
- }
97
+ if (typeof detail.context.label === 'number') {
98
+
99
+ detail.context.label = this.reach(TRANSLATIONS.joi.index, {
100
+ index: (detail.context.label as number + 1).toString(),
101
+ path: detail.path[0]
102
+ });
103
+ } else {
104
+
105
+ detail.context.label = this.raw(detail.context.label as string);
94
106
  }
95
107
 
96
- return this.reach(TRANSLATIONS.joi[detail.type], detail.context as IReplaces);
97
- }
108
+ if (detail.context.label === TRANSLATION_NOT_FOUND) {
98
109
 
99
- return `There is no translation for joi type '${detail.type}'`;
110
+ detail.context.label = detail.context.key;
111
+ }
112
+ }
100
113
  }
101
114
  }
@@ -57,17 +57,19 @@ describe('Joi tests', () => {
57
57
 
58
58
  expect(localeptBR.joi({
59
59
  type: 'string.base',
60
+ path: ['path'],
60
61
  context: {
61
62
  key: 0,
62
63
  label: 0
63
64
  }
64
- } as any)).toEqual('1º valor precisa ser um texto.');
65
+ } as any)).toEqual('1º valor de path precisa ser um texto.');
65
66
  expect(localeptES.joi({
66
67
  type: 'string.base',
68
+ path: ['path'],
67
69
  context: {
68
70
  key: 0,
69
71
  label: 0
70
72
  }
71
- } as any)).toEqual('1er valor debe se uno texto.');
73
+ } as any)).toEqual('1er valor de path debe se uno texto.');
72
74
  });
73
75
  });
@@ -2,13 +2,17 @@ import { ITranslation } from '../translation.interface';
2
2
 
3
3
  export const joi: ITranslation = {
4
4
  'index': {
5
- ptBR: '{{index}}º valor',
6
- es: '{{index}}er valor'
5
+ ptBR: '{{index}}º valor de {{path}}',
6
+ es: '{{index}}er valor de {{path}}'
7
7
  },
8
8
  'string.base': {
9
9
  ptBR: '{{label}} precisa ser um texto.',
10
10
  es: '{{label}} debe se uno texto.'
11
11
  },
12
+ 'string.email': {
13
+ ptBR: '{{label}} precisa ser um email válido.',
14
+ es: '{{label}}'
15
+ },
12
16
  'number.base': {
13
17
  ptBR: '{{label}} precisa ser numérico.',
14
18
  es: '{{label}} debe ser numérico.'
@@ -1,4 +1,5 @@
1
1
  export { gate } from './modules/gate/gate';
2
2
  export { button } from './common/buttons';
3
3
  export { joi } from './common/joi';
4
- export { databaseErrors } from './common/database-errors';
4
+ export { databaseErrors } from './common/database-errors';
5
+ export { company } from './modules/company/company';
@@ -0,0 +1,66 @@
1
+ export const company = {
2
+ name: {
3
+ ptBR: 'Nome',
4
+ es: 'Nombre'
5
+ },
6
+ cnpj: {
7
+ ptBR: 'CNPJ/CPF',
8
+ es: 'CNPJ/CPF'
9
+ },
10
+ address: {
11
+ ptBR: 'Endereço',
12
+ es: 'Dirección'
13
+ },
14
+ address_num: {
15
+ ptBR: 'Nº',
16
+ es: 'Nº'
17
+ },
18
+ address_neighborhood: {
19
+ ptBR: 'Bairro',
20
+ es: 'Bario'
21
+ },
22
+ address_state_id: {
23
+ ptBR: 'UF',
24
+ es: 'Provincia'
25
+ },
26
+ address_city_id: {
27
+ ptBR: 'Cidade',
28
+ es: 'Ciudad'
29
+ },
30
+ address_complementary: {
31
+ ptBR: 'Complemento',
32
+ es: 'Complemento'
33
+ },
34
+ postal_code: {
35
+ ptBR: 'CEP',
36
+ es: 'Codico postal'
37
+ },
38
+ responsible: {
39
+ ptBR: 'Responsável',
40
+ es: 'Responsable'
41
+ },
42
+ cnae: {
43
+ ptBR: 'CNAE',
44
+ es: 'CNAE'
45
+ },
46
+ cnae_description: {
47
+ ptBR: 'Descrição do CNAE',
48
+ es: 'Descrición del CNAE'
49
+ },
50
+ secondary_cnae: {
51
+ ptBR: 'CNAE Secundário',
52
+ es: 'CNAE Segundario'
53
+ },
54
+ external_id: {
55
+ ptBR: 'Chave externa',
56
+ es: 'Clave externa'
57
+ },
58
+ alert_emails: {
59
+ ptBR: 'Emails para recebimento de alerta',
60
+ es: 'Emails para recebimiento de alerta'
61
+ },
62
+ alert_users: {
63
+ ptBR: 'Usuários para recebimento de alertas',
64
+ es: 'Usuarios para recebimento de alertas'
65
+ }
66
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sofit/view-locale",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Traduções do Sofit View",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",