i18n-ai-translate
Version:
AI-powered localization CLI, Node library, and GitHub Action. Translate i18next JSON, Gettext PO, Java .properties, and iOS .strings with ChatGPT, Claude, Gemini, or local Ollama models.
104 lines • 4.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_CACHE_PATH = exports.CACHE_VERSION = void 0;
exports.createCache = createCache;
exports.cacheKey = cacheKey;
exports.getCachedTranslation = getCachedTranslation;
exports.setCachedTranslation = setCachedTranslation;
exports.loadCache = loadCache;
exports.saveCache = saveCache;
const utils_1 = require("./utils");
const crypto_1 = __importDefault(require("crypto"));
const fs_1 = __importDefault(require("fs"));
/** Bump when the on-disk shape changes; older caches are ignored. */
exports.CACHE_VERSION = 1;
/** Default cache file written into the cwd when `--cache` has no path. */
exports.DEFAULT_CACHE_PATH = ".i18n-ai-translate-cache.json";
/**
* @returns a fresh, empty cache at the current schema version
*/
function createCache() {
return { entries: {}, version: exports.CACHE_VERSION };
}
/**
* Compute the content-addressed key for one translatable string.
* @param inputLanguageCode - the source language code
* @param outputLanguageCode - the target language code
* @param context - the `--context` string ("" when unset)
* @param source - the source text being translated
* @returns a hex sha256 digest uniquely identifying the entry
*/
function cacheKey(inputLanguageCode, outputLanguageCode, context, source) {
return crypto_1.default
.createHash("sha256")
.update(`${inputLanguageCode}