import fs from "fs"; import path from "path"; import { XMLParser } from "fast-xml-parser"; /** @typedef {{ LCX: { $_TgtCul: string; Item: { Item: { Item: { $_ItemId: string; Str: { Val: string; Tgt: { Val: string; }; }; }[]; }; }; } }} ParsedLCL */ void 0; async function main() { const args = process.argv.slice(2); if (args.length !== 3) { console.log("Usage:"); console.log("\tnode generateLocalizedDiagnosticMessages.js "); return; } const inputPath = args[0]; const outputPath = args[1]; const diagnosticsMapFilePath = args[2]; // generate the lcg file for enu await generateLCGFile(); // generate other langs const files = await fs.promises.readdir(inputPath); await Promise.all(files.map(visitDirectory)); return; /** * @param {string} name */ async function visitDirectory(name) { const inputFilePath = path.join(inputPath, name, "diagnosticMessages", "diagnosticMessages.generated.json.lcl"); const contents = await fs.promises.readFile(inputFilePath); /** @type {ParsedLCL} */ // eslint-disable-next-line local/object-literal-surrounding-space const result = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "$_"}).parse(contents); if (!result || !result.LCX || !result.LCX.$_TgtCul) { console.error("Unexpected XML file structure. Expected to find result.LCX.$_TgtCul."); process.exit(1); } const outputDirectoryName = getPreferredLocaleName(result.LCX.$_TgtCul).toLowerCase(); if (!outputDirectoryName) { console.error(`Invalid output locale name for '${result.LCX.$_TgtCul}'.`); process.exit(1); } await writeFile(path.join(outputPath, outputDirectoryName, "diagnosticMessages.generated.json"), xmlObjectToString(result)); } /** * A locale name is based on the language tagging conventions of RFC 4646 (Windows Vista * and later), and is represented by LOCALE_SNAME. * Generally, the pattern - is used. Here, language is a lowercase ISO 639 * language code. The codes from ISO 639-1 are used when available. Otherwise, codes from * ISO 639-2/T are used. REGION specifies an uppercase ISO 3166-1 country/region identifier. * For example, the locale name for English (United States) is "en-US" and the locale name * for Divehi (Maldives) is "dv-MV". * * If the locale is a neutral locale (no region), the LOCALE_SNAME value follows the * pattern . If it is a neutral locale for which the script is significant, the * pattern is -