ui5-i18n-translate
Version:
A command-line interface (CLI) tool to effortlessly translate your UI5 i18n fallback files into multiple languages using the SAP Translation Hub. This package streamlines the localization process for your UI5 applications by automating the translation of
55 lines (54 loc) • 3.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const js_yaml_1 = __importDefault(require("js-yaml"));
const minimist_1 = __importDefault(require("minimist"));
class Settings {
static get Instance() {
return this.instance || (this.instance = new this());
}
constructor() {
var _a, _b;
const config = this.getConfigFile();
const parameter = this.getParameter();
this.authUrl = (parameter === null || parameter === void 0 ? void 0 : parameter.auth_url) || (config === null || config === void 0 ? void 0 : config.auth_url) || "";
this.authClientId = (parameter === null || parameter === void 0 ? void 0 : parameter.auth_client_id) || (config === null || config === void 0 ? void 0 : config.auth_client_id) || "";
this.authClientSecret = (parameter === null || parameter === void 0 ? void 0 : parameter.auth_client_secret) || (config === null || config === void 0 ? void 0 : config.auth_client_secret) || "";
this.apiUrl = (parameter === null || parameter === void 0 ? void 0 : parameter.api_url) || (config === null || config === void 0 ? void 0 : config.api_url) || "";
this.targetLanguages = ((_a = parameter === null || parameter === void 0 ? void 0 : parameter.target_languages) === null || _a === void 0 ? void 0 : _a.split(",")) || ((_b = config === null || config === void 0 ? void 0 : config.target_languages) === null || _b === void 0 ? void 0 : _b.split(",")) || "";
this.sourceLanguage = (parameter === null || parameter === void 0 ? void 0 : parameter.fallback_language) || (config === null || config === void 0 ? void 0 : config.fallback_language) || "en";
this.isTest = (parameter === null || parameter === void 0 ? void 0 : parameter.test) || false;
this.validateMandatorySettings();
}
getConfigFile() {
const currentDirectory = process.cwd();
const configFilePath = path_1.default.join(currentDirectory, path_1.default.sep, "ui5-i18n-translate.yml");
const configFileExists = fs_1.default.existsSync(configFilePath);
let config = {};
if (configFileExists) {
const fileContents = fs_1.default.readFileSync(configFilePath, "utf8");
config = js_yaml_1.default.load(fileContents);
}
return config;
}
getParameter() {
return (0, minimist_1.default)(process.argv.slice(2));
}
validateMandatorySettings() {
if (!this.authUrl)
throw new Error(`Setting 'auth_url' is not defined`);
if (!this.authClientId)
throw new Error(`Setting 'auth_client_id' is not defined`);
if (!this.authClientSecret)
throw new Error(`Setting 'auth_client_secret' is not defined`);
if (!this.apiUrl)
throw new Error(`Setting 'api_url' is not defined`);
if (!this.targetLanguages)
throw new Error(`Setting 'translate_to' is not defined`);
}
}
exports.default = Settings;