@sap-ux/adp-tooling 0.18.92 → 0.18.93
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.
|
@@ -18,6 +18,7 @@ const node_fs_1 = require("node:fs");
|
|
|
18
18
|
const project_access_1 = require("@sap-ux/project-access");
|
|
19
19
|
const types_1 = require("../types");
|
|
20
20
|
const ejs_1 = require("ejs");
|
|
21
|
+
const key_user_translations_1 = require("../writer/i18n/key-user-translations");
|
|
21
22
|
/**
|
|
22
23
|
* Writes annotation changes to the specified project path using the provided `mem-fs-editor` instance.
|
|
23
24
|
*
|
|
@@ -83,6 +84,14 @@ async function writeKeyUserChanges(projectPath, config, fs) {
|
|
|
83
84
|
if (!change['fileName']) {
|
|
84
85
|
continue;
|
|
85
86
|
}
|
|
87
|
+
const fileName = change['fileName'];
|
|
88
|
+
const contentTexts = change['texts'];
|
|
89
|
+
const topLevelTexts = entry.texts;
|
|
90
|
+
// Replace content.texts values with i18n bindings and write translations to .properties files
|
|
91
|
+
if (contentTexts && topLevelTexts && Object.keys(topLevelTexts).length > 0) {
|
|
92
|
+
change['texts'] = (0, key_user_translations_1.replaceTextsWithI18nBindings)(contentTexts, fileName);
|
|
93
|
+
await (0, key_user_translations_1.writeKeyUserTranslations)(projectPath, fileName, topLevelTexts, fs);
|
|
94
|
+
}
|
|
86
95
|
const transformedChange = transformKeyUserChangeForAdp(change, config.app.id, config.app.layer);
|
|
87
96
|
await writeChangeToFolder(projectPath, transformedChange, fs);
|
|
88
97
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { KeyUserTextTranslations } from '@sap-ux/axios-extension';
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a backend language key to the locale suffix used in i18n .properties file names.
|
|
5
|
+
*
|
|
6
|
+
* The backend (LRep) already normalizes language keys to ISO 639 via T002/T002X lookup,
|
|
7
|
+
* so this function primarily converts BCP47 separators (`-`) to underscores (`_`) for
|
|
8
|
+
* .properties file naming and applies old-to-new ISO 639 mapping as a safety net.
|
|
9
|
+
*
|
|
10
|
+
* @param lang - Language key from the backend response (e.g., '', 'en', 'iw', 'pt-BR', 'zh-Hans').
|
|
11
|
+
* @returns The normalized locale suffix for .properties file naming (e.g., '', 'en', 'he', 'pt_BR', 'zh_Hans').
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeLanguageForI18n(lang: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces the `value` property of each entry in `content.texts` with an i18n binding expression.
|
|
16
|
+
* The generated key follows the pattern `<fileName>_<textId>`.
|
|
17
|
+
*
|
|
18
|
+
* @param contentTexts - The `texts` object from inside the change content.
|
|
19
|
+
* @param fileName - The file name of the change, used as key prefix.
|
|
20
|
+
* @returns The modified texts object with i18n bindings replacing values.
|
|
21
|
+
*/
|
|
22
|
+
export declare function replaceTextsWithI18nBindings(contentTexts: Record<string, Record<string, unknown>>, fileName: string): Record<string, Record<string, unknown>>;
|
|
23
|
+
/**
|
|
24
|
+
* Writes translations from the top-level `texts` object of a key-user change
|
|
25
|
+
* into the project's i18n .properties files.
|
|
26
|
+
*
|
|
27
|
+
* @param projectPath - The root path of the project.
|
|
28
|
+
* @param fileName - The file name of the change, used as key prefix.
|
|
29
|
+
* @param topLevelTexts - The top-level `texts` object from the API response entry.
|
|
30
|
+
* @param fs - The `mem-fs-editor` instance used for file operations.
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeKeyUserTranslations(projectPath: string, fileName: string, topLevelTexts: KeyUserTextTranslations, fs: Editor): Promise<void>;
|
|
33
|
+
//# sourceMappingURL=key-user-translations.d.ts.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeLanguageForI18n = normalizeLanguageForI18n;
|
|
4
|
+
exports.replaceTextsWithI18nBindings = replaceTextsWithI18nBindings;
|
|
5
|
+
exports.writeKeyUserTranslations = writeKeyUserTranslations;
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
8
|
+
const i18n_1 = require("@sap-ux/i18n");
|
|
9
|
+
/**
|
|
10
|
+
* Old-to-new ISO 639 language code mappings. Safety net for legacy systems that may still return deprecated codes.
|
|
11
|
+
* Source: sap/base/i18n/Localization.js M_ISO639_OLD_TO_NEW
|
|
12
|
+
*/
|
|
13
|
+
const M_ISO639_OLD_TO_NEW = {
|
|
14
|
+
'iw': 'he',
|
|
15
|
+
'ji': 'yi'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes a backend language key to the locale suffix used in i18n .properties file names.
|
|
19
|
+
*
|
|
20
|
+
* The backend (LRep) already normalizes language keys to ISO 639 via T002/T002X lookup,
|
|
21
|
+
* so this function primarily converts BCP47 separators (`-`) to underscores (`_`) for
|
|
22
|
+
* .properties file naming and applies old-to-new ISO 639 mapping as a safety net.
|
|
23
|
+
*
|
|
24
|
+
* @param lang - Language key from the backend response (e.g., '', 'en', 'iw', 'pt-BR', 'zh-Hans').
|
|
25
|
+
* @returns The normalized locale suffix for .properties file naming (e.g., '', 'en', 'he', 'pt_BR', 'zh_Hans').
|
|
26
|
+
*/
|
|
27
|
+
function normalizeLanguageForI18n(lang) {
|
|
28
|
+
if (!lang) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
// Parse BCP47 tag: language[-Script][-Region][-variant][-extension][-privateuse]
|
|
32
|
+
const parts = lang.split(/[-_]/);
|
|
33
|
+
let language = parts[0].toLowerCase();
|
|
34
|
+
// Apply old-to-new ISO 639 mapping as safety net
|
|
35
|
+
language = M_ISO639_OLD_TO_NEW[language] ?? language;
|
|
36
|
+
// Collect script and region subtags, skip variants/extensions/private use
|
|
37
|
+
const subtags = [];
|
|
38
|
+
for (const part of parts.slice(1)) {
|
|
39
|
+
if (/^[A-Za-z]{4}$/.test(part)) {
|
|
40
|
+
// Script subtag (e.g., Hans, Hant, Latn)
|
|
41
|
+
subtags.push(part[0].toUpperCase() + part.slice(1).toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
else if (/^[A-Za-z]{2}$/.test(part)) {
|
|
44
|
+
// Region subtag (e.g., GB, TW, BR)
|
|
45
|
+
subtags.push(part.toUpperCase());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return subtags.length ? `${language}_${subtags.join('_')}` : language;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Replaces the `value` property of each entry in `content.texts` with an i18n binding expression.
|
|
52
|
+
* The generated key follows the pattern `<fileName>_<textId>`.
|
|
53
|
+
*
|
|
54
|
+
* @param contentTexts - The `texts` object from inside the change content.
|
|
55
|
+
* @param fileName - The file name of the change, used as key prefix.
|
|
56
|
+
* @returns The modified texts object with i18n bindings replacing values.
|
|
57
|
+
*/
|
|
58
|
+
function replaceTextsWithI18nBindings(contentTexts, fileName) {
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const textId of Object.keys(contentTexts)) {
|
|
61
|
+
const entry = { ...contentTexts[textId] };
|
|
62
|
+
const generatedKey = `${fileName}_${textId}`;
|
|
63
|
+
entry.value = `{i18n>${generatedKey}}`;
|
|
64
|
+
result[textId] = entry;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Writes translations from the top-level `texts` object of a key-user change
|
|
70
|
+
* into the project's i18n .properties files.
|
|
71
|
+
*
|
|
72
|
+
* @param projectPath - The root path of the project.
|
|
73
|
+
* @param fileName - The file name of the change, used as key prefix.
|
|
74
|
+
* @param topLevelTexts - The top-level `texts` object from the API response entry.
|
|
75
|
+
* @param fs - The `mem-fs-editor` instance used for file operations.
|
|
76
|
+
*/
|
|
77
|
+
async function writeKeyUserTranslations(projectPath, fileName, topLevelTexts, fs) {
|
|
78
|
+
const webappPath = await (0, project_access_1.getWebappPath)(projectPath, fs);
|
|
79
|
+
const entriesByLanguage = {};
|
|
80
|
+
for (const textId of Object.keys(topLevelTexts)) {
|
|
81
|
+
const textEntry = topLevelTexts[textId];
|
|
82
|
+
const textType = textEntry.type;
|
|
83
|
+
const values = textEntry.values;
|
|
84
|
+
if (!values) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const generatedKey = `${fileName}_${textId}`;
|
|
88
|
+
for (const lang of Object.keys(values)) {
|
|
89
|
+
const normalizedLang = normalizeLanguageForI18n(lang);
|
|
90
|
+
if (!entriesByLanguage[normalizedLang]) {
|
|
91
|
+
entriesByLanguage[normalizedLang] = [];
|
|
92
|
+
}
|
|
93
|
+
const entry = {
|
|
94
|
+
key: generatedKey,
|
|
95
|
+
value: values[lang]
|
|
96
|
+
};
|
|
97
|
+
if (textType) {
|
|
98
|
+
entry.annotation = { textType };
|
|
99
|
+
}
|
|
100
|
+
entriesByLanguage[normalizedLang].push(entry);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const lang of Object.keys(entriesByLanguage)) {
|
|
104
|
+
const propertiesFileName = lang ? `i18n_${lang}.properties` : 'i18n.properties';
|
|
105
|
+
const i18nFilePath = (0, node_path_1.join)(webappPath, 'i18n', propertiesFileName);
|
|
106
|
+
await (0, i18n_1.createPropertiesI18nEntries)(i18nFilePath, entriesByLanguage[lang], undefined, fs);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=key-user-translations.js.map
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aadp-tooling"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.18.
|
|
12
|
+
"version": "0.18.93",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prompts": "2.4.2",
|
|
37
37
|
"sanitize-filename": "1.6.3",
|
|
38
38
|
"uuid": "11.1.0",
|
|
39
|
-
"@sap-ux/axios-extension": "1.25.
|
|
39
|
+
"@sap-ux/axios-extension": "1.25.24",
|
|
40
40
|
"@sap-ux/btp-utils": "1.1.10",
|
|
41
41
|
"@sap-ux/i18n": "0.3.9",
|
|
42
42
|
"@sap-ux/inquirer-common": "0.11.24",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@sap-ux/project-access": "1.35.13",
|
|
47
47
|
"@sap-ux/project-input-validator": "0.6.68",
|
|
48
48
|
"@sap-ux/store": "1.5.10",
|
|
49
|
-
"@sap-ux/system-access": "0.6.
|
|
49
|
+
"@sap-ux/system-access": "0.6.66",
|
|
50
50
|
"@sap-ux/ui5-config": "0.29.21",
|
|
51
51
|
"@sap-ux/ui5-info": "0.13.15"
|
|
52
52
|
},
|