@sofit/view-locale 0.1.1 → 0.1.3
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/.circleci/config.yml +9 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/languages.d.ts +10 -0
- package/dist/languages.js +2 -0
- package/dist/runner.d.ts +11 -0
- package/dist/runner.js +48 -0
- package/dist/translations/common/buttons.d.ts +6 -0
- package/dist/translations/common/buttons.js +8 -0
- package/dist/translations/index.d.ts +2 -0
- package/dist/translations/index.js +7 -0
- package/dist/translations/modules/vehicle.d.ts +18 -0
- package/dist/translations/modules/vehicle.js +20 -0
- package/package.json +3 -2
- package/readme.md +3 -0
package/.circleci/config.yml
CHANGED
|
@@ -29,6 +29,10 @@ jobs:
|
|
|
29
29
|
- node_modules
|
|
30
30
|
key: v1-dependencies-{{ checksum "package.json" }}
|
|
31
31
|
|
|
32
|
+
- run:
|
|
33
|
+
name: Run code quality
|
|
34
|
+
command: npm run lint
|
|
35
|
+
|
|
32
36
|
- run:
|
|
33
37
|
name: Run tests
|
|
34
38
|
command: npm test
|
|
@@ -37,7 +41,7 @@ jobs:
|
|
|
37
41
|
root: ~/repo
|
|
38
42
|
paths: .
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
deploy:
|
|
41
45
|
<<: *defaults
|
|
42
46
|
steps:
|
|
43
47
|
- attach_workspace:
|
|
@@ -45,31 +49,24 @@ jobs:
|
|
|
45
49
|
- run:
|
|
46
50
|
name: Build from typescript to javascript
|
|
47
51
|
command: npm run build
|
|
48
|
-
|
|
49
|
-
deploy:
|
|
50
|
-
<<: *defaults
|
|
51
|
-
steps:
|
|
52
|
-
- attach_workspace:
|
|
53
|
-
at: ~/repo
|
|
54
52
|
- run:
|
|
55
53
|
name: Authenticate with registry
|
|
56
54
|
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
|
|
57
55
|
- run:
|
|
58
|
-
name: Publish
|
|
56
|
+
name: Publish new version of @sofit/view-locale
|
|
59
57
|
command: npm publish
|
|
58
|
+
- run:
|
|
59
|
+
name: Creating a new tag
|
|
60
|
+
command: N=`cat package.json | grep version | egrep "[0-9].[0-9].[0-9]" -o` && git tag -a v$N -m "New version of @sofit/view-locale $N" && git push --tags
|
|
60
61
|
|
|
61
62
|
workflows:
|
|
62
63
|
version: 2
|
|
63
64
|
test-build-deploy:
|
|
64
65
|
jobs:
|
|
65
66
|
- test
|
|
66
|
-
- build:
|
|
67
|
-
requires:
|
|
68
|
-
- test
|
|
69
67
|
- deploy:
|
|
70
68
|
requires:
|
|
71
69
|
- test
|
|
72
|
-
- build
|
|
73
70
|
filters:
|
|
74
71
|
branches:
|
|
75
72
|
only: master
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { locale, Locale } from './runner';
|
package/dist/index.js
ADDED
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IAccessKey, LANGUAGES } from './languages';
|
|
2
|
+
export interface IReplaces {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class Locale {
|
|
6
|
+
private readonly language;
|
|
7
|
+
constructor(language: LANGUAGES);
|
|
8
|
+
reach(accessKey: IAccessKey, replaces?: IReplaces): string;
|
|
9
|
+
raw(context: any, path: string, replaces?: IReplaces): string;
|
|
10
|
+
}
|
|
11
|
+
export declare function locale(language: LANGUAGES): Locale;
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Locale {
|
|
4
|
+
constructor(language) {
|
|
5
|
+
this.language = language;
|
|
6
|
+
}
|
|
7
|
+
reach(accessKey, replaces) {
|
|
8
|
+
let text = accessKey[this.language];
|
|
9
|
+
if (Boolean(text)) {
|
|
10
|
+
if (replaces !== undefined) {
|
|
11
|
+
for (const key in replaces) {
|
|
12
|
+
if (replaces.hasOwnProperty(key)) {
|
|
13
|
+
const value = replaces[key];
|
|
14
|
+
text = text.replace(`{{${key}}}`, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
return 'Translation not found';
|
|
21
|
+
}
|
|
22
|
+
raw(context, path, replaces) {
|
|
23
|
+
const paths = path.split('.');
|
|
24
|
+
let target = context;
|
|
25
|
+
for (const element of paths) {
|
|
26
|
+
target = target[element];
|
|
27
|
+
if (!target) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (target) {
|
|
32
|
+
return this.reach(target, replaces);
|
|
33
|
+
}
|
|
34
|
+
return 'Translation not found';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Locale = Locale;
|
|
38
|
+
const cache = {
|
|
39
|
+
ptBR: null,
|
|
40
|
+
es: null
|
|
41
|
+
};
|
|
42
|
+
function locale(language) {
|
|
43
|
+
if (cache[language] === null) {
|
|
44
|
+
cache[language] = new Locale(language);
|
|
45
|
+
}
|
|
46
|
+
return cache[language];
|
|
47
|
+
}
|
|
48
|
+
exports.locale = locale;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vehicle = {
|
|
4
|
+
label: {
|
|
5
|
+
name: {
|
|
6
|
+
ptBR: 'Nome',
|
|
7
|
+
es: 'Nuombre'
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
not_found: {
|
|
12
|
+
ptBR: 'Não encontrado',
|
|
13
|
+
es: 'nao coisado'
|
|
14
|
+
},
|
|
15
|
+
test: {
|
|
16
|
+
ptBR: 'Teste de coisa pra {{variable}}',
|
|
17
|
+
es: 'Carai {{variable}}'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sofit/view-locale",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Traduções do Sofit View",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "jest --config ./jest.config.json",
|
|
9
9
|
"dev": "nodemon",
|
|
10
|
-
"
|
|
10
|
+
"lint": "tslint --project ./",
|
|
11
|
+
"build": "tsc --p ./"
|
|
11
12
|
},
|
|
12
13
|
"author": "desenvolvimento@sofit4.com.br",
|
|
13
14
|
"contributors": [
|
package/readme.md
ADDED