@verbaly/compiler 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -133,7 +133,11 @@ declare function formatCheckResult(result: CheckResult): string;
|
|
|
133
133
|
//#endregion
|
|
134
134
|
//#region src/codegen.d.ts
|
|
135
135
|
declare const VIRTUAL_ID = "virtual:verbaly";
|
|
136
|
-
|
|
136
|
+
interface RuntimeModuleOptions {
|
|
137
|
+
localeImport?: (locale: string) => string;
|
|
138
|
+
extraExports?: string;
|
|
139
|
+
}
|
|
140
|
+
declare function generateRuntimeModule(cfg: ResolvedConfig, options?: RuntimeModuleOptions): string;
|
|
137
141
|
declare function generateLocaleModule(catalog: Catalog): string;
|
|
138
142
|
declare function generateDts(entries: Map<string, string>): string;
|
|
139
143
|
declare function writeDts(cfg: ResolvedConfig, entries: Map<string, string>): void;
|
|
@@ -289,5 +293,5 @@ interface TransformResult {
|
|
|
289
293
|
}
|
|
290
294
|
declare function transformCode(code: string, file: string, analysis?: Analysis): TransformResult | null;
|
|
291
295
|
//#endregion
|
|
292
|
-
export { type Alternate, type Analysis, type Catalog, type Catalogs, type CheckResult, type ClaudeProviderOptions, type DoctorEntry, type DoctorResult, type ExchangeFormat, type ExportOptions, type ExportResult, type ExportedFile, type ImportOptions, type ImportResult, type InitOptions, type InitResult, LOCALE_MODULE_PREFIX, MessageRegistry, type MissingEntry, PSEUDO_LOCALE, type ParamType, RESOLVED_VIRTUAL_ID, type RenderConfig, type RenderHtmlOptions, type RenderHtmlResult, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, SOURCE_FILE_RE, type SyncResult, type TaggedMessage, type TaggedParam, type TransComponent, type TransformResult, type TranslateConfig, type TranslateOptions, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type UsedKey, VIRTUAL_ID, type VerbalyConfig, analyze, catalogPath, check, claudeProvider, collectParams, detectBundler, doctor, exportCatalogs, extractProject, findConfigFile, formatCheckResult, generateDts, generateLocaleModule, generateRuntimeModule, importCatalogs, init, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadVirtualModule, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, renderHtml, renderParamType, renderSite, resolveConfig, resolveVirtualId, runBuildGate, serializeCatalog, stableKey, structureMatches, syncCatalogs, targetLocales, transformCode, translateCatalogs, writeCatalog, writeDts };
|
|
296
|
+
export { type Alternate, type Analysis, type Catalog, type Catalogs, type CheckResult, type ClaudeProviderOptions, type DoctorEntry, type DoctorResult, type ExchangeFormat, type ExportOptions, type ExportResult, type ExportedFile, type ImportOptions, type ImportResult, type InitOptions, type InitResult, LOCALE_MODULE_PREFIX, MessageRegistry, type MissingEntry, PSEUDO_LOCALE, type ParamType, RESOLVED_VIRTUAL_ID, type RenderConfig, type RenderHtmlOptions, type RenderHtmlResult, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type SyncResult, type TaggedMessage, type TaggedParam, type TransComponent, type TransformResult, type TranslateConfig, type TranslateOptions, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type UsedKey, VIRTUAL_ID, type VerbalyConfig, analyze, catalogPath, check, claudeProvider, collectParams, detectBundler, doctor, exportCatalogs, extractProject, findConfigFile, formatCheckResult, generateDts, generateLocaleModule, generateRuntimeModule, importCatalogs, init, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadVirtualModule, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, renderHtml, renderParamType, renderSite, resolveConfig, resolveVirtualId, runBuildGate, serializeCatalog, stableKey, structureMatches, syncCatalogs, targetLocales, transformCode, translateCatalogs, writeCatalog, writeDts };
|
|
293
297
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -409,25 +409,35 @@ function renderParamType(types) {
|
|
|
409
409
|
//#endregion
|
|
410
410
|
//#region src/codegen.ts
|
|
411
411
|
const VIRTUAL_ID = "virtual:verbaly";
|
|
412
|
-
function generateRuntimeModule(cfg) {
|
|
412
|
+
function generateRuntimeModule(cfg, options = {}) {
|
|
413
|
+
const importPath = options.localeImport ?? ((locale) => `virtual:verbaly/locale/${locale}`);
|
|
413
414
|
const others = cfg.locales.filter((locale) => locale !== cfg.sourceLocale);
|
|
414
415
|
const src = JSON.stringify(cfg.sourceLocale);
|
|
415
|
-
const loaders = others.map((locale) => `
|
|
416
|
+
const loaders = others.map((locale) => ` ${JSON.stringify(locale)}: () => import('${importPath(locale)}'),`).join("\n");
|
|
416
417
|
return `import { createVerbaly } from 'verbaly';
|
|
417
|
-
import source from '${
|
|
418
|
+
import source from '${importPath(cfg.sourceLocale)}';
|
|
418
419
|
|
|
419
420
|
export const sourceLocale = ${src};
|
|
420
421
|
export const locales = ${JSON.stringify(cfg.locales)};
|
|
421
422
|
|
|
423
|
+
const localeLoaders = {
|
|
424
|
+
${loaders}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// raw catalog access — SSR integrations serialize it across the client boundary
|
|
428
|
+
export async function loadMessages(locale) {
|
|
429
|
+
if (locale === ${src}) return source;
|
|
430
|
+
const loader = localeLoaders[locale];
|
|
431
|
+
return loader ? (await loader()).default : {};
|
|
432
|
+
}
|
|
433
|
+
|
|
422
434
|
// per-request/per-instance factory (SSR) — the singleton below is browser/SPA-only
|
|
423
435
|
export function createInstance(options) {
|
|
424
436
|
return createVerbaly({
|
|
425
437
|
locale: ${src},
|
|
426
438
|
fallback: ${src},
|
|
427
439
|
messages: { [${src}]: source },
|
|
428
|
-
loaders:
|
|
429
|
-
${loaders}
|
|
430
|
-
},
|
|
440
|
+
loaders: localeLoaders,
|
|
431
441
|
...options,
|
|
432
442
|
});
|
|
433
443
|
}
|
|
@@ -456,7 +466,7 @@ export async function setLocale(locale) {
|
|
|
456
466
|
await v.loadLocale(locale);
|
|
457
467
|
v.setLocale(locale);
|
|
458
468
|
}
|
|
459
|
-
`;
|
|
469
|
+
${options.extraExports ?? ""}`;
|
|
460
470
|
}
|
|
461
471
|
function generateLocaleModule(catalog) {
|
|
462
472
|
return `export default ${JSON.stringify(catalog)};\n`;
|
|
@@ -482,6 +492,7 @@ ${lines.join("\n")}
|
|
|
482
492
|
|
|
483
493
|
export const sourceLocale: string;
|
|
484
494
|
export const locales: string[];
|
|
495
|
+
export function loadMessages(locale: string): Promise<Record<string, string>>;
|
|
485
496
|
export function createInstance(
|
|
486
497
|
options?: import('verbaly').VerbalyOptions<VerbalyKey>,
|
|
487
498
|
): import('verbaly').Verbaly<VerbalyKey>;
|