wuchale
Version:
Protobuf-like i18n from plain code
94 lines (93 loc) • 3.75 kB
TypeScript
import { IndexTracker, Message } from "./adapters.js";
import type { Adapter, GlobConf, LoaderPath } from "./adapters.js";
import { type CompiledElement } from "./compile.js";
import { type ItemType } from "./ai/index.js";
import { type Matcher } from 'picomatch';
import PO from "pofile";
import { type ConfigPartial } from "./config.js";
import { type Logger } from './log.js';
import { type Token } from 'path-to-regexp';
import { type URLLocalizer } from './url.js';
type PluralRule = {
nplurals: number;
plural: string;
};
type Catalog = Record<string, ItemType>;
type POFile = {
catalog: Catalog;
headers: Record<string, string>;
pluralRule: PluralRule;
};
export declare const urlPatternFlag = "url-pattern";
export declare function loadPOFile(filename: string): Promise<PO>;
export type Mode = 'dev' | 'build' | 'cli';
type Compiled = {
hasPlurals: boolean;
items: CompiledElement[];
};
type CompiledCatalogs = Record<string, Compiled>;
type SharedState = {
ownerKey: string;
otherFileMatches: Matcher[];
poFilesByLoc: Record<string, POFile>;
compiled: CompiledCatalogs;
extractedUrls: Record<string, Catalog>;
indexTracker: IndexTracker;
};
export type SharedStates = Record<string, SharedState>;
type GranularState = {
id: string;
compiled: CompiledCatalogs;
indexTracker: IndexTracker;
};
type TransformOutputCode = {
code?: string;
map?: any;
};
export declare class AdapterHandler {
#private;
key: string;
loaderPath: LoaderPath;
proxyPath: string;
proxySyncPath: string;
fileMatches: Matcher;
localizeUrl?: URLLocalizer;
sharedState: SharedState;
granularStateByFile: Record<string, GranularState>;
granularStateByID: Record<string, GranularState>;
catalogPathsToLocales: Record<string, string>;
onBeforeWritePO: () => void;
constructor(adapter: Adapter, key: string, config: ConfigPartial, mode: Mode, projectRoot: string, log: Logger);
getLoaderPaths(): LoaderPath[];
getLoaderPath(): Promise<LoaderPath>;
getCompiledFilePath(loc: string, id: string | null): string;
getLoadIDs(forImport?: boolean): string[];
genProxy(catalogs: string[], loadIDs: string[], syncImports?: string[]): string;
getProxy(): string;
getProxySync(): string;
getData(): string;
catalogFileName: (locale: string) => string;
urlPatternFromTranslate: (patternTranslated: string, keys: Token[]) => string;
writeUrlFiles: () => Promise<void>;
init: (sharedStates: SharedStates) => Promise<void>;
urlPatternToTranslate: (pattern: string) => string;
initUrlPatterns: () => Promise<void>;
loadCatalogNCompile: (loc: string, hmrVersion?: number) => Promise<void>;
loadCatalogModule: (locale: string, loadID: string | null, hmrVersion: number) => string;
matchUrl: (url: string) => string | null;
getUrlToCompile: (key: string, locale: string) => string;
compile: (loc: string, hmrVersion?: number) => Promise<void>;
writeCompiled: (loc: string, hmrVersion?: number) => Promise<void>;
writeProxies: () => Promise<void>;
writeTransformed: (filename: string, content: string) => Promise<void>;
globConfToArgs: (conf: GlobConf) => [string[], {
ignore: string[];
}];
savePO: (loc: string) => Promise<void>;
savePoAndCompile: (loc: string) => Promise<void>;
handleMessages: (loc: string, msgs: Message[], filename: string) => Promise<string[]>;
transform: (content: string, filename: string, hmrVersion?: number, forServer?: boolean, direct?: boolean) => Promise<TransformOutputCode>;
directFileHandler(): (filename: string) => Promise<void>;
directScanFS(clean: boolean, sync: boolean): Promise<void>;
}
export {};