UNPKG

@sap-ux/i18n

Version:
32 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeToExistingI18nPropertiesFile = writeToExistingI18nPropertiesFile; const utils_1 = require("../../utils"); /** * Write i18n entries to an existing i18n.properties file. * * @param i18nFilePath i18n file path * @param newI18nEntries new i18n entries that will be maintained * @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node * @returns boolean */ async function writeToExistingI18nPropertiesFile(i18nFilePath, newI18nEntries, fs) { let newContent = newI18nEntries .map((entry) => (0, utils_1.printPropertiesI18nEntry)(entry.key, entry.value, entry.annotation)) .join(''); const content = await (0, utils_1.readFile)(i18nFilePath, fs); if (content) { const lines = content.split(/\r\n|\n/); // check if file does not end with new line if (lines.length > 0 && lines[lines.length - 1].trim()) { // If there no end line - add new gap line before new content newContent = `\n${newContent}`; } await (0, utils_1.writeFile)(i18nFilePath, content.concat(newContent), fs); return true; } else { return false; } } //# sourceMappingURL=index.js.map