UNPKG

@sap-ux/i18n

Version:

Library for i18n

35 lines 1.55 kB
import { join } from 'node:path'; import { getI18nConfiguration, getCapI18nFolder } from '../../utils/index.js'; import { tryAddJsonTexts } from './json.js'; import { tryAddCsvTexts } from './csv.js'; import { tryAddPropertiesTexts } from './properties.js'; /** * Create new i18n entries to an existing file or in a new file if one does not exist. * * @param root project root, where i18n folder should reside if no i18n file exists * @param path absolute path to cds file for which translation should be maintained * @param newI18nEntries new i18n entries that will be maintained * @param env CDS environment configuration * @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 To create new entries, if tries: * ```markdown * 1. `.json` file * 2. `.properties` file, if failed for `.json` file * 3. `.csv` file if failed for `.properties` file * ``` */ export async function createCapI18nEntries(root, path, newI18nEntries, env, fs) { const { baseFileName } = getI18nConfiguration(env); const i18nFolderPath = await getCapI18nFolder(root, path, env, fs); const filePath = join(i18nFolderPath, baseFileName); const updaters = [tryAddJsonTexts, tryAddPropertiesTexts, tryAddCsvTexts]; for (const update of updaters) { const completed = await update(env, filePath, newI18nEntries, fs); if (completed) { return true; } } return false; } //# sourceMappingURL=create.js.map