UNPKG

auto-translate-json-library

Version:

Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server

68 lines (67 loc) 2.72 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.FolderFiles = void 0; const fs = __importStar(require("node:fs")); const path = __importStar(require("node:path")); const files_1 = require("./files"); class FolderFiles { constructor(filePath) { const localeDir = path.dirname(filePath); this.folderPath = path.dirname(localeDir); this.fileName = path.basename(filePath); this.sourceLocale = path.basename(localeDir); this.targetLocales = this.getTargetLocales(); console.log(this.folderPath, this.fileName, this.sourceLocale, this.targetLocales); } getTargetLocales() { const files = fs .readdirSync(this.folderPath) .map((folder, _index, _array) => path.basename(folder)) .map((locale, _index, _array) => locale !== this.sourceLocale ? locale : "") .filter((x, _index, _array) => x); // do not want empty strings return files; } createFileName(locale) { return `${this.folderPath}/${locale}/${this.fileName}`; } loadJsonFromLocale(locale) { return (0, files_1.loadJsonFromLocale)(this.createFileName(locale)); } saveJsonToLocale(locale, file) { (0, files_1.saveJsonToLocale)(this.createFileName(locale), file); } } exports.FolderFiles = FolderFiles;