@siemens/element-translate-ng 47.0.0 → 47.1.0-next.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@siemens/element-translate-ng",
3
3
  "description": "Element translation abstraction layer.",
4
- "version": "47.0.0",
4
+ "version": "47.1.0-next.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
@@ -17,9 +17,6 @@
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
20
- "bin": {
21
- "update-translatable-keys": "bin/update-translatable-keys.js"
22
- },
23
20
  "peerDependencies": {
24
21
  "@angular/common": "19",
25
22
  "@angular/core": "19",
@@ -30,10 +27,6 @@
30
27
  "optional": true
31
28
  }
32
29
  },
33
- "dependencies": {
34
- "fast-xml-parser": "^4.5.0",
35
- "tslib": "^2.3.0"
36
- },
37
30
  "exports": {
38
31
  "./docs.json": {
39
32
  "default": "./docs.json"
@@ -68,5 +61,8 @@
68
61
  },
69
62
  "module": "fesm2022/siemens-element-translate-ng.mjs",
70
63
  "typings": "index.d.ts",
71
- "sideEffects": false
64
+ "sideEffects": false,
65
+ "dependencies": {
66
+ "tslib": "^2.3.0"
67
+ }
72
68
  }
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /* eslint-disable prefer-arrow/prefer-arrow-functions */
4
- import { spawn } from 'child_process';
5
- import * as fs from 'fs';
6
- import { dirname } from 'path';
7
-
8
- import { XMLParser } from 'fast-xml-parser';
9
-
10
- const configFile = process.argv[2] || './element-translate.conf.json';
11
- const toolConfig = JSON.parse(fs.readFileSync(configFile));
12
-
13
- console.log('Running localize-extract');
14
- const args = ['-s', toolConfig.files, '-f', 'xlf2', '-o', 'messages.xlf'];
15
- const extract = spawn('localize-extract', args, {
16
- stdio: ['ignore', 'ignore', 'inherit'],
17
- shell: true
18
- });
19
- extract.on('error', error => console.log(`error: ${error.message}`));
20
-
21
- extract.on('close', () => {
22
- processMessages();
23
- generateFiles();
24
- fs.rmSync('messages.xlf');
25
- });
26
-
27
- function prepareConfigs() {
28
- for (const config of toolConfig.configs) {
29
- config.keys = new Set();
30
- config.translations = {};
31
- }
32
- }
33
-
34
- function getConfigs(notes) {
35
- if (!Array.isArray(notes)) {
36
- notes = [notes];
37
- }
38
- const configs = [];
39
- for (const note of notes) {
40
- if (note['@_category'] !== 'location') {
41
- continue;
42
- }
43
- const location = note['#text'];
44
-
45
- for (const config of toolConfig.configs) {
46
- if (location?.startsWith(config.locationPrefix)) {
47
- configs.push(config);
48
- }
49
- }
50
- }
51
- return configs;
52
- }
53
-
54
- function processMessages() {
55
- console.log('Completed running localize-extract');
56
- console.log('Generating translation keys');
57
-
58
- const parser = new XMLParser({ ignoreAttributes: false });
59
- const messages = parser.parse(fs.readFileSync('./messages.xlf').toString('utf-8'));
60
-
61
- prepareConfigs();
62
-
63
- for (const unit of messages.xliff.file.unit) {
64
- const key = unit['@_id'];
65
- const value = unit.segment.source.toString(); // can be number
66
-
67
- // ignore some bogus output
68
- if (key.match(/^\d+$/)) {
69
- continue;
70
- }
71
-
72
- const configs = getConfigs(unit.notes.note);
73
- for (const config of configs) {
74
- config.keys.add(key);
75
- config.translations[key] = value;
76
- }
77
- }
78
- }
79
-
80
- function generateFiles() {
81
- for (const config of toolConfig.configs) {
82
- // only update if there are keys found, i.e. don't overwrite when not all libs are build
83
- if (!config.keys.size) {
84
- console.log(`Skipping ${config.name} since no keys found`);
85
- continue;
86
- }
87
-
88
- const keys = Array.from(config.keys);
89
- keys.sort();
90
-
91
- // for objects, keys are iterated in order they're added, so...
92
- const tmp = config.translations;
93
- config.translations = {};
94
- for (const key of keys) {
95
- config.translations[key] = tmp[key];
96
- }
97
-
98
- const interfaceLine = keys.map(key => ` '${key}'?: string;`);
99
- const interfaceFull = `/* eslint-disable */
100
-
101
- // Auto-generated file. Run 'yarn update-translatable-keys' to update.
102
-
103
- export interface ${config.keysInterfaceName} {
104
- ${interfaceLine.join('\n')}
105
- }
106
- `;
107
-
108
- fs.mkdirSync(dirname(config.keysFile), { recursive: true });
109
- fs.writeFileSync(config.keysFile, interfaceFull);
110
-
111
- fs.mkdirSync(dirname(config.messagesFile), { recursive: true });
112
- fs.writeFileSync(config.messagesFile, JSON.stringify(config.translations, null, 2));
113
-
114
- console.log(`Completed generating code for ${config.name}:`);
115
- console.log(` - ${config.keysFile}`);
116
- console.log(` - ${config.messagesFile}`);
117
- }
118
-
119
- console.log('Completed generating translation keys');
120
- }