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.
40 lines (39 loc) • 1.36 kB
TypeScript
import type FormatAdapter from "./format_adapter";
type PlaceholderMap = {
/** Native MessageFormat tokens, indexed by their argument number. */
tokens: string[];
};
/**
* One logical line of the source file. A `raw` record is a comment or
* blank line preserved verbatim; an `entry` record is a `key=value`
* pair. `rawBlock` holds the entry's original text (possibly several
* physical lines joined by line continuations) so an unchanged value
* round-trips byte-for-byte; `rawKey`/`separator` are the line-one
* prefix used to re-emit only the value when a translation differs.
*/
type PropertyRecord = {
kind: "raw";
text: string;
} | {
kind: "entry";
key: string;
rawKey: string;
separator: string;
rawBlock: string;
/** Placeholder-stripped original value; "unchanged" sentinel. */
normalizedValue: string;
placeholders: PlaceholderMap;
};
/**
* Everything needed to rebuild the .properties file after the flat map
* round-trips through the pipeline: the ordered records (comments,
* blanks, and entries with their original bytes) plus whether the file
* ended in a newline.
*/
type PropertiesSidecar = {
kind: "properties";
records: PropertyRecord[];
trailingNewline: boolean;
};
declare const PropertiesAdapter: FormatAdapter<PropertiesSidecar>;
export default PropertiesAdapter;