@translated/lara-cli 0.2.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/README.md +212 -0
- package/build/cli/cmd/glossary/glossary.js +55 -0
- package/build/cli/cmd/glossary/glossary.js.map +1 -0
- package/build/cli/cmd/init/init.input.js +177 -0
- package/build/cli/cmd/init/init.input.js.map +1 -0
- package/build/cli/cmd/init/init.js +158 -0
- package/build/cli/cmd/init/init.js.map +1 -0
- package/build/cli/cmd/init/init.types.js +2 -0
- package/build/cli/cmd/init/init.types.js.map +1 -0
- package/build/cli/cmd/init/init.utils.js +99 -0
- package/build/cli/cmd/init/init.utils.js.map +1 -0
- package/build/cli/cmd/memory/memory.js +55 -0
- package/build/cli/cmd/memory/memory.js.map +1 -0
- package/build/cli/cmd/translate/translate.js +149 -0
- package/build/cli/cmd/translate/translate.js.map +1 -0
- package/build/index.js +25 -0
- package/build/index.js.map +1 -0
- package/build/interface/parser.js +2 -0
- package/build/interface/parser.js.map +1 -0
- package/build/messages/messages.js +120 -0
- package/build/messages/messages.js.map +1 -0
- package/build/modules/common/common.const.js +424 -0
- package/build/modules/common/common.const.js.map +1 -0
- package/build/modules/common/common.types.js +15 -0
- package/build/modules/common/common.types.js.map +1 -0
- package/build/modules/config/config.provider.js +47 -0
- package/build/modules/config/config.provider.js.map +1 -0
- package/build/modules/config/config.types.js +95 -0
- package/build/modules/config/config.types.js.map +1 -0
- package/build/modules/translation/translation.engine.js +165 -0
- package/build/modules/translation/translation.engine.js.map +1 -0
- package/build/modules/translation/translation.service.js +45 -0
- package/build/modules/translation/translation.service.js.map +1 -0
- package/build/parsers/android-xml.parser.js +308 -0
- package/build/parsers/android-xml.parser.js.map +1 -0
- package/build/parsers/json.parser.js +18 -0
- package/build/parsers/json.parser.js.map +1 -0
- package/build/parsers/markdown.parser.js +74 -0
- package/build/parsers/markdown.parser.js.map +1 -0
- package/build/parsers/parser.factory.js +52 -0
- package/build/parsers/parser.factory.js.map +1 -0
- package/build/parsers/parser.types.js +2 -0
- package/build/parsers/parser.types.js.map +1 -0
- package/build/parsers/po.parser.js +175 -0
- package/build/parsers/po.parser.js.map +1 -0
- package/build/parsers/ts.parser.js +176 -0
- package/build/parsers/ts.parser.js.map +1 -0
- package/build/parsers/vue.parser.js +156 -0
- package/build/parsers/vue.parser.js.map +1 -0
- package/build/utils/checksum.js +80 -0
- package/build/utils/checksum.js.map +1 -0
- package/build/utils/cli.js +4 -0
- package/build/utils/cli.js.map +1 -0
- package/build/utils/display.js +60 -0
- package/build/utils/display.js.map +1 -0
- package/build/utils/error.js +18 -0
- package/build/utils/error.js.map +1 -0
- package/build/utils/locale.js +108 -0
- package/build/utils/locale.js.map +1 -0
- package/build/utils/parser.js +25 -0
- package/build/utils/parser.js.map +1 -0
- package/build/utils/path.js +173 -0
- package/build/utils/path.js.map +1 -0
- package/build/utils/progressWithOra.js +72 -0
- package/build/utils/progressWithOra.js.map +1 -0
- package/build/utils/prompt.js +205 -0
- package/build/utils/prompt.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import picomatch from 'picomatch';
|
|
2
|
+
import { TranslationService } from './translation.service.js';
|
|
3
|
+
import { calculateChecksum } from '#utils/checksum.js';
|
|
4
|
+
import { buildLocalePath, ensureDirectoryExists, readSafe } from '#utils/path.js';
|
|
5
|
+
import { writeFile } from 'fs/promises';
|
|
6
|
+
import { progressWithOra } from '#utils/progressWithOra.js';
|
|
7
|
+
import { Messages } from '#messages/messages.js';
|
|
8
|
+
import { ParserFactory } from '../../parsers/parser.factory.js';
|
|
9
|
+
function detectFormatting(jsonContent) {
|
|
10
|
+
const lines = jsonContent.split('\n');
|
|
11
|
+
let indentation = 2;
|
|
12
|
+
for (const line of lines) {
|
|
13
|
+
const match = line.match(/^(\s+)\S/);
|
|
14
|
+
if (match && match[1]) {
|
|
15
|
+
const indent = match[1];
|
|
16
|
+
if (indent.includes('\t')) {
|
|
17
|
+
indentation = '\t';
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (indent.match(/^ +$/)) {
|
|
21
|
+
indentation = indent.length;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const trailingNewline = jsonContent.endsWith('\n') ? '\n' : '';
|
|
27
|
+
return { indentation, trailingNewline };
|
|
28
|
+
}
|
|
29
|
+
export class TranslationEngine {
|
|
30
|
+
sourceLocale;
|
|
31
|
+
targetLocales;
|
|
32
|
+
inputPath;
|
|
33
|
+
forceTranslation;
|
|
34
|
+
lockedPatterns;
|
|
35
|
+
ignoredPatterns;
|
|
36
|
+
projectInstruction;
|
|
37
|
+
fileInstruction;
|
|
38
|
+
fileKeyInstructionPatterns;
|
|
39
|
+
globalKeyInstructionPatterns;
|
|
40
|
+
translationMemoryIds;
|
|
41
|
+
glossaryIds;
|
|
42
|
+
translatorService;
|
|
43
|
+
parser;
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.sourceLocale = options.sourceLocale;
|
|
46
|
+
this.targetLocales = options.targetLocales;
|
|
47
|
+
this.inputPath = options.inputPath;
|
|
48
|
+
this.forceTranslation = options.forceTranslation;
|
|
49
|
+
this.lockedPatterns = options.lockedKeys.map((pattern) => picomatch(pattern));
|
|
50
|
+
this.ignoredPatterns = options.ignoredKeys.map((pattern) => picomatch(pattern));
|
|
51
|
+
this.projectInstruction = options.projectInstruction;
|
|
52
|
+
this.fileInstruction = options.fileInstruction;
|
|
53
|
+
this.fileKeyInstructionPatterns = options.fileKeyInstructions.map(({ path, instruction }) => ({
|
|
54
|
+
matcher: picomatch(path),
|
|
55
|
+
instruction,
|
|
56
|
+
}));
|
|
57
|
+
this.globalKeyInstructionPatterns = options.globalKeyInstructions.map(({ path, instruction }) => ({
|
|
58
|
+
matcher: picomatch(path),
|
|
59
|
+
instruction,
|
|
60
|
+
}));
|
|
61
|
+
this.translationMemoryIds = options.translationMemoryIds;
|
|
62
|
+
this.glossaryIds = options.glossaryIds;
|
|
63
|
+
this.translatorService = TranslationService.getInstance();
|
|
64
|
+
this.parser = new ParserFactory(this.inputPath);
|
|
65
|
+
}
|
|
66
|
+
async translate() {
|
|
67
|
+
await this.handleInputPath(this.inputPath);
|
|
68
|
+
}
|
|
69
|
+
async handleInputPath(inputPath) {
|
|
70
|
+
const sourcePath = buildLocalePath(inputPath, this.sourceLocale);
|
|
71
|
+
const changelog = calculateChecksum(sourcePath, this.parser, this.sourceLocale);
|
|
72
|
+
const keysCount = Object.keys(changelog).length;
|
|
73
|
+
const sourceContent = await readSafe(sourcePath, '');
|
|
74
|
+
for (const targetLocale of this.targetLocales) {
|
|
75
|
+
progressWithOra.setText(Messages.info.translatingFileProgress(inputPath, targetLocale, keysCount));
|
|
76
|
+
const targetPath = buildLocalePath(inputPath, targetLocale);
|
|
77
|
+
const fallback = this.parser.getFallback();
|
|
78
|
+
const targetContent = await readSafe(targetPath, fallback);
|
|
79
|
+
const isTargetEmpty = targetContent === fallback || targetContent.trim() === '';
|
|
80
|
+
const contentForStructure = isTargetEmpty ? sourceContent : targetContent;
|
|
81
|
+
const formatting = detectFormatting(contentForStructure);
|
|
82
|
+
const target = this.parser.parse(targetContent, { targetLocale });
|
|
83
|
+
const entries = (await Promise.all(Object.entries(changelog)
|
|
84
|
+
.filter(([key]) => !this.isIgnored(key))
|
|
85
|
+
.map(async ([key, value]) => {
|
|
86
|
+
const state = value.state;
|
|
87
|
+
const sourceValue = value.value;
|
|
88
|
+
const targetValue = target[key];
|
|
89
|
+
if (this.isLocked(key)) {
|
|
90
|
+
return [key, sourceValue];
|
|
91
|
+
}
|
|
92
|
+
if (!targetValue || this.forceTranslation) {
|
|
93
|
+
const translatedValue = await this.translateKey(key, sourceValue, this.sourceLocale, targetLocale);
|
|
94
|
+
return [key, translatedValue];
|
|
95
|
+
}
|
|
96
|
+
if (state === 'unchanged') {
|
|
97
|
+
return [key, targetValue];
|
|
98
|
+
}
|
|
99
|
+
if (state === 'new' && targetValue) {
|
|
100
|
+
return [key, targetValue];
|
|
101
|
+
}
|
|
102
|
+
if (typeof sourceValue !== 'string') {
|
|
103
|
+
return [key, sourceValue];
|
|
104
|
+
}
|
|
105
|
+
const translatedValue = await this.translateKey(key, sourceValue, this.sourceLocale, targetLocale);
|
|
106
|
+
return [key, translatedValue];
|
|
107
|
+
}))).filter((entry) => entry !== null);
|
|
108
|
+
const newContent = Object.fromEntries(entries);
|
|
109
|
+
await ensureDirectoryExists(targetPath);
|
|
110
|
+
await writeFile(targetPath, this.parser.serialize(newContent, {
|
|
111
|
+
...formatting,
|
|
112
|
+
targetLocale,
|
|
113
|
+
originalContent: sourcePath === targetPath ? targetContent : sourceContent,
|
|
114
|
+
}));
|
|
115
|
+
progressWithOra.tick(1);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async translateKey(key, value, sourceLocale, targetLocale) {
|
|
119
|
+
if (typeof value !== 'string') {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
if (value.trim() === '') {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
const textBlocks = [{ text: value, translatable: true }];
|
|
126
|
+
const instruction = this.getInstructionForKey(key);
|
|
127
|
+
const options = {
|
|
128
|
+
instructions: instruction ? [instruction] : undefined,
|
|
129
|
+
adaptTo: this.translationMemoryIds.length > 0 ? this.translationMemoryIds : [],
|
|
130
|
+
glossaries: this.glossaryIds.length > 0 ? this.glossaryIds : undefined,
|
|
131
|
+
};
|
|
132
|
+
const translations = await this.translatorService.translate(textBlocks, sourceLocale, targetLocale, options);
|
|
133
|
+
const lastTranslation = translations.pop();
|
|
134
|
+
if (!lastTranslation) {
|
|
135
|
+
throw new Error(Messages.errors.emptyTranslationResult(value));
|
|
136
|
+
}
|
|
137
|
+
return lastTranslation.text;
|
|
138
|
+
}
|
|
139
|
+
isIgnored(key) {
|
|
140
|
+
return this.ignoredPatterns.some((pattern) => pattern(key));
|
|
141
|
+
}
|
|
142
|
+
isLocked(key) {
|
|
143
|
+
return this.lockedPatterns.some((pattern) => pattern(key));
|
|
144
|
+
}
|
|
145
|
+
getInstructionForKey(key) {
|
|
146
|
+
for (const { matcher, instruction } of this.fileKeyInstructionPatterns) {
|
|
147
|
+
if (matcher(key)) {
|
|
148
|
+
return instruction;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const { matcher, instruction } of this.globalKeyInstructionPatterns) {
|
|
152
|
+
if (matcher(key)) {
|
|
153
|
+
return instruction;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (this.fileInstruction) {
|
|
157
|
+
return this.fileInstruction;
|
|
158
|
+
}
|
|
159
|
+
if (this.projectInstruction) {
|
|
160
|
+
return this.projectInstruction;
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=translation.engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation.engine.js","sourceRoot":"/","sources":["modules/translation/translation.engine.ts"],"names":[],"mappings":"AAAA,OAAO,SAAsB,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AA6BhE,SAAS,gBAAgB,CAAC,WAAmB;IAI3C,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,WAAW,GAAoB,CAAC,CAAC;IAGrC,K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AS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Credentials, Translator } from '@translated/lara';
|
|
2
|
+
import { Messages } from '#messages/messages.js';
|
|
3
|
+
export class TranslationService {
|
|
4
|
+
static instance;
|
|
5
|
+
client;
|
|
6
|
+
constructor() {
|
|
7
|
+
const keyId = process.env.LARA_ACCESS_KEY_ID;
|
|
8
|
+
const keySecret = process.env.LARA_ACCESS_KEY_SECRET;
|
|
9
|
+
if (!keyId || !keySecret) {
|
|
10
|
+
throw new Error(Messages.errors.envVarsNotSet);
|
|
11
|
+
}
|
|
12
|
+
this.client = new Translator(new Credentials(keyId, keySecret));
|
|
13
|
+
}
|
|
14
|
+
static getInstance() {
|
|
15
|
+
if (!TranslationService.instance) {
|
|
16
|
+
TranslationService.instance = new TranslationService();
|
|
17
|
+
}
|
|
18
|
+
return TranslationService.instance;
|
|
19
|
+
}
|
|
20
|
+
async translate(textBlocks, sourceLocale, targetLocale, options) {
|
|
21
|
+
const maxRetries = 5;
|
|
22
|
+
let attempt = 0;
|
|
23
|
+
while (attempt < maxRetries) {
|
|
24
|
+
try {
|
|
25
|
+
const response = await this.client.translate(textBlocks, sourceLocale, targetLocale, options);
|
|
26
|
+
return response.translation;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
attempt++;
|
|
30
|
+
if (attempt >= maxRetries) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw new Error(Messages.errors.maxRetriesExceeded);
|
|
37
|
+
}
|
|
38
|
+
async getTranslationMemories() {
|
|
39
|
+
return this.client.memories.list();
|
|
40
|
+
}
|
|
41
|
+
async getGlossaries() {
|
|
42
|
+
return this.client.glossaries.list();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=translation.service.js.map
|
|
@@ -0,0 +1 @@
|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YAC9B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,EAAE,CAAC;gBAEV,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;oBAC1B,MAAM,KAAK,CAAC;gBACd,CAAC;gBAGD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;QAGD,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,sBAAsB;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,aAAa;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
2
|
+
export class AndroidXmlParser {
|
|
3
|
+
fallbackContent = '<?xml version="1.0" encoding="utf-8"?>\n<resources>\n</resources>';
|
|
4
|
+
parser;
|
|
5
|
+
orderMap = new Map();
|
|
6
|
+
constructor() {
|
|
7
|
+
this.parser = new XMLParser({
|
|
8
|
+
ignoreAttributes: false,
|
|
9
|
+
attributeNamePrefix: '@_',
|
|
10
|
+
textNodeName: '#text',
|
|
11
|
+
preserveOrder: false,
|
|
12
|
+
parseAttributeValue: false,
|
|
13
|
+
trimValues: false,
|
|
14
|
+
isArray: (name) => {
|
|
15
|
+
return name === 'item';
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
isAndroidXmlParsed(value) {
|
|
20
|
+
return (typeof value === 'object' &&
|
|
21
|
+
value !== null &&
|
|
22
|
+
(!('resources' in value) || typeof value.resources === 'object'));
|
|
23
|
+
}
|
|
24
|
+
parse(content) {
|
|
25
|
+
const strContent = content.toString();
|
|
26
|
+
this.orderMap = this.buildOrderMap(strContent);
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = this.parser.parse(strContent);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('Failed to parse Android XML content', error);
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
if (!this.isAndroidXmlParsed(parsed) || !parsed.resources) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
const translations = {};
|
|
39
|
+
const resources = parsed.resources;
|
|
40
|
+
if (resources.string) {
|
|
41
|
+
const strings = Array.isArray(resources.string) ? resources.string : [resources.string];
|
|
42
|
+
for (const str of strings) {
|
|
43
|
+
const name = str['@_name'];
|
|
44
|
+
if (!name)
|
|
45
|
+
continue;
|
|
46
|
+
if (str['@_translatable'] === 'false')
|
|
47
|
+
continue;
|
|
48
|
+
const value = str['#text'] || '';
|
|
49
|
+
translations[name] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (resources.plurals) {
|
|
53
|
+
const plurals = Array.isArray(resources.plurals) ? resources.plurals : [resources.plurals];
|
|
54
|
+
for (const plural of plurals) {
|
|
55
|
+
const name = plural['@_name'];
|
|
56
|
+
if (!name)
|
|
57
|
+
continue;
|
|
58
|
+
const items = plural.item
|
|
59
|
+
? (Array.isArray(plural.item) ? plural.item : [plural.item])
|
|
60
|
+
: [];
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
const quantity = item['@_quantity'];
|
|
63
|
+
if (!quantity)
|
|
64
|
+
continue;
|
|
65
|
+
const value = item['#text'] || '';
|
|
66
|
+
const key = `${name}/${quantity}`;
|
|
67
|
+
translations[key] = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (resources['string-array']) {
|
|
72
|
+
const stringArrays = Array.isArray(resources['string-array'])
|
|
73
|
+
? resources['string-array']
|
|
74
|
+
: [resources['string-array']];
|
|
75
|
+
for (const stringArray of stringArrays) {
|
|
76
|
+
const name = stringArray['@_name'];
|
|
77
|
+
if (!name)
|
|
78
|
+
continue;
|
|
79
|
+
if (stringArray['@_translatable'] === 'false')
|
|
80
|
+
continue;
|
|
81
|
+
const items = stringArray.item
|
|
82
|
+
? (Array.isArray(stringArray.item) ? stringArray.item : [stringArray.item])
|
|
83
|
+
: [];
|
|
84
|
+
for (let i = 0; i < items.length; i++) {
|
|
85
|
+
const item = items[i];
|
|
86
|
+
if (item === undefined)
|
|
87
|
+
continue;
|
|
88
|
+
const value = typeof item === 'string' ? item : (item['#text'] || '');
|
|
89
|
+
const key = `${name}/${i}`;
|
|
90
|
+
translations[key] = value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return translations;
|
|
95
|
+
}
|
|
96
|
+
escapeTextContent(value) {
|
|
97
|
+
return value
|
|
98
|
+
.replace(/&/g, '&')
|
|
99
|
+
.replace(/</g, '<')
|
|
100
|
+
.replace(/>/g, '>')
|
|
101
|
+
.replace(/"/g, '"')
|
|
102
|
+
.replace(/'/g, ''');
|
|
103
|
+
}
|
|
104
|
+
buildOrderMap(content) {
|
|
105
|
+
const map = new Map();
|
|
106
|
+
let orderIndex = 0;
|
|
107
|
+
const resourceRegex = /<(string-array|plurals|string)\b[^>]*\bname=["']([^"']+)["'][^>]*>/g;
|
|
108
|
+
let match;
|
|
109
|
+
while ((match = resourceRegex.exec(content)) !== null) {
|
|
110
|
+
const tag = match[1];
|
|
111
|
+
const name = match[2];
|
|
112
|
+
if (name) {
|
|
113
|
+
const key = `${tag}:${name}`;
|
|
114
|
+
if (!map.has(key)) {
|
|
115
|
+
map.set(key, orderIndex++);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return map;
|
|
120
|
+
}
|
|
121
|
+
serialize(data, options) {
|
|
122
|
+
const { originalContent } = options;
|
|
123
|
+
if (!originalContent) {
|
|
124
|
+
throw new Error('Original content is required for Android XML serialization');
|
|
125
|
+
}
|
|
126
|
+
const strContent = originalContent.toString();
|
|
127
|
+
this.orderMap = this.buildOrderMap(strContent);
|
|
128
|
+
let parsed;
|
|
129
|
+
try {
|
|
130
|
+
parsed = this.parser.parse(strContent);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Failed to parse original Android XML content', error);
|
|
134
|
+
return strContent;
|
|
135
|
+
}
|
|
136
|
+
if (!this.isAndroidXmlParsed(parsed)) {
|
|
137
|
+
return strContent;
|
|
138
|
+
}
|
|
139
|
+
if (!parsed.resources) {
|
|
140
|
+
parsed.resources = {};
|
|
141
|
+
}
|
|
142
|
+
const resources = parsed.resources;
|
|
143
|
+
if (resources.string) {
|
|
144
|
+
const strings = Array.isArray(resources.string) ? resources.string : [resources.string];
|
|
145
|
+
for (const str of strings) {
|
|
146
|
+
const name = str['@_name'];
|
|
147
|
+
if (!name)
|
|
148
|
+
continue;
|
|
149
|
+
if (str['@_translatable'] === 'false')
|
|
150
|
+
continue;
|
|
151
|
+
if (data[name] !== undefined) {
|
|
152
|
+
str['#text'] = String(data[name] || '');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (resources.plurals) {
|
|
157
|
+
const plurals = Array.isArray(resources.plurals) ? resources.plurals : [resources.plurals];
|
|
158
|
+
for (const plural of plurals) {
|
|
159
|
+
const name = plural['@_name'];
|
|
160
|
+
if (!name || !plural.item)
|
|
161
|
+
continue;
|
|
162
|
+
const items = Array.isArray(plural.item) ? plural.item : [plural.item];
|
|
163
|
+
for (const item of items) {
|
|
164
|
+
const quantity = item['@_quantity'];
|
|
165
|
+
if (!quantity)
|
|
166
|
+
continue;
|
|
167
|
+
const key = `${name}/${quantity}`;
|
|
168
|
+
if (data[key] !== undefined) {
|
|
169
|
+
item['#text'] = String(data[key] || '');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (resources['string-array']) {
|
|
175
|
+
const stringArrays = Array.isArray(resources['string-array'])
|
|
176
|
+
? resources['string-array']
|
|
177
|
+
: [resources['string-array']];
|
|
178
|
+
for (const stringArray of stringArrays) {
|
|
179
|
+
const name = stringArray['@_name'];
|
|
180
|
+
if (!name)
|
|
181
|
+
continue;
|
|
182
|
+
if (stringArray['@_translatable'] === 'false')
|
|
183
|
+
continue;
|
|
184
|
+
const items = stringArray.item
|
|
185
|
+
? (Array.isArray(stringArray.item) ? stringArray.item : [stringArray.item])
|
|
186
|
+
: [];
|
|
187
|
+
for (let i = 0; i < items.length; i++) {
|
|
188
|
+
const item = items[i];
|
|
189
|
+
if (item === undefined)
|
|
190
|
+
continue;
|
|
191
|
+
const key = `${name}/${i}`;
|
|
192
|
+
if (data[key] !== undefined) {
|
|
193
|
+
if (typeof item === 'string') {
|
|
194
|
+
items[i] = { '#text': String(data[key] || '') };
|
|
195
|
+
}
|
|
196
|
+
else if (item && typeof item === 'object') {
|
|
197
|
+
item['#text'] = String(data[key] || '');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (items.length > 0) {
|
|
202
|
+
stringArray.item = items.length === 1 ? items[0] : items;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const resourceEntries = [];
|
|
207
|
+
if (resources.string) {
|
|
208
|
+
const strings = Array.isArray(resources.string) ? resources.string : [resources.string];
|
|
209
|
+
for (const str of strings) {
|
|
210
|
+
const name = str['@_name'];
|
|
211
|
+
if (name) {
|
|
212
|
+
const order = this.orderMap.get(`string:${name}`) ?? Number.MAX_SAFE_INTEGER;
|
|
213
|
+
resourceEntries.push({ type: 'string', resource: str, order });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (resources.plurals) {
|
|
218
|
+
const plurals = Array.isArray(resources.plurals) ? resources.plurals : [resources.plurals];
|
|
219
|
+
for (const plural of plurals) {
|
|
220
|
+
const name = plural['@_name'];
|
|
221
|
+
if (name) {
|
|
222
|
+
const order = this.orderMap.get(`plurals:${name}`) ?? Number.MAX_SAFE_INTEGER;
|
|
223
|
+
resourceEntries.push({ type: 'plurals', resource: plural, order });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (resources['string-array']) {
|
|
228
|
+
const stringArrays = Array.isArray(resources['string-array'])
|
|
229
|
+
? resources['string-array']
|
|
230
|
+
: [resources['string-array']];
|
|
231
|
+
for (const stringArray of stringArrays) {
|
|
232
|
+
const name = stringArray['@_name'];
|
|
233
|
+
if (name) {
|
|
234
|
+
const order = this.orderMap.get(`string-array:${name}`) ?? Number.MAX_SAFE_INTEGER;
|
|
235
|
+
resourceEntries.push({ type: 'string-array', resource: stringArray, order });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
resourceEntries.sort((a, b) => a.order - b.order);
|
|
240
|
+
const indent = ' ';
|
|
241
|
+
const lines = ['<resources>'];
|
|
242
|
+
for (const entry of resourceEntries) {
|
|
243
|
+
if (entry.type === 'string') {
|
|
244
|
+
const str = entry.resource;
|
|
245
|
+
const name = str['@_name'];
|
|
246
|
+
const translatable = str['@_translatable'];
|
|
247
|
+
const value = str['#text'] || '';
|
|
248
|
+
const escapedName = this.escapeTextContent(String(name));
|
|
249
|
+
const escapedValue = this.escapeTextContent(value);
|
|
250
|
+
let attrs = `name="${escapedName}"`;
|
|
251
|
+
if (translatable === 'false') {
|
|
252
|
+
attrs += ` translatable="false"`;
|
|
253
|
+
}
|
|
254
|
+
lines.push(`${indent}<string ${attrs}>${escapedValue}</string>`);
|
|
255
|
+
}
|
|
256
|
+
else if (entry.type === 'plurals') {
|
|
257
|
+
const plural = entry.resource;
|
|
258
|
+
const name = plural['@_name'];
|
|
259
|
+
const items = plural.item
|
|
260
|
+
? (Array.isArray(plural.item) ? plural.item : [plural.item])
|
|
261
|
+
: [];
|
|
262
|
+
const escapedName = this.escapeTextContent(String(name));
|
|
263
|
+
lines.push(`${indent}<plurals name="${escapedName}">`);
|
|
264
|
+
for (const item of items) {
|
|
265
|
+
const quantity = item['@_quantity'];
|
|
266
|
+
if (!quantity)
|
|
267
|
+
continue;
|
|
268
|
+
const value = item['#text'] || '';
|
|
269
|
+
const escapedQuantity = this.escapeTextContent(String(quantity));
|
|
270
|
+
const escapedValue = this.escapeTextContent(value);
|
|
271
|
+
lines.push(`${indent}${indent}<item quantity="${escapedQuantity}">${escapedValue}</item>`);
|
|
272
|
+
}
|
|
273
|
+
lines.push(`${indent}</plurals>`);
|
|
274
|
+
}
|
|
275
|
+
else if (entry.type === 'string-array') {
|
|
276
|
+
const stringArray = entry.resource;
|
|
277
|
+
const name = stringArray['@_name'];
|
|
278
|
+
const translatable = stringArray['@_translatable'];
|
|
279
|
+
const items = stringArray.item
|
|
280
|
+
? (Array.isArray(stringArray.item) ? stringArray.item : [stringArray.item])
|
|
281
|
+
: [];
|
|
282
|
+
const escapedName = this.escapeTextContent(String(name));
|
|
283
|
+
let attrs = `name="${escapedName}"`;
|
|
284
|
+
if (translatable === 'false') {
|
|
285
|
+
attrs += ` translatable="false"`;
|
|
286
|
+
}
|
|
287
|
+
lines.push(`${indent}<string-array ${attrs}>`);
|
|
288
|
+
for (const item of items) {
|
|
289
|
+
const value = typeof item === 'string' ? item : (item['#text'] || '');
|
|
290
|
+
const escapedValue = this.escapeTextContent(value);
|
|
291
|
+
lines.push(`${indent}${indent}<item>${escapedValue}</item>`);
|
|
292
|
+
}
|
|
293
|
+
lines.push(`${indent}</string-array>`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
lines.push('</resources>');
|
|
297
|
+
const xml = lines.join('\n');
|
|
298
|
+
const trimmedXml = xml.trimStart();
|
|
299
|
+
if (!trimmedXml.startsWith('<?xml')) {
|
|
300
|
+
return '<?xml version="1.0" encoding="utf-8"?>\n' + xml;
|
|
301
|
+
}
|
|
302
|
+
return xml;
|
|
303
|
+
}
|
|
304
|
+
getFallback() {
|
|
305
|
+
return this.fallbackContent;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=android-xml.parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"android-xml.parser.js","sourceRoot":"/","sources":["parsers/android-xml.parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAqF5C,MAAM,OAAO,gBAAgB;IACV,eAAe,GAAG,mEAAmE,CAAC;IACtF,MAAM,CAAY;IAC3B,QAAQ,GAAwB,IAAI,GAAG,EAAE,CAAC;IAElD;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC;YAC1B,gBAAgB,EAAE,KAAK;YACvB,mBAAmB,EAAE,IAAI;YACzB,YAAY,EAAE,OAAO;YACrB,aAAa,EAAE,KAAK;YACpB,mBAAmB,EAAE,KAAK;YAC1B,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChB,OAAO,IAAI,KAAK,MAAM,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAKO,kBAAkB,CAAC,KAAc;QACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACd,CAAC,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,OAAQ,KAA0B,CAAC,SAAS,KAAK,QAAQ,CAAC,CACvF,CAAC;IACJ,CAAC;IAYD,KAAK,CAAC,OAAwB;QAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAE/C,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OA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AC,eAAe,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { flatten as flat, unflatten as unflat } from 'flat';
|
|
2
|
+
export class JsonParser {
|
|
3
|
+
fallbackContent = '{}';
|
|
4
|
+
delimiter = '/';
|
|
5
|
+
parse(content) {
|
|
6
|
+
const parsed = JSON.parse(content);
|
|
7
|
+
return flat(parsed, { delimiter: this.delimiter });
|
|
8
|
+
}
|
|
9
|
+
serialize(data, options) {
|
|
10
|
+
const unflattened = unflat(data, { delimiter: this.delimiter });
|
|
11
|
+
const formatted = JSON.stringify(unflattened, null, options.indentation);
|
|
12
|
+
return formatted + options.trailingNewline;
|
|
13
|
+
}
|
|
14
|
+
getFallback() {
|
|
15
|
+
return this.fallbackContent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=json.parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.parser.js","sourceRoot":"/","sources":["parsers/json.parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAkB5D,MAAM,OAAO,UAAU;IACJ,eAAe,GAAW,IAAI,CAAC;IACxC,SAAS,GAAW,GAAG,CAAC;IAyBhC,KAAK,CAAC,OAAe;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IACrD,CAAC;IAyBD,SAAS,CAAC,IAA6B,EAAE,OAA8B;QACrE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAChE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,OAAO,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC;IAC7C,CAAC;IAKD,WAAW;QACT,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { remark } from 'remark';
|
|
2
|
+
import remarkGfm from 'remark-gfm';
|
|
3
|
+
import { visit, SKIP } from 'unist-util-visit';
|
|
4
|
+
export class MarkdownParser {
|
|
5
|
+
fallbackContent = '';
|
|
6
|
+
processor = remark().use(remarkGfm);
|
|
7
|
+
parse(content) {
|
|
8
|
+
const strContent = content.toString();
|
|
9
|
+
const tree = this.processor.parse(strContent);
|
|
10
|
+
const textSegments = this.extractTextSegments(tree);
|
|
11
|
+
const result = {};
|
|
12
|
+
for (let i = 0; i < textSegments.length; i++) {
|
|
13
|
+
const segment = textSegments[i];
|
|
14
|
+
if (segment) {
|
|
15
|
+
const key = `segment_${i}`;
|
|
16
|
+
result[key] = segment.node.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
serialize(data, options) {
|
|
22
|
+
const { originalContent } = options;
|
|
23
|
+
const strContent = originalContent.toString();
|
|
24
|
+
const tree = this.processor.parse(strContent);
|
|
25
|
+
this.updateTextNodes(tree, data);
|
|
26
|
+
return this.processor.stringify(tree);
|
|
27
|
+
}
|
|
28
|
+
getFallback() {
|
|
29
|
+
return this.fallbackContent;
|
|
30
|
+
}
|
|
31
|
+
extractTextSegments(tree) {
|
|
32
|
+
const segments = [];
|
|
33
|
+
visit(tree, (node) => {
|
|
34
|
+
if (node.type === 'code' ||
|
|
35
|
+
node.type === 'inlineCode' ||
|
|
36
|
+
node.type === 'html' ||
|
|
37
|
+
node.type === 'yaml') {
|
|
38
|
+
return SKIP;
|
|
39
|
+
}
|
|
40
|
+
if (node.type === 'text') {
|
|
41
|
+
const textNode = node;
|
|
42
|
+
if (textNode.value.trim().length > 0) {
|
|
43
|
+
segments.push({
|
|
44
|
+
node: textNode,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return segments;
|
|
50
|
+
}
|
|
51
|
+
updateTextNodes(tree, translatedData) {
|
|
52
|
+
let segmentIndex = 0;
|
|
53
|
+
visit(tree, (node) => {
|
|
54
|
+
if (node.type === 'code' ||
|
|
55
|
+
node.type === 'inlineCode' ||
|
|
56
|
+
node.type === 'html' ||
|
|
57
|
+
node.type === 'yaml') {
|
|
58
|
+
return SKIP;
|
|
59
|
+
}
|
|
60
|
+
if (node.type === 'text') {
|
|
61
|
+
const textNode = node;
|
|
62
|
+
if (textNode.value.trim().length > 0) {
|
|
63
|
+
const key = `segment_${segmentIndex}`;
|
|
64
|
+
const translatedText = translatedData[key];
|
|
65
|
+
if (translatedText && typeof translatedText === 'string') {
|
|
66
|
+
textNode.value = translatedText;
|
|
67
|
+
}
|
|
68
|
+
segmentIndex++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=markdown.parser.js.map
|