@verbaly/compiler 0.39.0 → 0.40.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/README.md +41 -1
- package/dist/{claude-0MJOMelz.js → claude-DGo229kG.js} +2 -2
- package/dist/{claude-0MJOMelz.js.map → claude-DGo229kG.js.map} +1 -1
- package/dist/cli.js +36 -2
- package/dist/cli.js.map +1 -1
- package/dist/{config-pSOnS9OZ.js → config-B6MP3zwt.js} +2 -1
- package/dist/config-B6MP3zwt.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +48 -5
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/config-pSOnS9OZ.js.map +0 -1
|
@@ -15,6 +15,7 @@ function resolveConfig(config = {}) {
|
|
|
15
15
|
root,
|
|
16
16
|
dir,
|
|
17
17
|
sourceLocale,
|
|
18
|
+
routing: config.routing ?? "prefix-except-source",
|
|
18
19
|
locales: [...locales],
|
|
19
20
|
include: config.include ?? ["{src,app}/**/*.{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}"],
|
|
20
21
|
exclude: config.exclude ?? ["**/node_modules/**", "**/dist/**"],
|
|
@@ -75,4 +76,4 @@ function definedOnly(config) {
|
|
|
75
76
|
//#endregion
|
|
76
77
|
export { targetLocales as a, resolveConfig as i, isModuleNotFound as n, loadConfig as r, findConfigFile as t };
|
|
77
78
|
|
|
78
|
-
//# sourceMappingURL=config-
|
|
79
|
+
//# sourceMappingURL=config-B6MP3zwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-B6MP3zwt.js","names":[],"sources":["../src/pseudo.ts","../src/config.ts"],"sourcesContent":["import type { Catalog, Catalogs } from './catalog';\nimport type { ResolvedConfig } from './config';\n\nexport const PSEUDO_LOCALE = 'en-XA';\n\nconst ACCENTS: Record<string, string> = {\n a: 'á',\n b: 'ƀ',\n c: 'ç',\n d: 'đ',\n e: 'é',\n f: 'ƒ',\n g: 'ğ',\n h: 'ĥ',\n i: 'í',\n j: 'ĵ',\n k: 'ķ',\n l: 'ĺ',\n m: 'ɱ',\n n: 'ñ',\n o: 'ó',\n p: 'þ',\n q: 'ǫ',\n r: 'ŕ',\n s: 'š',\n t: 'ţ',\n u: 'ú',\n v: 'ṽ',\n w: 'ŵ',\n x: 'ẋ',\n y: 'ý',\n z: 'ž',\n A: 'Á',\n B: 'Ɓ',\n C: 'Ç',\n D: 'Đ',\n E: 'É',\n F: 'Ƒ',\n G: 'Ğ',\n H: 'Ĥ',\n I: 'Í',\n J: 'Ĵ',\n K: 'Ķ',\n L: 'Ĺ',\n M: 'Ḿ',\n N: 'Ñ',\n O: 'Ó',\n P: 'Þ',\n Q: 'Ǫ',\n R: 'Ŕ',\n S: 'Š',\n T: 'Ţ',\n U: 'Ú',\n V: 'Ṽ',\n W: 'Ŵ',\n X: 'Ẍ',\n Y: 'Ý',\n Z: 'Ž',\n};\n\nconst TAG_AT = /<\\/?[a-zA-Z][\\w-]*\\/?>/y;\n\n// params, variant blocks, tags and escapes survive verbatim\nexport function pseudoLocalize(message: string): string {\n let out = '';\n let letters = 0;\n let i = 0;\n while (i < message.length) {\n const two = message.slice(i, i + 2);\n if (two === '{{' || two === '}}' || two === '||' || two === '##') {\n out += two;\n i += 2;\n continue;\n }\n const ch = message[i]!;\n if (ch === '{') {\n const end = matchBrace(message, i);\n out += message.slice(i, end);\n i = end;\n continue;\n }\n if (ch === '<') {\n TAG_AT.lastIndex = i;\n const m = TAG_AT.exec(message);\n if (m) {\n out += m[0];\n i += m[0].length;\n continue;\n }\n }\n const mapped = ACCENTS[ch];\n if (mapped) {\n out += mapped;\n letters += 1;\n } else {\n out += ch;\n }\n i += 1;\n }\n const pad = '~'.repeat(Math.ceil(letters / 3));\n return `⟦${out}${pad ? ' ' + pad : ''}⟧`;\n}\n\nfunction matchBrace(message: string, start: number): number {\n let depth = 0;\n for (let i = start; i < message.length; i++) {\n const two = message.slice(i, i + 2);\n if (two === '{{' || two === '}}') {\n i += 1;\n continue;\n }\n const ch = message[i];\n if (ch === '{') depth += 1;\n else if (ch === '}') {\n depth -= 1;\n if (depth === 0) return i + 1;\n }\n }\n return message.length; // unbalanced → verbatim\n}\n\n// regenerates the whole pseudo catalog from the source catalog\nexport function pseudoCatalogs(\n cfg: ResolvedConfig,\n catalogs: Catalogs,\n locale: string = PSEUDO_LOCALE,\n): string[] {\n const source = catalogs[cfg.sourceLocale] ?? {};\n const target: Catalog = {};\n for (const [key, msg] of Object.entries(source)) {\n target[key] = msg ? pseudoLocalize(msg) : '';\n }\n catalogs[locale] = target;\n return Object.keys(target).filter((key) => target[key]);\n}\n","import { existsSync, readFileSync, readdirSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RichLink, Routing } from 'verbaly';\nimport { PSEUDO_LOCALE } from './pseudo';\nimport type { TranslateProvider } from './translate';\n\n// a term maps to how it must come out: one rendering for every locale, or one per locale\nexport type GlossaryEntry = string | Record<string, string>;\n\nexport interface TranslateConfig {\n provider?: 'claude' | TranslateProvider;\n model?: string;\n batchSize?: number;\n concurrency?: number;\n retries?: number;\n instructions?: string;\n glossary?: Record<string, GlossaryEntry>;\n}\n\nexport interface RedirectConfig {\n on?: 'root' | 'all';\n storageKey?: string | false;\n}\n\nexport interface RenderConfig {\n links?: Record<string, RichLink>;\n site?: string;\n attribute?: string;\n base?: string;\n baseUrl?: string;\n hreflang?: boolean;\n sitemap?: boolean | string;\n redirect?: boolean | RedirectConfig;\n clean?: boolean;\n}\n\nexport interface VerbalyConfig {\n root?: string;\n dir?: string;\n sourceLocale?: string;\n locales?: string[];\n routing?: Routing;\n include?: string[];\n exclude?: string[];\n dts?: string | false;\n translate?: TranslateConfig;\n render?: RenderConfig;\n}\n\nexport interface ResolvedConfig {\n root: string;\n dir: string;\n sourceLocale: string;\n locales: string[];\n routing: Routing;\n include: string[];\n exclude: string[];\n dts: string | false | undefined;\n translate: TranslateConfig;\n render: RenderConfig;\n}\n\nexport function resolveConfig(config: VerbalyConfig = {}): ResolvedConfig {\n const root = resolve(config.root ?? process.cwd());\n const dir = resolve(root, config.dir ?? 'locales');\n const sourceLocale = config.sourceLocale ?? 'en';\n\n const locales = new Set<string>([sourceLocale, ...(config.locales ?? [])]);\n if (existsSync(dir)) {\n for (const file of readdirSync(dir)) {\n if (file.endsWith('.json') && !file.startsWith('.') && file !== `${PSEUDO_LOCALE}.json`) {\n locales.add(file.slice(0, -5));\n }\n }\n }\n\n return {\n root,\n dir,\n sourceLocale,\n // what render has always written, so a project that never says it keeps the urls it had\n routing: config.routing ?? 'prefix-except-source',\n locales: [...locales],\n include: config.include ?? ['{src,app}/**/*.{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}'],\n exclude: config.exclude ?? ['**/node_modules/**', '**/dist/**'],\n dts: typeof config.dts === 'string' ? resolve(root, config.dts) : config.dts,\n translate: config.translate ?? {},\n render: config.render ?? {},\n };\n}\n\nconst CONFIG_FILES = [\n 'verbaly.config.js',\n 'verbaly.config.mjs',\n 'verbaly.config.ts',\n 'verbaly.config.mts',\n 'verbaly.config.json',\n];\n\nexport function findConfigFile(root: string): string | undefined {\n return CONFIG_FILES.find((name) => existsSync(join(root, name)));\n}\n\nexport async function loadConfigFile(root: string): Promise<VerbalyConfig> {\n for (const name of ['verbaly.config.js', 'verbaly.config.mjs']) {\n const path = join(root, name);\n if (existsSync(path)) {\n const mod = (await import(pathToFileURL(path).href)) as { default?: VerbalyConfig };\n return mod.default ?? {};\n }\n }\n for (const name of ['verbaly.config.ts', 'verbaly.config.mts']) {\n const path = join(root, name);\n if (existsSync(path)) return loadTsConfig(path);\n }\n const jsonPath = join(root, 'verbaly.config.json');\n if (existsSync(jsonPath)) {\n return JSON.parse(readFileSync(jsonPath, 'utf8')) as VerbalyConfig;\n }\n return {};\n}\n\nasync function loadTsConfig(path: string): Promise<VerbalyConfig> {\n try {\n const { bundleRequire } = await import('bundle-require');\n const { mod } = await bundleRequire<{ default?: VerbalyConfig }>({ filepath: path });\n return mod.default ?? {};\n } catch (error) {\n if (isModuleNotFound(error, 'esbuild')) {\n throw new Error(`[verbaly] ${path} needs esbuild: install it with pnpm add -D esbuild`, {\n cause: error,\n });\n }\n throw error;\n }\n}\n\nexport function isModuleNotFound(error: unknown, name: string): boolean {\n return (\n error instanceof Error &&\n (error as { code?: string }).code === 'ERR_MODULE_NOT_FOUND' &&\n error.message.includes(name)\n );\n}\n\n// non-source locales a command may write to (optional CLI override, always config-bounded)\nexport function targetLocales(cfg: ResolvedConfig, override?: string[]): string[] {\n return (override ?? cfg.locales).filter(\n (locale) => locale !== cfg.sourceLocale && cfg.locales.includes(locale),\n );\n}\n\n// file config + inline overrides\nexport async function loadConfig(\n root: string,\n overrides: VerbalyConfig = {},\n): Promise<ResolvedConfig> {\n const fileConfig = await loadConfigFile(root);\n return resolveConfig({ ...fileConfig, ...definedOnly(overrides), root });\n}\n\nfunction definedOnly(config: VerbalyConfig): VerbalyConfig {\n return Object.fromEntries(\n Object.entries(config).filter(([, value]) => value !== undefined),\n ) as VerbalyConfig;\n}\n"],"mappings":";;;;;AC+DA,SAAgB,cAAc,SAAwB,CAAC,GAAmB;CACxE,MAAM,OAAO,QAAQ,OAAO,QAAQ,QAAQ,IAAI,CAAC;CACjD,MAAM,MAAM,QAAQ,MAAM,OAAO,OAAO,SAAS;CACjD,MAAM,eAAe,OAAO,gBAAgB;CAE5C,MAAM,0BAAU,IAAI,IAAY,CAAC,cAAc,GAAI,OAAO,WAAW,CAAC,CAAE,CAAC;CACzE,IAAI,WAAW,GAAG,GACX;OAAA,MAAM,QAAQ,YAAY,GAAG,GAChC,IAAI,KAAK,SAAS,OAAO,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,SAAS,cAC9D,QAAQ,IAAI,KAAK,MAAM,GAAG,EAAE,CAAC;CAAA;CAKnC,OAAO;EACL;EACA;EACA;EAEA,SAAS,OAAO,WAAW;EAC3B,SAAS,CAAC,GAAG,OAAO;EACpB,SAAS,OAAO,WAAW,CAAC,yDAAyD;EACrF,SAAS,OAAO,WAAW,CAAC,sBAAsB,YAAY;EAC9D,KAAK,OAAO,OAAO,QAAQ,WAAW,QAAQ,MAAM,OAAO,GAAG,IAAI,OAAO;EACzE,WAAW,OAAO,aAAa,CAAC;EAChC,QAAQ,OAAO,UAAU,CAAC;CAC5B;AACF;AAEA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,eAAe,MAAkC;CAC/D,OAAO,aAAa,MAAM,SAAS,WAAW,KAAK,MAAM,IAAI,CAAC,CAAC;AACjE;AAEA,eAAsB,eAAe,MAAsC;CACzE,KAAK,MAAM,QAAQ,CAAC,qBAAqB,oBAAoB,GAAG;EAC9D,MAAM,OAAO,KAAK,MAAM,IAAI;EAC5B,IAAI,WAAW,IAAI,GAEjB,QAAO,MADY,OAAO,cAAc,IAAI,CAAC,CAAC,MAAA,CACnC,WAAW,CAAC;CAE3B;CACA,KAAK,MAAM,QAAQ,CAAC,qBAAqB,oBAAoB,GAAG;EAC9D,MAAM,OAAO,KAAK,MAAM,IAAI;EAC5B,IAAI,WAAW,IAAI,GAAG,OAAO,aAAa,IAAI;CAChD;CACA,MAAM,WAAW,KAAK,MAAM,qBAAqB;CACjD,IAAI,WAAW,QAAQ,GACrB,OAAO,KAAK,MAAM,aAAa,UAAU,MAAM,CAAC;CAElD,OAAO,CAAC;AACV;AAEA,eAAe,aAAa,MAAsC;CAChE,IAAI;EACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,EAAE,QAAQ,MAAM,cAA2C,EAAE,UAAU,KAAK,CAAC;EACnF,OAAO,IAAI,WAAW,CAAC;CACzB,SAAS,OAAO;EACd,IAAI,iBAAiB,OAAO,SAAS,GACnC,MAAM,IAAI,MAAM,aAAa,KAAK,sDAAsD,EACtF,OAAO,MACT,CAAC;EAEH,MAAM;CACR;AACF;AAEA,SAAgB,iBAAiB,OAAgB,MAAuB;CACtE,OACE,iBAAiB,SAChB,MAA4B,SAAS,0BACtC,MAAM,QAAQ,SAAS,IAAI;AAE/B;AAGA,SAAgB,cAAc,KAAqB,UAA+B;CAChF,QAAQ,YAAY,IAAI,QAAA,CAAS,QAC9B,WAAW,WAAW,IAAI,gBAAgB,IAAI,QAAQ,SAAS,MAAM,CACxE;AACF;AAGA,eAAsB,WACpB,MACA,YAA2B,CAAC,GACH;CAEzB,OAAO,cAAc;EAAE,GAAG,MADD,eAAe,IAAI;EACN,GAAG,YAAY,SAAS;EAAG;CAAK,CAAC;AACzE;AAEA,SAAS,YAAY,QAAsC;CACzD,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAClE;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RichLink } from "verbaly";
|
|
1
|
+
import { RichLink, Routing } from "verbaly";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
//#region src/catalog.d.ts
|
|
4
4
|
type Catalog = Record<string, string>;
|
|
@@ -79,6 +79,7 @@ interface VerbalyConfig {
|
|
|
79
79
|
dir?: string;
|
|
80
80
|
sourceLocale?: string;
|
|
81
81
|
locales?: string[];
|
|
82
|
+
routing?: Routing;
|
|
82
83
|
include?: string[];
|
|
83
84
|
exclude?: string[];
|
|
84
85
|
dts?: string | false;
|
|
@@ -90,6 +91,7 @@ interface ResolvedConfig {
|
|
|
90
91
|
dir: string;
|
|
91
92
|
sourceLocale: string;
|
|
92
93
|
locales: string[];
|
|
94
|
+
routing: Routing;
|
|
93
95
|
include: string[];
|
|
94
96
|
exclude: string[];
|
|
95
97
|
dts: string | false | undefined;
|
|
@@ -313,8 +315,10 @@ interface RenderSiteResult {
|
|
|
313
315
|
files: number;
|
|
314
316
|
locales: string[];
|
|
315
317
|
missing: Record<string, string[]>;
|
|
318
|
+
untranslatedHead: string[];
|
|
316
319
|
}
|
|
317
320
|
declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
|
|
321
|
+
declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
|
|
318
322
|
//#endregion
|
|
319
|
-
export { type BrokenEntry, type Catalog, type Catalogs, type CheckResult, type DoctorEntry, type DoctorResult, type Drafts, type GlossaryEntry, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type PluginOptions, RESOLVED_VIRTUAL_ID, type RedirectConfig, type RenderConfig, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type StatusResult, type SyncResult, type TransformResult, type TranslateConfig, type TranslateFailure, type TranslateOptions, type TranslateProgress, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type VerbalyConfig, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, check, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
|
|
323
|
+
export { type BrokenEntry, type Catalog, type Catalogs, type CheckResult, type DoctorEntry, type DoctorResult, type Drafts, type GlossaryEntry, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type PluginOptions, RESOLVED_VIRTUAL_ID, type RedirectConfig, type RenderConfig, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type StatusResult, type SyncResult, type TransformResult, type TranslateConfig, type TranslateFailure, type TranslateOptions, type TranslateProgress, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type VerbalyConfig, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, check, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
|
|
320
324
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-
|
|
1
|
+
import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-B6MP3zwt.js";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseTags, safeAttribute } from "verbaly";
|
|
@@ -868,11 +868,21 @@ function generateRuntimeModule(cfg, options = {}) {
|
|
|
868
868
|
const others = cfg.locales.filter((locale) => locale !== cfg.sourceLocale);
|
|
869
869
|
const src = JSON.stringify(cfg.sourceLocale);
|
|
870
870
|
const loaders = others.map((locale) => ` ${JSON.stringify(locale)}: () => import('${importPath(locale)}'),`).join("\n");
|
|
871
|
-
return `import { createVerbaly } from 'verbaly';
|
|
871
|
+
return `import { createVerbaly, localeFromPath as readPath, localePath as writePath } from 'verbaly';
|
|
872
872
|
import source from '${importPath(cfg.sourceLocale)}';
|
|
873
873
|
|
|
874
874
|
export const sourceLocale = ${src};
|
|
875
875
|
export const locales = ${JSON.stringify(cfg.locales)};
|
|
876
|
+
export const routing = ${JSON.stringify(cfg.routing)};
|
|
877
|
+
|
|
878
|
+
// bound to this project: the locale set, the source and the routing mode are never passed in
|
|
879
|
+
export function localePath(locale, options) {
|
|
880
|
+
return writePath(locale, { ...options, supported: locales, sourceLocale, routing });
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export function localeFromPath(options) {
|
|
884
|
+
return readPath({ ...options, supported: locales });
|
|
885
|
+
}
|
|
876
886
|
|
|
877
887
|
const localeLoaders = {
|
|
878
888
|
${loaders}
|
|
@@ -946,6 +956,15 @@ ${lines.join("\n")}
|
|
|
946
956
|
|
|
947
957
|
export const sourceLocale: string;
|
|
948
958
|
export const locales: string[];
|
|
959
|
+
export const routing: import('verbaly').Routing;
|
|
960
|
+
export function localePath(
|
|
961
|
+
locale: string,
|
|
962
|
+
options?: { path?: string; base?: string },
|
|
963
|
+
): string;
|
|
964
|
+
export function localeFromPath(options?: {
|
|
965
|
+
path?: string;
|
|
966
|
+
base?: string;
|
|
967
|
+
}): string | undefined;
|
|
949
968
|
export function loadMessages(locale: string): Promise<Record<string, string>>;
|
|
950
969
|
export function createInstance(
|
|
951
970
|
options?: import('verbaly').VerbalyOptions<VerbalyKey>,
|
|
@@ -1390,7 +1409,7 @@ function formatTranslateFailures(failed) {
|
|
|
1390
1409
|
async function resolveProvider(cfg, model) {
|
|
1391
1410
|
const configured = cfg.translate.provider;
|
|
1392
1411
|
if (typeof configured === "function") return configured;
|
|
1393
|
-
const { claudeProvider } = await import("./claude-
|
|
1412
|
+
const { claudeProvider } = await import("./claude-DGo229kG.js");
|
|
1394
1413
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
1395
1414
|
}
|
|
1396
1415
|
function structureMatches(source, translated) {
|
|
@@ -1499,6 +1518,11 @@ function detectHost(root) {
|
|
|
1499
1518
|
//#endregion
|
|
1500
1519
|
//#region src/doctor.ts
|
|
1501
1520
|
const PREVIEW = 5;
|
|
1521
|
+
const ROUTING_SAYS = {
|
|
1522
|
+
"prefix-except-source": "the source locale has no prefix, every other locale does",
|
|
1523
|
+
"prefix-all": "every locale has a prefix, the source included",
|
|
1524
|
+
"no-prefix": "the language is not in the url, one address serves every locale"
|
|
1525
|
+
};
|
|
1502
1526
|
const ICON = {
|
|
1503
1527
|
ok: "✓",
|
|
1504
1528
|
warn: "⚠",
|
|
@@ -1561,6 +1585,9 @@ async function doctor(cfg) {
|
|
|
1561
1585
|
}
|
|
1562
1586
|
const source = catalogs[cfg.sourceLocale];
|
|
1563
1587
|
if (source && Object.keys(source).length === 0) warn("source", `source catalog ${cfg.sourceLocale}.json is empty`, "write your first t`…` message and run `npx verbaly extract`");
|
|
1588
|
+
const mirrors = cfg.render.site !== void 0 || Object.keys(cfg.render).length > 0;
|
|
1589
|
+
if (cfg.routing === "no-prefix" && mirrors) warn("routing", "routing is \"no-prefix\" but a render section is configured, and render writes one url tree per locale", "drop the render section, or set routing to \"prefix-except-source\" so the helpers agree with the urls");
|
|
1590
|
+
else ok("routing", `${cfg.routing}: ${ROUTING_SAYS[cfg.routing]}`);
|
|
1564
1591
|
const deps = readDependencies(cfg.root);
|
|
1565
1592
|
const host = detectHost(cfg.root);
|
|
1566
1593
|
const installed = WIRING_PACKAGES.find((pkg) => deps[pkg]);
|
|
@@ -2012,6 +2039,13 @@ function injectAlternates(ms, html, alternates) {
|
|
|
2012
2039
|
const head = /<\/head\s*>/i.exec(html);
|
|
2013
2040
|
if (head) ms.appendLeft(head.index, block);
|
|
2014
2041
|
}
|
|
2042
|
+
const TITLE_TAG = /<title\b([^>]*)>/i;
|
|
2043
|
+
const REFRESH_META = /<meta\b[^>]*http-equiv\s*=\s*["']?refresh/i;
|
|
2044
|
+
function headIsBound(html, attr) {
|
|
2045
|
+
if (REFRESH_META.test(html)) return true;
|
|
2046
|
+
const title = TITLE_TAG.exec(html);
|
|
2047
|
+
return title ? title[1].includes(attr) : true;
|
|
2048
|
+
}
|
|
2015
2049
|
async function renderSite(cfg, options = {}) {
|
|
2016
2050
|
const site = join(cfg.root, options.site ?? cfg.render.site ?? "dist");
|
|
2017
2051
|
const locales = options.locales ?? cfg.locales;
|
|
@@ -2045,10 +2079,12 @@ async function renderSite(cfg, options = {}) {
|
|
|
2045
2079
|
});
|
|
2046
2080
|
const pages = new Set(files.map((file) => publicPath(relative(site, file).replace(/\\/g, "/"))));
|
|
2047
2081
|
const missing = {};
|
|
2082
|
+
const untranslatedHead = [];
|
|
2048
2083
|
const urls = [];
|
|
2049
2084
|
for (const file of files) {
|
|
2050
2085
|
const html = readFileSync(file, "utf8");
|
|
2051
2086
|
const rel = relative(site, file).replace(/\\/g, "/");
|
|
2087
|
+
if (locales.length > 1 && !headIsBound(html, attribute ?? "data-verbaly")) untranslatedHead.push(rel);
|
|
2052
2088
|
const alternates = wantHreflang ? pageAlternates(baseUrl, rel, locales, cfg.sourceLocale) : [];
|
|
2053
2089
|
if (wantHreflang) urls.push({
|
|
2054
2090
|
rel,
|
|
@@ -2084,9 +2120,16 @@ async function renderSite(cfg, options = {}) {
|
|
|
2084
2120
|
return {
|
|
2085
2121
|
files: files.length,
|
|
2086
2122
|
locales: [...locales],
|
|
2087
|
-
missing
|
|
2123
|
+
missing,
|
|
2124
|
+
untranslatedHead
|
|
2088
2125
|
};
|
|
2089
2126
|
}
|
|
2127
|
+
function formatRenderWarnings(result, sourceLocale) {
|
|
2128
|
+
const lines = [];
|
|
2129
|
+
for (const [locale, keys] of Object.entries(result.missing)) lines.push(` ${locale}: ${counted(keys.length, "key")} not pre-filled: ${keys.join(", ")}`);
|
|
2130
|
+
if (result.untranslatedHead.length > 0) lines.push(` ${counted(result.untranslatedHead.length, "page")} of ${result.files} ship the same <title> in every locale (${result.untranslatedHead[0]}), so search results read in ${sourceLocale}`, ` fix: bind the head too, <title data-verbaly="key"> and a meta through data-verbaly-attr`);
|
|
2131
|
+
return lines;
|
|
2132
|
+
}
|
|
2090
2133
|
function pageUrl(baseUrl, prefix, rel) {
|
|
2091
2134
|
const path = rel.replace(/(^|\/)index\.html$/, "$1");
|
|
2092
2135
|
return `${baseUrl}${prefix}${path ? `/${path}` : "/"}`;
|
|
@@ -2187,6 +2230,6 @@ function decodeEntities(text) {
|
|
|
2187
2230
|
return text.replace(/"/g, "\"").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
2188
2231
|
}
|
|
2189
2232
|
//#endregion
|
|
2190
|
-
export { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, check, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
|
|
2233
|
+
export { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, check, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
|
|
2191
2234
|
|
|
2192
2235
|
//# sourceMappingURL=index.js.map
|