@sap-ux/i18n
Version:
Library for i18n
28 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPropertiesI18nEntries = createPropertiesI18nEntries;
const utils_1 = require("../../utils");
const utils_2 = require("../utils");
const path_1 = require("path");
/**
* Creates new i18n entries in `i18n.properties` file.
*
* @param i18nFilePath absolute path to `i18n.properties` file
* @param newI18nEntries new i18n entries that will be maintained
* @param root project root optionally used in comment if file is newly generated
* @param fs optional `mem-fs-editor` instance. If provided, `mem-fs-editor` api is used instead of `fs` of node
* @returns boolean or exception
* @description If `i18n.properties` file does not exits, it tries to create.
* @description Consumer should maintain respective `manifest.json` entry if needed.
*/
async function createPropertiesI18nEntries(i18nFilePath, newI18nEntries, root, fs) {
if ((!fs && !(await (0, utils_1.doesExist)(i18nFilePath))) || (fs && !fs.exists(i18nFilePath))) {
let content = '# Resource bundle \n';
if (root) {
content = `# This is the resource bundle for ${(0, path_1.basename)(root)}\n`;
}
await (0, utils_1.writeFile)(i18nFilePath, content, fs);
}
return await (0, utils_2.writeToExistingI18nPropertiesFile)(i18nFilePath, newI18nEntries, fs);
}
//# sourceMappingURL=create.js.map