@burojs/i18n-core 0.2.0 → 0.5.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lookup.ts","../src/i18next-adapter.ts","../src/i18n.ts","../src/resource-context.ts","../src/locale-registry.ts","../src/create-i18n-from-registry.ts","../src/index.ts"],"names":["i18next"],"mappings":";;;;;;;;;AAYO,SAAS,UAAA,CAAW,KAAa,QAAA,EAA6B;AACnE,EAAA,IAAI,CAAC,GAAA,EAAK,OAAO,EAAC;AAIlB,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,YAAY,CAAA,IAAK,GAAA,CAAI,UAAA,CAAW,QAAQ,CAAA,IAAK,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA,EAAG;AACzF,IAAA,OAAO,CAAC,GAAG,CAAA;AAAA,EACb;AAEA,EAAA,MAAM,aAAuB,EAAC;AAC9B,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,UAAA,CAAW,IAAA,CAAK,CAAA,UAAA,EAAa,QAAQ,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE,CAAA;AAAA,EAChD;AACA,EAAA,UAAA,CAAW,IAAA,CAAK,CAAA,YAAA,EAAe,GAAG,CAAA,CAAE,CAAA;AACpC,EAAA,UAAA,CAAW,IAAA,CAAK,CAAA,OAAA,EAAU,GAAG,CAAA,CAAE,CAAA;AAC/B,EAAA,UAAA,CAAW,KAAK,GAAG,CAAA;AACnB,EAAA,OAAO,UAAA;AACT;ACJA,eAAsB,qBAAqB,MAAA,EAAoD;AAC7F,EAAA,MAAM,QAAA,GAAiBA,yBAAQ,cAAA,EAAe;AAE9C,EAAA,MAAM,SAAS,IAAA,CAAK;AAAA,IAClB,KAAK,MAAA,CAAO,aAAA;AAAA,IACZ,WAAA,EAAa,MAAA,CAAO,cAAA,IAAkB,MAAA,CAAO,aAAA;AAAA,IAC7C,eAAe,MAAA,CAAO,OAAA;AA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EACH;AACA,EAAA,OAAO,GAAA;AACT;;;ACxMA,eAAsB,sBAAA,CACpB,UACA,MAAA,EACqB;AACrB,EAAA,MAAM,OAAA,GAAU,MAAM,oBAAA,CAAqB;AAAA,IACzC,eAAe,MAAA,CAAO,aAAA;AAAA,IACtB,OAAA,EAAS,SAAS,OAAA,EAAQ;AAAA,IAC1B,SAAA,EAAW,SAAS,cAAA,EAAe;AAAA,IACnC,GAAI,OAAO,cAAA,KAAmB,MAAA,GAAY,EAAE,cAAA,EAAgB,MAAA,CAAO,cAAA,EAAe,GAAI,EAAC;AAAA,IACvF,GAAI,OAAO,YAAA,KAAiB,MAAA,GAAY,EAAE,YAAA,EAAc,MAAA,CAAO,YAAA,EAAa,GAAI,EAAC;AAAA,IACjF,GAAI,OAAO,WAAA,KAAgB,MAAA,GAAY,EAAE,WAAA,EAAa,MAAA,CAAO,WAAA,EAAY,GAAI;AAAC,GAC/E,CAAA;AACD,EAAA,OAAO,WAAW,EAAE,OAAA,EAAS,aAAA,EAAe,MAAA,CAAO,eAAe,CAAA;AACpE;;;AC/BO,IAAM,YAAA,GAAe;AACrB,IAAM,eAAA,GAAkB","file":"index.cjs","sourcesContent":["/**\n * Build candidate keys for fallback lookup.\n *\n * Lookup order (first match wins):\n * 1. resources.<name>.<key> — resource-specific\n * 2. resources._.<key> — base for all resources\n * 3. common.<key> — global common\n * 4. <key> — raw fallback (debug only)\n *\n * If `key` is already namespaced (starts with `resources.`, `enums.` or\n * `common.`), return it as-is without further scoping.\n */\nexport function resolveKey(key: string, resource?: string): string[] {\n if (!key) return [];\n\n // Already namespaced — return as-is. `enums.` is a first-class top-level\n // namespace (global enum labels), like `resources.` and `common.`.\n if (key.startsWith('resources.') || key.startsWith('enums.') || key.startsWith('common.')) {\n return [key];\n }\n\n const candidates: string[] = [];\n if (resource) {\n candidates.push(`resources.${resource}.${key}`);\n }\n candidates.push(`resources._.${key}`);\n candidates.push(`common.${key}`);\n candidates.push(key); // raw fallback for warnings\n return candidates;\n}\n","import i18next, { type FallbackLng, type i18n } from 'i18next';\nimport type { I18nAdapter, TranslationBundle } from './types/index.js';\n\nexport interface I18nextAdapterConfig {\n defaultLocale: string;\n locales: string[];\n resources?: Record<string, Record<string, TranslationBundle>>;\n /**\n * A single fallback locale (`'en'`) applies uniformly to every locale. A\n * `fr → en` fallback for one locale but not another needs i18next's own\n * per-locale chain shape instead — `{ fr: ['en'], default: ['en'] }` — so\n * this accepts i18next's full `FallbackLng` type rather than just `string`.\n * The chain is entirely CONFIG: nothing in this adapter special-cases any\n * particular locale code, here or anywhere else.\n */\n fallbackLocale?: FallbackLng;\n keySeparator?: string | false;\n nsSeparator?: string | false;\n}\n\n/**\n * Default I18nAdapter implementation backed by i18next.\n * Each top-level key in resources becomes a separate i18next namespace\n * (e.g. 'common', 'resources').\n */\nexport async function createI18nextAdapter(config: I18nextAdapterConfig): Promise<I18nAdapter> {\n const instance: i18n = i18next.createInstance();\n\n await instance.init({\n lng: config.defaultLocale,\n fallbackLng: config.fallbackLocale ?? config.defaultLocale,\n supportedLngs: config.locales,\n resources: config.resources,\n keySeparator: config.keySeparator ?? '.',\n // Qualified Buro entity refs use `namespace:id`. Resource keys flow\n // through `resources.<ref>.<key>`, so treating ':' as i18next's namespace\n // separator would split a valid ref before our explicit `ns` routing gets\n // to resolve it.\n nsSeparator: config.nsSeparator ?? false,\n defaultNS: 'common',\n interpolation: { escapeValue: false },\n returnNull: false,\n });\n\n return {\n t(key, params) {\n const dotIdx = key.indexOf('.');\n if (dotIdx === -1) {\n return instance.t(key, params) as string;\n }\n const ns = key.substring(0, dotIdx);\n const subKey = key.substring(dotIdx + 1);\n const result = instance.t(subKey, { ns, ...(params ?? {}) }) as string;\n // i18next returns the bare subKey when missing — restore the full key as fallback\n if (result === subKey && !instance.exists(subKey, { ns })) {\n return key;\n }\n return result;\n },\n async changeLocale(locale) {\n await instance.changeLanguage(locale);\n },\n async loadNamespace(namespace, _locale) {\n await instance.loadNamespaces(namespace);\n },\n getCurrentLocale() {\n return instance.language;\n },\n onLocaleChange(cb) {\n instance.on('languageChanged', cb);\n return () => instance.off('languageChanged', cb);\n },\n hasKey(key) {\n const dotIdx = key.indexOf('.');\n const ns = dotIdx === -1 ? undefined : key.substring(0, dotIdx);\n const subKey = dotIdx === -1 ? key : key.substring(dotIdx + 1);\n const opts = ns === undefined ? undefined : { ns };\n if (!instance.exists(subKey, opts)) return false;\n /*\n `exists()` alone is not enough, and the gap is the root cause of a whole\n family of bugs rather than a curiosity.\n\n i18next answers `exists()` with TRUE for an OBJECT node — `fields.gtin`\n once that entry is promoted from a plain string to `{ label, doc }`,\n `enums.<ns>.<value>` when it carries a `doc` but no `label`, and so on.\n `t()` on such a node neither throws nor returns the key: it returns the\n literal sentence\n\n key '…' returned an object instead of string.\n\n Since `resolveContentSlot` commits to the FIRST key whose `has()` is\n true, every resolver built on it — field labels, enum labels, nav\n labels, tab captions — would render that sentence to the user. No crash,\n no warning, just wrong text on screen. It was found three separate times\n in three separate resolvers before being fixed here, once.\n\n So `has` now means what its callers always assumed: there is a USABLE\n STRING at this key. Non-object primitives stay truthy, leaving plural\n forms and numeric values behaving exactly as before.\n */\n const value = instance.t(subKey, { ...(opts ?? {}), returnObjects: true }) as unknown;\n return typeof value !== 'object' || value === null;\n },\n };\n}\n","import { resolveKey } from './lookup.js';\nimport type { I18nAdapter } from './types/index.js';\n\nexport interface I18nFacade {\n t: (key: string, options?: { resource?: string; params?: Record<string, unknown> }) => string;\n /**\n * True when a translation for `key` EXISTS (through the same candidate chain\n * as {@link I18nFacade.t}). Distinct from `t`, which returns the raw key on a\n * miss — the content model probes presence with `has` to tell \"no bundle\n * entry\" (render nothing) from \"bundle entry === key text\".\n */\n has: (key: string, options?: { resource?: string }) => boolean;\n changeLocale: (locale: string) => Promise<void>;\n getCurrentLocale: () => string;\n /**\n * Subscribe to active-locale changes. Returns an unsubscribe fn. When the\n * adapter can't notify, this is a no-op subscription (returns an unsubscribe\n * that does nothing) — the live language switch then falls back to a static\n * read. Consumed by `useLocale()` via `useSyncExternalStore`.\n */\n onLocaleChange: (cb: () => void) => () => void;\n loadNamespace: (namespace: string, locale: string) => Promise<void>;\n adapter: I18nAdapter;\n}\n\nexport interface CreateI18nConfig {\n adapter: I18nAdapter;\n warnOnMissing?: boolean;\n}\n\nexport function createI18n(config: CreateI18nConfig): I18nFacade {\n const { adapter, warnOnMissing = true } = config;\n\n return {\n t(key, options) {\n const candidates = resolveKey(key, options?.resource);\n for (const candidate of candidates) {\n if (adapter.hasKey(candidate)) {\n return adapter.t(candidate, options?.params);\n }\n }\n if (warnOnMissing && typeof console !== 'undefined') {\n console.warn(\n `[@burojs/i18n-core] Missing translation: '${key}'${options?.resource ? ` (resource: ${options.resource})` : ''}`,\n );\n }\n return key;\n },\n has(key, options) {\n return resolveKey(key, options?.resource).some((candidate) => adapter.hasKey(candidate));\n },\n async changeLocale(locale) {\n await adapter.changeLocale(locale);\n },\n getCurrentLocale() {\n return adapter.getCurrentLocale();\n },\n onLocaleChange(cb) {\n return adapter.onLocaleChange?.(cb) ?? (() => {});\n },\n async loadNamespace(namespace, locale) {\n await adapter.loadNamespace(namespace, locale);\n },\n adapter,\n };\n}\n","import type { I18nFacade } from './i18n.js';\n\nexport interface ResourceI18n {\n t: (key: string, options?: { resource?: string; params?: Record<string, unknown> }) => string;\n changeLocale: (locale: string) => Promise<void>;\n getCurrentLocale: () => string;\n resource: string;\n}\n\n/**\n * Wraps an I18nFacade with a default resource scope.\n * `t('actions.delete')` will lookup `resources.<resource>.actions.delete` first.\n * Pass an explicit `resource` option to override the default scope.\n */\nexport function createResourceI18n(i18n: I18nFacade, resource: string): ResourceI18n {\n return {\n t(key, options) {\n return i18n.t(key, {\n resource: options?.resource ?? resource,\n params: options?.params,\n });\n },\n changeLocale: i18n.changeLocale,\n getCurrentLocale: i18n.getCurrentLocale,\n resource,\n };\n}\n","import type { TranslationBundle } from './types/bundle.js';\n\n/**\n * One package/app/domain module's offering for one locale.\n *\n * A contribution is data, not code: nothing about `createI18nextAdapter`'s\n * `resources` shape is visible here, and nothing here names a fixed set of\n * locale codes or counts them. `locale` is whatever the file/module that\n * produced this contribution says it is — the registry never validates it\n * against a known list, because there is no known list. That is the whole\n * point: a twenty-first language is a twenty-first contribution, not a\n * twenty-first `case`.\n */\nexport interface LocaleContribution {\n /** Locale code this contribution provides strings for (e.g. 'en', 'es', 'fr'). */\n locale: string;\n /**\n * i18next namespace the bundle merges into. Defaults to `'common'` — the\n * same default namespace `createI18nextAdapter` uses.\n */\n namespace?: string;\n /**\n * Declared merge priority. On a key collision within the same\n * (locale, namespace), the contribution with the HIGHER priority wins —\n * not whichever happened to register last. Ties fall back to registration\n * order (last registered wins), which is why two genuinely competing\n * sources must declare distinct priorities rather than relying on the tie\n * break.\n */\n priority: number;\n /**\n * Where this contribution came from — a package name, `'app'`, an enum\n * module name. Diagnostic only (surfaced by {@link LocaleRegistry.contributions}\n * for debugging a collision); never branched on.\n */\n source: string;\n bundle: TranslationBundle;\n}\n\nexport interface LocaleRegistry {\n /** Add one contribution. Order of registration does not matter for the merge result — only `priority` does (see {@link LocaleContribution.priority}). */\n register(contribution: LocaleContribution): void;\n /**\n * Every locale code that has at least one contribution, sorted. Derived\n * purely from what was registered — nothing enumerates or counts locales\n * anywhere else in this module.\n */\n locales(): string[];\n /** Every namespace that has at least one contribution, sorted. */\n namespaces(): string[];\n /** All registered contributions, in registration order. For diagnostics/tests. */\n contributions(): readonly LocaleContribution[];\n /**\n * Assemble `{ [locale]: { [namespace]: TranslationBundle } }`, ready to\n * pass straight as `createI18nextAdapter`'s `resources` config. Within one\n * (locale, namespace) group, contributions are deep-merged in ascending\n * priority order, so a higher-priority contribution's leaves win over a\n * lower-priority one's on any overlapping key while leaving the rest of\n * the lower-priority bundle intact.\n */\n buildResources(): Record<string, Record<string, TranslationBundle>>;\n}\n\nconst DEFAULT_NAMESPACE = 'common';\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Recursively merge `overlay` onto `base`. Arrays and primitives are replaced\n * wholesale (a `TranslationBundle` array leaf — see that type's own comment\n * on why arrays are a real leaf shape — is not index-merged: the whole array\n * is the unit an overlay replaces). Plain objects merge key by key.\n */\nfunction mergeBundle(base: TranslationBundle, overlay: TranslationBundle): TranslationBundle {\n const out: Record<string, unknown> = { ...base };\n for (const [key, overlayValue] of Object.entries(overlay)) {\n const baseValue = out[key];\n out[key] =\n isPlainObject(baseValue) && isPlainObject(overlayValue)\n ? mergeBundle(baseValue as TranslationBundle, overlayValue as TranslationBundle)\n : overlayValue;\n }\n return out as TranslationBundle;\n}\n\nexport function createLocaleRegistry(): LocaleRegistry {\n const registered: LocaleContribution[] = [];\n\n return {\n register(contribution) {\n registered.push(contribution);\n },\n locales() {\n return Array.from(new Set(registered.map((c) => c.locale))).sort();\n },\n namespaces() {\n return Array.from(new Set(registered.map((c) => c.namespace ?? DEFAULT_NAMESPACE))).sort();\n },\n contributions() {\n return registered;\n },\n buildResources() {\n // Group by (locale, namespace) via NESTED maps rather than a\n // delimiter-joined composite string key. A locale or namespace code is\n // caller-supplied and unconstrained (see `LocaleContribution.locale`'s\n // own comment), so any single-character delimiter is a value that\n // *could* collide with real content; nested `Map`s need no delimiter\n // at all, so there is nothing to collide with and nothing unusual\n // embedded in this file's source for a diff tool to trip over.\n const byLocale = new Map<string, Map<string, LocaleContribution[]>>();\n for (const contribution of registered) {\n const namespace = contribution.namespace ?? DEFAULT_NAMESPACE;\n let byNamespace = byLocale.get(contribution.locale);\n if (!byNamespace) {\n byNamespace = new Map<string, LocaleContribution[]>();\n byLocale.set(contribution.locale, byNamespace);\n }\n const group = byNamespace.get(namespace);\n if (group) {\n group.push(contribution);\n } else {\n byNamespace.set(namespace, [contribution]);\n }\n }\n\n const resources: Record<string, Record<string, TranslationBundle>> = {};\n for (const [locale, byNamespace] of byLocale) {\n const namespaces: Record<string, TranslationBundle> = {};\n for (const [namespace, group] of byNamespace) {\n // Stable sort ascending by priority: lower priority applied first,\n // higher priority applied last so it wins the overlapping leaves.\n // `Array#sort` is stable per spec (ES2019+), so contributions with\n // equal priority keep their registration order — last-registered\n // wins ONLY within a tie, never across a declared priority gap.\n const ordered = [...group].sort((a, b) => a.priority - b.priority);\n let merged: TranslationBundle = {};\n for (const contribution of ordered) {\n merged = mergeBundle(merged, contribution.bundle);\n }\n namespaces[namespace] = merged;\n }\n resources[locale] = namespaces;\n }\n return resources;\n },\n };\n}\n\n/**\n * A bundler-produced glob module, as `import.meta.glob` (Vite) or an\n * equivalent walk over `require.context` (webpack) would yield it: a flat\n * map of path → either the loaded module itself or `{ default }`.\n *\n * Bundler-agnostic on purpose, same reasoning as `@burojs/core`'s\n * `docsFromGlob`: no bundler-agnostic glob primitive exists, and a published\n * package must not require one — the ADOPTER calls `import.meta.glob` (or\n * whatever their bundler offers) and hands the plain object here.\n */\nexport type LocaleGlobModule = TranslationBundle | { default: TranslationBundle };\n\nexport interface LocaleContributionsFromGlobOptions {\n /** {@link LocaleContribution.source} for every contribution produced. */\n source: string;\n /** {@link LocaleContribution.priority} for every contribution produced. */\n priority: number;\n /** {@link LocaleContribution.namespace}. Defaults to `'common'`. */\n namespace?: string;\n /**\n * Extracts the locale code from a glob path. Default matches a bare\n * `<locale>.ts`/`<locale>.tsx`/`<locale>.js` filename (`'./locales/en.ts'`\n * → `'en'`, `'./locales/fr-CA.ts'` → `'fr-CA'`) — no restriction to a\n * known set of codes; whatever the filename says IS the locale code. Paths\n * that don't match are skipped rather than guessed at (same discipline as\n * `docsFromGlob`).\n */\n localeOf?: (path: string) => string | undefined;\n}\n\nconst DEFAULT_LOCALE_PATTERN = /(?:^|\\/)([A-Za-z0-9-]+)\\.(?:ts|tsx|js|jsx|mjs|cjs)$/;\n\nfunction defaultLocaleOf(path: string): string | undefined {\n return DEFAULT_LOCALE_PATTERN.exec(path)?.[1];\n}\n\n/**\n * Normalize a bundler glob of per-locale files into {@link LocaleContribution}s.\n * One file → one locale → one contribution. Nothing here enumerates or counts\n * locale codes: whatever files are present in the globbed directory at build\n * time ARE the contributions produced — dropping in a new file is the entire\n * mechanism for adding a language.\n */\nexport function localeContributionsFromGlob(\n glob: Record<string, LocaleGlobModule>,\n options: LocaleContributionsFromGlobOptions,\n): LocaleContribution[] {\n const localeOf = options.localeOf ?? defaultLocaleOf;\n const out: LocaleContribution[] = [];\n for (const [path, mod] of Object.entries(glob)) {\n const locale = localeOf(path);\n if (locale === undefined) continue;\n // Eager `import.meta.glob` yields a module namespace object — always\n // `{ default, ...named exports }` for a file that does `export default\n // {...}`. Unwrap it when present; otherwise trust the glob already\n // handed a bare bundle (e.g. a caller that pre-unwrapped, or a\n // require.context-style walk that returns exports directly).\n const bundle = isPlainObject((mod as { default?: unknown }).default)\n ? (mod as { default: TranslationBundle }).default\n : (mod as TranslationBundle);\n out.push({\n locale,\n priority: options.priority,\n source: options.source,\n bundle,\n ...(options.namespace !== undefined ? { namespace: options.namespace } : {}),\n });\n }\n return out;\n}\n","import { type I18nFacade, createI18n } from './i18n.js';\nimport { type I18nextAdapterConfig, createI18nextAdapter } from './i18next-adapter.js';\nimport type { LocaleRegistry } from './locale-registry.js';\n\nexport type CreateI18nFromRegistryConfig = Pick<\n I18nextAdapterConfig,\n 'defaultLocale' | 'fallbackLocale' | 'keySeparator' | 'nsSeparator'\n> & {\n warnOnMissing?: boolean;\n};\n\n/**\n * Wires a {@link LocaleRegistry} straight into `createI18nextAdapter` +\n * `createI18n`: `registry.locales()` becomes the adapter's `locales`,\n * `registry.buildResources()` becomes its `resources`. This is the ONLY\n * place those two need to be threaded together — an app that builds its own\n * registry never re-lists its locale codes to hand them to the adapter, it\n * just calls this.\n */\nexport async function createI18nFromRegistry(\n registry: LocaleRegistry,\n config: CreateI18nFromRegistryConfig,\n): Promise<I18nFacade> {\n const adapter = await createI18nextAdapter({\n defaultLocale: config.defaultLocale,\n locales: registry.locales(),\n resources: registry.buildResources(),\n ...(config.fallbackLocale !== undefined ? { fallbackLocale: config.fallbackLocale } : {}),\n ...(config.keySeparator !== undefined ? { keySeparator: config.keySeparator } : {}),\n ...(config.nsSeparator !== undefined ? { nsSeparator: config.nsSeparator } : {}),\n });\n return createI18n({ adapter, warnOnMissing: config.warnOnMissing });\n}\n","// Constants\nexport const PACKAGE_NAME = '@burojs/i18n-core' as const;\nexport const PACKAGE_VERSION = '0.0.0' as const;\n\n// Types\nexport type * from './types/index.js';\n\n// Lookup\nexport { resolveKey } from './lookup.js';\n\n// i18next adapter\nexport { createI18nextAdapter, type I18nextAdapterConfig } from './i18next-adapter.js';\n\n// I18n facade\nexport { createI18n, type I18nFacade, type CreateI18nConfig } from './i18n.js';\n\n// Resource context\nexport { createResourceI18n, type ResourceI18n } from './resource-context.js';\n\n// Locale registry — assembling locales from what has REGISTERED (framework\n// packages, the app, domain enum modules) instead of a hand-printed literal.\nexport {\n createLocaleRegistry,\n localeContributionsFromGlob,\n type LocaleContribution,\n type LocaleContributionsFromGlobOptions,\n type LocaleGlobModule,\n type LocaleRegistry,\n} from './locale-registry.js';\nexport {\n createI18nFromRegistry,\n type CreateI18nFromRegistryConfig,\n} from './create-i18n-from-registry.js';\n"]}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/lookup.ts","../src/i18next-adapter.ts","../src/i18n.ts","../src/resource-context.ts","../src/locale-registry.ts","../src/create-i18n-from-registry.ts","../src/index.ts"],"sourcesContent":["/**\n * Build candidate keys for fallback lookup.\n *\n * Lookup order (first match wins):\n * 1. resources.<name>.<key> — resource-specific\n * 2. resources._.<key> — base for all resources\n * 3. common.<key> — global common\n * 4. <key> — raw fallback (debug only)\n *\n * If `key` is already namespaced (starts with `resources.`, `enums.`,\n * `common.` or `blocks.`), return it as-is without further scoping.\n */\nexport function resolveKey(key: string, resource?: string): string[] {\n if (!key) return [];\n\n // Already namespaced — return as-is. `enums.` is a first-class top-level\n // namespace (global enum labels), like `resources.` and `common.`; so is\n // `blocks.` (a block view's `t` reads `blocks.<id>.<key>`).\n if (\n key.startsWith('resources.') ||\n key.startsWith('enums.') ||\n key.startsWith('common.') ||\n key.startsWith('blocks.')\n ) {\n return [key];\n }\n\n const candidates: string[] = [];\n if (resource) {\n candidates.push(`resources.${resource}.${key}`);\n }\n candidates.push(`resources._.${key}`);\n candidates.push(`common.${key}`);\n candidates.push(key); // raw fallback for warnings\n return candidates;\n}\n","import i18next, { type FallbackLng, type i18n } from 'i18next';\nimport type { I18nAdapter, TranslationBundle } from './types/index.js';\n\n/** What a lookup answers when no locale in the chain holds a usable value. */\nconst MISSING = '\\u0000';\n\nexport interface I18nextAdapterConfig {\n defaultLocale: string;\n locales: string[];\n resources?: Record<string, Record<string, TranslationBundle>>;\n /**\n * A single fallback locale (`'en'`) applies uniformly to every locale. A\n * `fr → en` fallback for one locale but not another needs i18next's own\n * per-locale chain shape instead — `{ fr: ['en'], default: ['en'] }` — so\n * this accepts i18next's full `FallbackLng` type rather than just `string`.\n * The chain is entirely CONFIG: nothing in this adapter special-cases any\n * particular locale code, here or anywhere else.\n */\n fallbackLocale?: FallbackLng;\n keySeparator?: string | false;\n nsSeparator?: string | false;\n}\n\n/**\n * Default I18nAdapter implementation backed by i18next.\n * Each top-level key in resources becomes a separate i18next namespace\n * (e.g. 'common', 'resources').\n */\nexport async function createI18nextAdapter(config: I18nextAdapterConfig): Promise<I18nAdapter> {\n const instance: i18n = i18next.createInstance();\n\n await instance.init({\n lng: config.defaultLocale,\n fallbackLng: config.fallbackLocale ?? config.defaultLocale,\n supportedLngs: config.locales,\n resources: config.resources,\n keySeparator: config.keySeparator ?? '.',\n // Qualified Buro entity refs use `namespace:id`. Resource keys flow\n // through `resources.<ref>.<key>`, so treating ':' as i18next's namespace\n // separator would split a valid ref before our explicit `ns` routing gets\n // to resolve it.\n nsSeparator: config.nsSeparator ?? false,\n defaultNS: 'common',\n interpolation: { escapeValue: false },\n returnNull: false,\n // An empty string is an untranslated key (what extraction tools write), not\n // a translation: `exists` and `t` walk on to the fallback locale, then the\n // caller's code default, so a label never renders blank.\n returnEmptyString: false,\n });\n\n return {\n t(key, params) {\n const dotIdx = key.indexOf('.');\n if (dotIdx === -1) {\n return instance.t(key, params) as string;\n }\n const ns = key.substring(0, dotIdx);\n const subKey = key.substring(dotIdx + 1);\n const result = instance.t(subKey, { ns, ...(params ?? {}) }) as string;\n // i18next returns the bare subKey when missing — restore the full key as\n // fallback. The probe carries the count, so a resolved count family is\n // not mistaken for a miss.\n const count = typeof params?.count === 'number' ? params.count : undefined;\n if (\n result === subKey &&\n !instance.exists(subKey, count === undefined ? { ns } : { ns, count })\n ) {\n return key;\n }\n return result;\n },\n async changeLocale(locale) {\n await instance.changeLanguage(locale);\n },\n async loadNamespace(namespace, _locale) {\n await instance.loadNamespaces(namespace);\n },\n getCurrentLocale() {\n return instance.language;\n },\n onLocaleChange(cb) {\n instance.on('languageChanged', cb);\n return () => instance.off('languageChanged', cb);\n },\n hasKey(key, options) {\n const dotIdx = key.indexOf('.');\n const ns = dotIdx === -1 ? undefined : key.substring(0, dotIdx);\n const subKey = dotIdx === -1 ? key : key.substring(dotIdx + 1);\n const lookup = {\n ...(ns === undefined ? {} : { ns }),\n ...(options?.count === undefined ? {} : { count: options.count }),\n };\n /*\n `exists()` is not enough, and the gap is the root cause of a whole\n family of bugs rather than a curiosity.\n\n i18next answers `exists()` with TRUE for an OBJECT node — `fields.gtin`\n once that entry is promoted from a plain string to `{ label, doc }`,\n `enums.<ns>.<value>` when it carries a `doc` but no `label`, and so on.\n `t()` on such a node neither throws nor returns the key: it returns the\n literal sentence\n\n key '…' returned an object instead of string.\n\n Since `resolveContentSlot` commits to the FIRST key whose `has()` is\n true, every resolver built on it — field labels, enum labels, nav\n labels, tab captions — would render that sentence to the user. No crash,\n no warning, just wrong text on screen. It was found three separate times\n in three separate resolvers before being fixed here, once.\n\n `exists()` is also TRUE for an empty string in the last locale of the\n chain, even with `returnEmptyString: false`. So the lookup itself is the\n probe: `t()` walks the whole chain (count forms included) and answers the\n sentinel default only when no locale holds a usable value.\n\n So `has` means what its callers always assumed: there is a USABLE,\n non-empty STRING at this key. Non-object primitives stay truthy, leaving\n plural forms and numeric values behaving exactly as before.\n */\n const value = instance.t(subKey, {\n ...lookup,\n returnObjects: true,\n defaultValue: MISSING,\n }) as unknown;\n return value !== MISSING && (typeof value !== 'object' || value === null);\n },\n };\n}\n","import { resolveKey } from './lookup.js';\nimport type { I18nAdapter } from './types/index.js';\n\nexport interface I18nFacade {\n /**\n * Translate `key` through the candidate chain. `count` selects a count\n * family's form (`<key>_one | _few | _many | _other`, by the locale's CLDR\n * rules) and interpolates `{{count}}`; a family asked without a count is\n * missing. A `count` inside `params` only interpolates.\n */\n t: (\n key: string,\n options?: { resource?: string; params?: Record<string, unknown>; count?: number },\n ) => string;\n /**\n * True when a translation for `key` EXISTS (through the same candidate chain\n * as {@link I18nFacade.t}). Distinct from `t`, which returns the raw key on a\n * miss — the content model probes presence with `has` to tell \"no bundle\n * entry\" (render nothing) from \"bundle entry === key text\". Pass `count` to probe a count family.\n */\n has: (key: string, options?: { resource?: string; count?: number }) => boolean;\n changeLocale: (locale: string) => Promise<void>;\n getCurrentLocale: () => string;\n /**\n * Subscribe to active-locale changes. Returns an unsubscribe fn. When the\n * adapter can't notify, this is a no-op subscription (returns an unsubscribe\n * that does nothing) — the live language switch then falls back to a static\n * read. Consumed by `useLocale()` via `useSyncExternalStore`.\n */\n onLocaleChange: (cb: () => void) => () => void;\n loadNamespace: (namespace: string, locale: string) => Promise<void>;\n /**\n * The locale codes this app can switch to. Optional: a facade built without\n * a list (a hand-rolled one, a test double) simply does not say, and a\n * language control then offers only the active locale. `createI18nFromRegistry`\n * fills it from the registry.\n */\n locales?: () => readonly string[];\n adapter: I18nAdapter;\n}\n\nexport interface CreateI18nConfig {\n adapter: I18nAdapter;\n warnOnMissing?: boolean;\n /** The switchable locale codes, exposed as {@link I18nFacade.locales}. */\n locales?: () => readonly string[];\n}\n\nexport function createI18n(config: CreateI18nConfig): I18nFacade {\n const { adapter, warnOnMissing = true, locales } = config;\n\n return {\n t(key, options) {\n // `count` is the one spelling: a `count` inside `params` only interpolates.\n const count = options?.count;\n const params = count === undefined ? options?.params : { ...options?.params, count };\n const candidates = resolveKey(key, options?.resource);\n for (const candidate of candidates) {\n const present =\n count === undefined ? adapter.hasKey(candidate) : adapter.hasKey(candidate, { count });\n if (present) {\n return adapter.t(candidate, params);\n }\n }\n if (warnOnMissing && typeof console !== 'undefined') {\n console.warn(\n `[@burojs/i18n-core] Missing translation: '${key}'${options?.resource ? ` (resource: ${options.resource})` : ''}`,\n );\n }\n return key;\n },\n has(key, options) {\n const count = options?.count;\n return resolveKey(key, options?.resource).some((candidate) =>\n count === undefined ? adapter.hasKey(candidate) : adapter.hasKey(candidate, { count }),\n );\n },\n async changeLocale(locale) {\n await adapter.changeLocale(locale);\n },\n getCurrentLocale() {\n return adapter.getCurrentLocale();\n },\n onLocaleChange(cb) {\n return adapter.onLocaleChange?.(cb) ?? (() => {});\n },\n async loadNamespace(namespace, locale) {\n await adapter.loadNamespace(namespace, locale);\n },\n ...(locales === undefined ? {} : { locales }),\n adapter,\n };\n}\n","import type { I18nFacade } from './i18n.js';\n\nexport interface ResourceI18n {\n t: (\n key: string,\n options?: { resource?: string; params?: Record<string, unknown>; count?: number },\n ) => string;\n changeLocale: (locale: string) => Promise<void>;\n getCurrentLocale: () => string;\n resource: string;\n}\n\n/**\n * Wraps an I18nFacade with a default resource scope.\n * `t('actions.delete')` will lookup `resources.<resource>.actions.delete` first.\n * Pass an explicit `resource` option to override the default scope.\n */\nexport function createResourceI18n(i18n: I18nFacade, resource: string): ResourceI18n {\n return {\n t(key, options) {\n return i18n.t(key, {\n resource: options?.resource ?? resource,\n params: options?.params,\n ...(options?.count === undefined ? {} : { count: options.count }),\n });\n },\n changeLocale: i18n.changeLocale,\n getCurrentLocale: i18n.getCurrentLocale,\n resource,\n };\n}\n","import type { TranslationBundle } from './types/bundle.js';\n\n/**\n * One package/app/domain module's offering for one locale.\n *\n * A contribution is data, not code: nothing about `createI18nextAdapter`'s\n * `resources` shape is visible here, and nothing here names a fixed set of\n * locale codes or counts them. `locale` is whatever the file/module that\n * produced this contribution says it is — the registry never validates it\n * against a known list, because there is no known list. That is the whole\n * point: a twenty-first language is a twenty-first contribution, not a\n * twenty-first `case`.\n */\nexport interface LocaleContribution {\n /** Locale code this contribution provides strings for (e.g. 'en', 'es', 'fr'). */\n locale: string;\n /**\n * i18next namespace the bundle merges into. Defaults to `'common'` — the\n * same default namespace `createI18nextAdapter` uses.\n */\n namespace?: string;\n /**\n * Declared merge priority. On a key collision within the same\n * (locale, namespace), the contribution with the HIGHER priority wins —\n * not whichever happened to register last. Ties fall back to registration\n * order (last registered wins), which is why two genuinely competing\n * sources must declare distinct priorities rather than relying on the tie\n * break.\n */\n priority: number;\n /**\n * Where this contribution came from — a package name, `'app'`, an enum\n * module name. Diagnostic only (surfaced by {@link LocaleRegistry.contributions}\n * for debugging a collision); never branched on.\n */\n source: string;\n bundle: TranslationBundle;\n}\n\nexport interface LocaleRegistry {\n /**\n * The primary locale, as declared to {@link createLocaleRegistry}: the one\n * whose text is the default in code, and the locale every other one falls\n * back to. The single source of truth for it — `createI18nFromRegistry`\n * defaults both the starting locale and the fallback to it, and\n * `@burojs/testing`'s `checkApp` reads it to know which locale is exempt\n * from `i18n.missing`. Never derived from contributions or their order.\n */\n primary(): string;\n /** Add one contribution. Order of registration does not matter for the merge result — only `priority` does (see {@link LocaleContribution.priority}). */\n register(contribution: LocaleContribution): void;\n /**\n * Every locale code that has at least one contribution, sorted. Derived\n * purely from what was registered — nothing enumerates or counts locales\n * anywhere else in this module.\n */\n locales(): string[];\n /** Every namespace that has at least one contribution, sorted. */\n namespaces(): string[];\n /** All registered contributions, in registration order. For diagnostics/tests. */\n contributions(): readonly LocaleContribution[];\n /**\n * Assemble `{ [locale]: { [namespace]: TranslationBundle } }`, ready to\n * pass straight as `createI18nextAdapter`'s `resources` config. Within one\n * (locale, namespace) group, contributions are deep-merged in ascending\n * priority order, so a higher-priority contribution's leaves win over a\n * lower-priority one's on any overlapping key while leaving the rest of\n * the lower-priority bundle intact.\n *\n * Throws when no contribution is registered for {@link primary}: a\n * fallback chain that ends at a locale with no bundle, and a primary that\n * `locales()` (and so every language switcher built from it) does not\n * list, is a misconfiguration (usually a typo, `'en-US'` for `'en'`, or a\n * glob that missed its file), not a state to render. An app that really\n * has no strings for its primary locale registers an empty bundle for it.\n */\n buildResources(): Record<string, Record<string, TranslationBundle>>;\n}\n\nconst DEFAULT_NAMESPACE = 'common';\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Recursively merge `overlay` onto `base`. Arrays and primitives are replaced\n * wholesale (a `TranslationBundle` array leaf — see that type's own comment\n * on why arrays are a real leaf shape — is not index-merged: the whole array\n * is the unit an overlay replaces). Plain objects merge key by key.\n */\nfunction mergeBundle(base: TranslationBundle, overlay: TranslationBundle): TranslationBundle {\n const out: Record<string, unknown> = { ...base };\n for (const [key, overlayValue] of Object.entries(overlay)) {\n const baseValue = out[key];\n out[key] =\n isPlainObject(baseValue) && isPlainObject(overlayValue)\n ? mergeBundle(baseValue as TranslationBundle, overlayValue as TranslationBundle)\n : overlayValue;\n }\n return out as TranslationBundle;\n}\n\nexport interface LocaleRegistryOptions {\n /**\n * The primary locale: the one whose text is the default in code. Required,\n * and declared here rather than inferred, because nothing in the\n * contributions says which locale it is — registration order and the\n * sorted `locales()` both carry no meaning.\n */\n primary: string;\n}\n\nexport function createLocaleRegistry(options: LocaleRegistryOptions): LocaleRegistry {\n const primary = (options as Partial<LocaleRegistryOptions> | undefined)?.primary;\n if (typeof primary !== 'string' || primary === '') {\n throw new TypeError(\n `createLocaleRegistry needs { primary }, the locale whose text is the default in code; received ${JSON.stringify(primary)}.`,\n );\n }\n const registered: LocaleContribution[] = [];\n\n return {\n primary() {\n return primary;\n },\n register(contribution) {\n registered.push(contribution);\n },\n locales() {\n return Array.from(new Set(registered.map((c) => c.locale))).sort();\n },\n namespaces() {\n return Array.from(new Set(registered.map((c) => c.namespace ?? DEFAULT_NAMESPACE))).sort();\n },\n contributions() {\n return registered;\n },\n buildResources() {\n if (!registered.some((c) => c.locale === primary)) {\n const known = Array.from(new Set(registered.map((c) => c.locale))).sort();\n throw new Error(\n `The locale registry's primary locale ${JSON.stringify(primary)} has no contribution` +\n ` (registered: ${known.length === 0 ? 'none' : known.join(', ')}). Register its bundle,` +\n ' an empty one if the app has no strings of its own, or declare the primary it does register.',\n );\n }\n // Group by (locale, namespace) via NESTED maps rather than a\n // delimiter-joined composite string key. A locale or namespace code is\n // caller-supplied and unconstrained (see `LocaleContribution.locale`'s\n // own comment), so any single-character delimiter is a value that\n // *could* collide with real content; nested `Map`s need no delimiter\n // at all, so there is nothing to collide with and nothing unusual\n // embedded in this file's source for a diff tool to trip over.\n const byLocale = new Map<string, Map<string, LocaleContribution[]>>();\n for (const contribution of registered) {\n const namespace = contribution.namespace ?? DEFAULT_NAMESPACE;\n let byNamespace = byLocale.get(contribution.locale);\n if (!byNamespace) {\n byNamespace = new Map<string, LocaleContribution[]>();\n byLocale.set(contribution.locale, byNamespace);\n }\n const group = byNamespace.get(namespace);\n if (group) {\n group.push(contribution);\n } else {\n byNamespace.set(namespace, [contribution]);\n }\n }\n\n const resources: Record<string, Record<string, TranslationBundle>> = {};\n for (const [locale, byNamespace] of byLocale) {\n const namespaces: Record<string, TranslationBundle> = {};\n for (const [namespace, group] of byNamespace) {\n // Stable sort ascending by priority: lower priority applied first,\n // higher priority applied last so it wins the overlapping leaves.\n // `Array#sort` is stable per spec (ES2019+), so contributions with\n // equal priority keep their registration order — last-registered\n // wins ONLY within a tie, never across a declared priority gap.\n const ordered = [...group].sort((a, b) => a.priority - b.priority);\n let merged: TranslationBundle = {};\n for (const contribution of ordered) {\n merged = mergeBundle(merged, contribution.bundle);\n }\n namespaces[namespace] = merged;\n }\n resources[locale] = namespaces;\n }\n return resources;\n },\n };\n}\n\n/**\n * A bundler-produced glob module, as `import.meta.glob` (Vite) or an\n * equivalent walk over `require.context` (webpack) would yield it: a flat\n * map of path → either the loaded module itself or `{ default }`.\n *\n * Bundler-agnostic on purpose, same reasoning as `@burojs/core`'s\n * `docsFromGlob`: no bundler-agnostic glob primitive exists, and a published\n * package must not require one — the ADOPTER calls `import.meta.glob` (or\n * whatever their bundler offers) and hands the plain object here.\n */\nexport type LocaleGlobModule = TranslationBundle | { default: TranslationBundle };\n\nexport interface LocaleContributionsFromGlobOptions {\n /** {@link LocaleContribution.source} for every contribution produced. */\n source: string;\n /** {@link LocaleContribution.priority} for every contribution produced. */\n priority: number;\n /** {@link LocaleContribution.namespace}. Defaults to `'common'`. */\n namespace?: string;\n /**\n * Extracts the locale code from a glob path. Default matches a bare\n * `<locale>.ts`/`<locale>.tsx`/`<locale>.js` filename (`'./locales/en.ts'`\n * → `'en'`, `'./locales/fr-CA.ts'` → `'fr-CA'`) — no restriction to a\n * known set of codes; whatever the filename says IS the locale code. Paths\n * that don't match are skipped rather than guessed at (same discipline as\n * `docsFromGlob`).\n */\n localeOf?: (path: string) => string | undefined;\n}\n\nconst DEFAULT_LOCALE_PATTERN = /(?:^|\\/)([A-Za-z0-9-]+)\\.(?:ts|tsx|js|jsx|mjs|cjs)$/;\n\nfunction defaultLocaleOf(path: string): string | undefined {\n return DEFAULT_LOCALE_PATTERN.exec(path)?.[1];\n}\n\n/**\n * Normalize a bundler glob of per-locale files into {@link LocaleContribution}s.\n * One file → one locale → one contribution. Nothing here enumerates or counts\n * locale codes: whatever files are present in the globbed directory at build\n * time ARE the contributions produced — dropping in a new file is the entire\n * mechanism for adding a language.\n */\nexport function localeContributionsFromGlob(\n glob: Record<string, LocaleGlobModule>,\n options: LocaleContributionsFromGlobOptions,\n): LocaleContribution[] {\n const localeOf = options.localeOf ?? defaultLocaleOf;\n const out: LocaleContribution[] = [];\n for (const [path, mod] of Object.entries(glob)) {\n const locale = localeOf(path);\n if (locale === undefined) continue;\n // Eager `import.meta.glob` yields a module namespace object — always\n // `{ default, ...named exports }` for a file that does `export default\n // {...}`. Unwrap it when present; otherwise trust the glob already\n // handed a bare bundle (e.g. a caller that pre-unwrapped, or a\n // require.context-style walk that returns exports directly).\n const bundle = isPlainObject((mod as { default?: unknown }).default)\n ? (mod as { default: TranslationBundle }).default\n : (mod as TranslationBundle);\n out.push({\n locale,\n priority: options.priority,\n source: options.source,\n bundle,\n ...(options.namespace !== undefined ? { namespace: options.namespace } : {}),\n });\n }\n return out;\n}\n","import { type I18nFacade, createI18n } from './i18n.js';\nimport { type I18nextAdapterConfig, createI18nextAdapter } from './i18next-adapter.js';\nimport type { LocaleRegistry } from './locale-registry.js';\n\nexport type CreateI18nFromRegistryConfig = Partial<\n Pick<I18nextAdapterConfig, 'defaultLocale' | 'fallbackLocale' | 'keySeparator' | 'nsSeparator'>\n> & {\n warnOnMissing?: boolean;\n};\n\n/**\n * Wires a {@link LocaleRegistry} straight into `createI18nextAdapter` +\n * `createI18n`: `registry.locales()` becomes the adapter's `locales`,\n * `registry.buildResources()` becomes its `resources`, and\n * `registry.primary()` is both the starting locale and the fallback unless\n * `defaultLocale` (the starting locale, say a stored choice) or\n * `fallbackLocale` (say a per-locale chain) overrides it. This is the ONLY\n * place those need to be threaded together — an app that builds its own\n * registry never re-lists its locale codes, or restates its primary locale,\n * to hand them to the adapter; it just calls this.\n *\n * Throws when the registry's primary locale has no contribution (see\n * {@link LocaleRegistry.buildResources}).\n */\nexport async function createI18nFromRegistry(\n registry: LocaleRegistry,\n config: CreateI18nFromRegistryConfig = {},\n): Promise<I18nFacade> {\n const resources = registry.buildResources();\n const primary = registry.primary();\n const adapter = await createI18nextAdapter({\n defaultLocale: config.defaultLocale ?? primary,\n locales: registry.locales(),\n resources,\n fallbackLocale: config.fallbackLocale ?? primary,\n ...(config.keySeparator !== undefined ? { keySeparator: config.keySeparator } : {}),\n ...(config.nsSeparator !== undefined ? { nsSeparator: config.nsSeparator } : {}),\n });\n return createI18n({\n adapter,\n warnOnMissing: config.warnOnMissing,\n locales: () => registry.locales(),\n });\n}\n","// Constants\nexport const PACKAGE_NAME = '@burojs/i18n-core' as const;\nexport const PACKAGE_VERSION = '0.0.0' as const;\n\n// Types\nexport type * from './types/index.js';\n\n// Lookup\nexport { resolveKey } from './lookup.js';\n\n// i18next adapter\nexport { createI18nextAdapter, type I18nextAdapterConfig } from './i18next-adapter.js';\n\n// I18n facade\nexport { createI18n, type I18nFacade, type CreateI18nConfig } from './i18n.js';\n\n// Resource context\nexport { createResourceI18n, type ResourceI18n } from './resource-context.js';\n\n// Locale registry — assembling locales from what has REGISTERED (framework\n// packages, the app, domain enum modules) instead of a hand-printed literal.\nexport {\n createLocaleRegistry,\n localeContributionsFromGlob,\n type LocaleContribution,\n type LocaleContributionsFromGlobOptions,\n type LocaleGlobModule,\n type LocaleRegistry,\n type LocaleRegistryOptions,\n} from './locale-registry.js';\nexport {\n createI18nFromRegistry,\n type CreateI18nFromRegistryConfig,\n} from './create-i18n-from-registry.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAgB,WAAW,KAAa,UAA6B;CACnE,IAAI,CAAC,KAAK,OAAO,CAAC;CAKlB,IACE,IAAI,WAAW,YAAY,KAC3B,IAAI,WAAW,QAAQ,KACvB,IAAI,WAAW,SAAS,KACxB,IAAI,WAAW,SAAS,GAExB,OAAO,CAAC,GAAG;CAGb,MAAM,aAAuB,CAAC;CAC9B,IAAI,UACF,WAAW,KAAK,aAAa,SAAS,GAAG,KAAK;CAEhD,WAAW,KAAK,eAAe,KAAK;CACpC,WAAW,KAAK,UAAU,KAAK;CAC/B,WAAW,KAAK,GAAG;CACnB,OAAO;AACT;;;AC/BA,MAAM,UAAU;AAwBhB,eAAsB,qBAAqB,QAAoD;CAC7F,MAAM,WAAiB,QAAA,QAAQ,eAAe;CAE9C,MAAM,SAAS,KAAK;EAClB,KAAK,OAAO;EACZ,aAAa,OAAO,kBAAkB,OAAO;EAC7C,eAAe,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C,MAAM,QAAQ,OAAO,QAAQ,IAAI,GAAG;EAC9C,MAAM,SAAS,SAAS,IAAI;EAC5B,IAAI,WAAW,KAAA,GAAW;EAM1B,MAAM,SAAS,cAAe,IAA8B,OAAO,IAC9D,IAAuC,UACvC;EACL,IAAI,KAAK;GACP;GACA,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GAChB;GACA,GAAI,QAAQ,cAAc,KAAA,IAAY,EAAE,WAAW,QAAQ,UAAU,IAAI,CAAC;EAC5E,CAAC;CACH;CACA,OAAO;AACT;;;AC9OA,eAAsB,uBACpB,UACA,SAAuC,CAAC,GACnB;CACrB,MAAM,YAAY,SAAS,eAAe;CAC1C,MAAM,UAAU,SAAS,QAAQ;CASjC,OAAO,WAAW;EAChB,eAToB,qBAAqB;GACzC,eAAe,OAAO,iBAAiB;GACvC,SAAS,SAAS,QAAQ;GAC1B;GACA,gBAAgB,OAAO,kBAAkB;GACzC,GAAI,OAAO,iBAAiB,KAAA,IAAY,EAAE,cAAc,OAAO,aAAa,IAAI,CAAC;GACjF,GAAI,OAAO,gBAAgB,KAAA,IAAY,EAAE,aAAa,OAAO,YAAY,IAAI,CAAC;EAChF,CAAC;EAGC,eAAe,OAAO;EACtB,eAAe,SAAS,QAAQ;CAClC,CAAC;AACH;;;AC1CA,MAAa,eAAe;AAC5B,MAAa,kBAAkB"}
package/dist/index.d.cts CHANGED
@@ -1,21 +1,30 @@
1
- import { FallbackLng } from 'i18next';
2
-
1
+ import { FallbackLng } from "i18next";
2
+ //#region src/types/adapter.d.ts
3
3
  interface I18nAdapter {
4
- t: (key: string, params?: Record<string, unknown>) => string;
5
- changeLocale: (locale: string) => Promise<void>;
6
- loadNamespace: (namespace: string, locale: string) => Promise<void>;
7
- getCurrentLocale: () => string;
8
- hasKey: (key: string) => boolean;
9
- /**
10
- * Subscribe to active-locale changes (fired by {@link I18nAdapter.changeLocale}).
11
- * Returns an unsubscribe fn. Optional — adapters that cannot notify omit it,
12
- * and the React layer then degrades to a non-reactive locale read. This is
13
- * what powers the live language switch (no page reload): `useLocale()` wires
14
- * it into `useSyncExternalStore`.
15
- */
16
- onLocaleChange?: (cb: () => void) => () => void;
4
+ t: (key: string, params?: Record<string, unknown>) => string;
5
+ changeLocale: (locale: string) => Promise<void>;
6
+ loadNamespace: (namespace: string, locale: string) => Promise<void>;
7
+ getCurrentLocale: () => string;
8
+ /**
9
+ * True when a USABLE STRING exists at `key` (an object node is not one).
10
+ * Pass `count` to ask about a count family (`<key>_one | _few | _many |
11
+ * _other`): i18next resolves the suffix only when it is asked with a count,
12
+ * so without one a present family reports missing.
13
+ */
14
+ hasKey: (key: string, options?: {
15
+ count?: number;
16
+ }) => boolean;
17
+ /**
18
+ * Subscribe to active-locale changes (fired by {@link I18nAdapter.changeLocale}).
19
+ * Returns an unsubscribe fn. Optional — adapters that cannot notify omit it,
20
+ * and the React layer then degrades to a non-reactive locale read. This is
21
+ * what powers the live language switch (no page reload): `useLocale()` wires
22
+ * it into `useSyncExternalStore`.
23
+ */
24
+ onLocaleChange?: (cb: () => void) => () => void;
17
25
  }
18
-
26
+ //#endregion
27
+ //#region src/types/bundle.d.ts
19
28
  /**
20
29
  * Recursive translation bundle: keys map to a string, a nested bundle, or an
21
30
  * ARRAY of either.
@@ -30,17 +39,18 @@ interface I18nAdapter {
30
39
  * the package that owns the type.
31
40
  */
32
41
  type TranslationBundle = {
33
- [key: string]: string | TranslationBundle | readonly (string | TranslationBundle)[];
42
+ [key: string]: string | TranslationBundle | readonly (string | TranslationBundle)[];
34
43
  };
35
44
  /**
36
45
  * Per-resource bundle: optional async loader returning default-export bundle.
37
46
  */
38
47
  type ResourceBundle = (() => Promise<{
39
- default: TranslationBundle;
48
+ default: TranslationBundle;
40
49
  }>) | Record<string, () => Promise<{
41
- default: TranslationBundle;
50
+ default: TranslationBundle;
42
51
  }>>;
43
-
52
+ //#endregion
53
+ //#region src/types/i18n-keys.d.ts
44
54
  /**
45
55
  * Open interface for opt-in codegen-typed i18n keys.
46
56
  *
@@ -50,14 +60,13 @@ type ResourceBundle = (() => Promise<{
50
60
  * }
51
61
  * }
52
62
  */
53
- interface I18nKeys {
54
- }
63
+ interface I18nKeys {}
55
64
  /**
56
65
  * Open interface for keys requiring interpolation parameters.
57
66
  */
58
- interface I18nKeysWithParams {
59
- }
60
-
67
+ interface I18nKeysWithParams {}
68
+ //#endregion
69
+ //#region src/lookup.d.ts
61
70
  /**
62
71
  * Build candidate keys for fallback lookup.
63
72
  *
@@ -67,26 +76,27 @@ interface I18nKeysWithParams {
67
76
  * 3. common.<key> — global common
68
77
  * 4. <key> — raw fallback (debug only)
69
78
  *
70
- * If `key` is already namespaced (starts with `resources.`, `enums.` or
71
- * `common.`), return it as-is without further scoping.
79
+ * If `key` is already namespaced (starts with `resources.`, `enums.`,
80
+ * `common.` or `blocks.`), return it as-is without further scoping.
72
81
  */
73
82
  declare function resolveKey(key: string, resource?: string): string[];
74
-
83
+ //#endregion
84
+ //#region src/i18next-adapter.d.ts
75
85
  interface I18nextAdapterConfig {
76
- defaultLocale: string;
77
- locales: string[];
78
- resources?: Record<string, Record<string, TranslationBundle>>;
79
- /**
80
- * A single fallback locale (`'en'`) applies uniformly to every locale. A
81
- * `fr → en` fallback for one locale but not another needs i18next's own
82
- * per-locale chain shape instead — `{ fr: ['en'], default: ['en'] }` — so
83
- * this accepts i18next's full `FallbackLng` type rather than just `string`.
84
- * The chain is entirely CONFIG: nothing in this adapter special-cases any
85
- * particular locale code, here or anywhere else.
86
- */
87
- fallbackLocale?: FallbackLng;
88
- keySeparator?: string | false;
89
- nsSeparator?: string | false;
86
+ defaultLocale: string;
87
+ locales: string[];
88
+ resources?: Record<string, Record<string, TranslationBundle>>;
89
+ /**
90
+ * A single fallback locale (`'en'`) applies uniformly to every locale. A
91
+ * `fr → en` fallback for one locale but not another needs i18next's own
92
+ * per-locale chain shape instead — `{ fr: ['en'], default: ['en'] }` — so
93
+ * this accepts i18next's full `FallbackLng` type rather than just `string`.
94
+ * The chain is entirely CONFIG: nothing in this adapter special-cases any
95
+ * particular locale code, here or anywhere else.
96
+ */
97
+ fallbackLocale?: FallbackLng;
98
+ keySeparator?: string | false;
99
+ nsSeparator?: string | false;
90
100
  }
91
101
  /**
92
102
  * Default I18nAdapter implementation backed by i18next.
@@ -94,47 +104,67 @@ interface I18nextAdapterConfig {
94
104
  * (e.g. 'common', 'resources').
95
105
  */
96
106
  declare function createI18nextAdapter(config: I18nextAdapterConfig): Promise<I18nAdapter>;
97
-
107
+ //#endregion
108
+ //#region src/i18n.d.ts
98
109
  interface I18nFacade {
99
- t: (key: string, options?: {
100
- resource?: string;
101
- params?: Record<string, unknown>;
102
- }) => string;
103
- /**
104
- * True when a translation for `key` EXISTS (through the same candidate chain
105
- * as {@link I18nFacade.t}). Distinct from `t`, which returns the raw key on a
106
- * miss — the content model probes presence with `has` to tell "no bundle
107
- * entry" (render nothing) from "bundle entry === key text".
108
- */
109
- has: (key: string, options?: {
110
- resource?: string;
111
- }) => boolean;
112
- changeLocale: (locale: string) => Promise<void>;
113
- getCurrentLocale: () => string;
114
- /**
115
- * Subscribe to active-locale changes. Returns an unsubscribe fn. When the
116
- * adapter can't notify, this is a no-op subscription (returns an unsubscribe
117
- * that does nothing) — the live language switch then falls back to a static
118
- * read. Consumed by `useLocale()` via `useSyncExternalStore`.
119
- */
120
- onLocaleChange: (cb: () => void) => () => void;
121
- loadNamespace: (namespace: string, locale: string) => Promise<void>;
122
- adapter: I18nAdapter;
110
+ /**
111
+ * Translate `key` through the candidate chain. `count` selects a count
112
+ * family's form (`<key>_one | _few | _many | _other`, by the locale's CLDR
113
+ * rules) and interpolates `{{count}}`; a family asked without a count is
114
+ * missing. A `count` inside `params` only interpolates.
115
+ */
116
+ t: (key: string, options?: {
117
+ resource?: string;
118
+ params?: Record<string, unknown>;
119
+ count?: number;
120
+ }) => string;
121
+ /**
122
+ * True when a translation for `key` EXISTS (through the same candidate chain
123
+ * as {@link I18nFacade.t}). Distinct from `t`, which returns the raw key on a
124
+ * miss — the content model probes presence with `has` to tell "no bundle
125
+ * entry" (render nothing) from "bundle entry === key text". Pass `count` to probe a count family.
126
+ */
127
+ has: (key: string, options?: {
128
+ resource?: string;
129
+ count?: number;
130
+ }) => boolean;
131
+ changeLocale: (locale: string) => Promise<void>;
132
+ getCurrentLocale: () => string;
133
+ /**
134
+ * Subscribe to active-locale changes. Returns an unsubscribe fn. When the
135
+ * adapter can't notify, this is a no-op subscription (returns an unsubscribe
136
+ * that does nothing) — the live language switch then falls back to a static
137
+ * read. Consumed by `useLocale()` via `useSyncExternalStore`.
138
+ */
139
+ onLocaleChange: (cb: () => void) => () => void;
140
+ loadNamespace: (namespace: string, locale: string) => Promise<void>;
141
+ /**
142
+ * The locale codes this app can switch to. Optional: a facade built without
143
+ * a list (a hand-rolled one, a test double) simply does not say, and a
144
+ * language control then offers only the active locale. `createI18nFromRegistry`
145
+ * fills it from the registry.
146
+ */
147
+ locales?: () => readonly string[];
148
+ adapter: I18nAdapter;
123
149
  }
124
150
  interface CreateI18nConfig {
125
- adapter: I18nAdapter;
126
- warnOnMissing?: boolean;
151
+ adapter: I18nAdapter;
152
+ warnOnMissing?: boolean;
153
+ /** The switchable locale codes, exposed as {@link I18nFacade.locales}. */
154
+ locales?: () => readonly string[];
127
155
  }
128
156
  declare function createI18n(config: CreateI18nConfig): I18nFacade;
129
-
157
+ //#endregion
158
+ //#region src/resource-context.d.ts
130
159
  interface ResourceI18n {
131
- t: (key: string, options?: {
132
- resource?: string;
133
- params?: Record<string, unknown>;
134
- }) => string;
135
- changeLocale: (locale: string) => Promise<void>;
136
- getCurrentLocale: () => string;
137
- resource: string;
160
+ t: (key: string, options?: {
161
+ resource?: string;
162
+ params?: Record<string, unknown>;
163
+ count?: number;
164
+ }) => string;
165
+ changeLocale: (locale: string) => Promise<void>;
166
+ getCurrentLocale: () => string;
167
+ resource: string;
138
168
  }
139
169
  /**
140
170
  * Wraps an I18nFacade with a default resource scope.
@@ -142,7 +172,8 @@ interface ResourceI18n {
142
172
  * Pass an explicit `resource` option to override the default scope.
143
173
  */
144
174
  declare function createResourceI18n(i18n: I18nFacade, resource: string): ResourceI18n;
145
-
175
+ //#endregion
176
+ //#region src/locale-registry.d.ts
146
177
  /**
147
178
  * One package/app/domain module's offering for one locale.
148
179
  *
@@ -155,54 +186,79 @@ declare function createResourceI18n(i18n: I18nFacade, resource: string): Resourc
155
186
  * twenty-first `case`.
156
187
  */
157
188
  interface LocaleContribution {
158
- /** Locale code this contribution provides strings for (e.g. 'en', 'es', 'fr'). */
159
- locale: string;
160
- /**
161
- * i18next namespace the bundle merges into. Defaults to `'common'` — the
162
- * same default namespace `createI18nextAdapter` uses.
163
- */
164
- namespace?: string;
165
- /**
166
- * Declared merge priority. On a key collision within the same
167
- * (locale, namespace), the contribution with the HIGHER priority wins —
168
- * not whichever happened to register last. Ties fall back to registration
169
- * order (last registered wins), which is why two genuinely competing
170
- * sources must declare distinct priorities rather than relying on the tie
171
- * break.
172
- */
173
- priority: number;
174
- /**
175
- * Where this contribution came from — a package name, `'app'`, an enum
176
- * module name. Diagnostic only (surfaced by {@link LocaleRegistry.contributions}
177
- * for debugging a collision); never branched on.
178
- */
179
- source: string;
180
- bundle: TranslationBundle;
189
+ /** Locale code this contribution provides strings for (e.g. 'en', 'es', 'fr'). */
190
+ locale: string;
191
+ /**
192
+ * i18next namespace the bundle merges into. Defaults to `'common'` — the
193
+ * same default namespace `createI18nextAdapter` uses.
194
+ */
195
+ namespace?: string;
196
+ /**
197
+ * Declared merge priority. On a key collision within the same
198
+ * (locale, namespace), the contribution with the HIGHER priority wins —
199
+ * not whichever happened to register last. Ties fall back to registration
200
+ * order (last registered wins), which is why two genuinely competing
201
+ * sources must declare distinct priorities rather than relying on the tie
202
+ * break.
203
+ */
204
+ priority: number;
205
+ /**
206
+ * Where this contribution came from — a package name, `'app'`, an enum
207
+ * module name. Diagnostic only (surfaced by {@link LocaleRegistry.contributions}
208
+ * for debugging a collision); never branched on.
209
+ */
210
+ source: string;
211
+ bundle: TranslationBundle;
181
212
  }
182
213
  interface LocaleRegistry {
183
- /** Add one contribution. Order of registration does not matter for the merge result — only `priority` does (see {@link LocaleContribution.priority}). */
184
- register(contribution: LocaleContribution): void;
185
- /**
186
- * Every locale code that has at least one contribution, sorted. Derived
187
- * purely from what was registered — nothing enumerates or counts locales
188
- * anywhere else in this module.
189
- */
190
- locales(): string[];
191
- /** Every namespace that has at least one contribution, sorted. */
192
- namespaces(): string[];
193
- /** All registered contributions, in registration order. For diagnostics/tests. */
194
- contributions(): readonly LocaleContribution[];
195
- /**
196
- * Assemble `{ [locale]: { [namespace]: TranslationBundle } }`, ready to
197
- * pass straight as `createI18nextAdapter`'s `resources` config. Within one
198
- * (locale, namespace) group, contributions are deep-merged in ascending
199
- * priority order, so a higher-priority contribution's leaves win over a
200
- * lower-priority one's on any overlapping key while leaving the rest of
201
- * the lower-priority bundle intact.
202
- */
203
- buildResources(): Record<string, Record<string, TranslationBundle>>;
214
+ /**
215
+ * The primary locale, as declared to {@link createLocaleRegistry}: the one
216
+ * whose text is the default in code, and the locale every other one falls
217
+ * back to. The single source of truth for it — `createI18nFromRegistry`
218
+ * defaults both the starting locale and the fallback to it, and
219
+ * `@burojs/testing`'s `checkApp` reads it to know which locale is exempt
220
+ * from `i18n.missing`. Never derived from contributions or their order.
221
+ */
222
+ primary(): string;
223
+ /** Add one contribution. Order of registration does not matter for the merge result — only `priority` does (see {@link LocaleContribution.priority}). */
224
+ register(contribution: LocaleContribution): void;
225
+ /**
226
+ * Every locale code that has at least one contribution, sorted. Derived
227
+ * purely from what was registered — nothing enumerates or counts locales
228
+ * anywhere else in this module.
229
+ */
230
+ locales(): string[];
231
+ /** Every namespace that has at least one contribution, sorted. */
232
+ namespaces(): string[];
233
+ /** All registered contributions, in registration order. For diagnostics/tests. */
234
+ contributions(): readonly LocaleContribution[];
235
+ /**
236
+ * Assemble `{ [locale]: { [namespace]: TranslationBundle } }`, ready to
237
+ * pass straight as `createI18nextAdapter`'s `resources` config. Within one
238
+ * (locale, namespace) group, contributions are deep-merged in ascending
239
+ * priority order, so a higher-priority contribution's leaves win over a
240
+ * lower-priority one's on any overlapping key while leaving the rest of
241
+ * the lower-priority bundle intact.
242
+ *
243
+ * Throws when no contribution is registered for {@link primary}: a
244
+ * fallback chain that ends at a locale with no bundle, and a primary that
245
+ * `locales()` (and so every language switcher built from it) does not
246
+ * list, is a misconfiguration (usually a typo, `'en-US'` for `'en'`, or a
247
+ * glob that missed its file), not a state to render. An app that really
248
+ * has no strings for its primary locale registers an empty bundle for it.
249
+ */
250
+ buildResources(): Record<string, Record<string, TranslationBundle>>;
204
251
  }
205
- declare function createLocaleRegistry(): LocaleRegistry;
252
+ interface LocaleRegistryOptions {
253
+ /**
254
+ * The primary locale: the one whose text is the default in code. Required,
255
+ * and declared here rather than inferred, because nothing in the
256
+ * contributions says which locale it is — registration order and the
257
+ * sorted `locales()` both carry no meaning.
258
+ */
259
+ primary: string;
260
+ }
261
+ declare function createLocaleRegistry(options: LocaleRegistryOptions): LocaleRegistry;
206
262
  /**
207
263
  * A bundler-produced glob module, as `import.meta.glob` (Vite) or an
208
264
  * equivalent walk over `require.context` (webpack) would yield it: a flat
@@ -214,24 +270,24 @@ declare function createLocaleRegistry(): LocaleRegistry;
214
270
  * whatever their bundler offers) and hands the plain object here.
215
271
  */
216
272
  type LocaleGlobModule = TranslationBundle | {
217
- default: TranslationBundle;
273
+ default: TranslationBundle;
218
274
  };
219
275
  interface LocaleContributionsFromGlobOptions {
220
- /** {@link LocaleContribution.source} for every contribution produced. */
221
- source: string;
222
- /** {@link LocaleContribution.priority} for every contribution produced. */
223
- priority: number;
224
- /** {@link LocaleContribution.namespace}. Defaults to `'common'`. */
225
- namespace?: string;
226
- /**
227
- * Extracts the locale code from a glob path. Default matches a bare
228
- * `<locale>.ts`/`<locale>.tsx`/`<locale>.js` filename (`'./locales/en.ts'`
229
- * → `'en'`, `'./locales/fr-CA.ts'` → `'fr-CA'`) — no restriction to a
230
- * known set of codes; whatever the filename says IS the locale code. Paths
231
- * that don't match are skipped rather than guessed at (same discipline as
232
- * `docsFromGlob`).
233
- */
234
- localeOf?: (path: string) => string | undefined;
276
+ /** {@link LocaleContribution.source} for every contribution produced. */
277
+ source: string;
278
+ /** {@link LocaleContribution.priority} for every contribution produced. */
279
+ priority: number;
280
+ /** {@link LocaleContribution.namespace}. Defaults to `'common'`. */
281
+ namespace?: string;
282
+ /**
283
+ * Extracts the locale code from a glob path. Default matches a bare
284
+ * `<locale>.ts`/`<locale>.tsx`/`<locale>.js` filename (`'./locales/en.ts'`
285
+ * → `'en'`, `'./locales/fr-CA.ts'` → `'fr-CA'`) — no restriction to a
286
+ * known set of codes; whatever the filename says IS the locale code. Paths
287
+ * that don't match are skipped rather than guessed at (same discipline as
288
+ * `docsFromGlob`).
289
+ */
290
+ localeOf?: (path: string) => string | undefined;
235
291
  }
236
292
  /**
237
293
  * Normalize a bundler glob of per-locale files into {@link LocaleContribution}s.
@@ -241,21 +297,30 @@ interface LocaleContributionsFromGlobOptions {
241
297
  * mechanism for adding a language.
242
298
  */
243
299
  declare function localeContributionsFromGlob(glob: Record<string, LocaleGlobModule>, options: LocaleContributionsFromGlobOptions): LocaleContribution[];
244
-
245
- type CreateI18nFromRegistryConfig = Pick<I18nextAdapterConfig, 'defaultLocale' | 'fallbackLocale' | 'keySeparator' | 'nsSeparator'> & {
246
- warnOnMissing?: boolean;
300
+ //#endregion
301
+ //#region src/create-i18n-from-registry.d.ts
302
+ type CreateI18nFromRegistryConfig = Partial<Pick<I18nextAdapterConfig, 'defaultLocale' | 'fallbackLocale' | 'keySeparator' | 'nsSeparator'>> & {
303
+ warnOnMissing?: boolean;
247
304
  };
248
305
  /**
249
306
  * Wires a {@link LocaleRegistry} straight into `createI18nextAdapter` +
250
307
  * `createI18n`: `registry.locales()` becomes the adapter's `locales`,
251
- * `registry.buildResources()` becomes its `resources`. This is the ONLY
252
- * place those two need to be threaded together — an app that builds its own
253
- * registry never re-lists its locale codes to hand them to the adapter, it
254
- * just calls this.
308
+ * `registry.buildResources()` becomes its `resources`, and
309
+ * `registry.primary()` is both the starting locale and the fallback unless
310
+ * `defaultLocale` (the starting locale, say a stored choice) or
311
+ * `fallbackLocale` (say a per-locale chain) overrides it. This is the ONLY
312
+ * place those need to be threaded together — an app that builds its own
313
+ * registry never re-lists its locale codes, or restates its primary locale,
314
+ * to hand them to the adapter; it just calls this.
315
+ *
316
+ * Throws when the registry's primary locale has no contribution (see
317
+ * {@link LocaleRegistry.buildResources}).
255
318
  */
256
- declare function createI18nFromRegistry(registry: LocaleRegistry, config: CreateI18nFromRegistryConfig): Promise<I18nFacade>;
257
-
319
+ declare function createI18nFromRegistry(registry: LocaleRegistry, config?: CreateI18nFromRegistryConfig): Promise<I18nFacade>;
320
+ //#endregion
321
+ //#region src/index.d.ts
258
322
  declare const PACKAGE_NAME: "@burojs/i18n-core";
259
323
  declare const PACKAGE_VERSION: "0.0.0";
260
-
261
- export { type CreateI18nConfig, type CreateI18nFromRegistryConfig, type I18nAdapter, type I18nFacade, type I18nKeys, type I18nKeysWithParams, type I18nextAdapterConfig, type LocaleContribution, type LocaleContributionsFromGlobOptions, type LocaleGlobModule, type LocaleRegistry, PACKAGE_NAME, PACKAGE_VERSION, type ResourceBundle, type ResourceI18n, type TranslationBundle, createI18n, createI18nFromRegistry, createI18nextAdapter, createLocaleRegistry, createResourceI18n, localeContributionsFromGlob, resolveKey };
324
+ //#endregion
325
+ export { type CreateI18nConfig, type CreateI18nFromRegistryConfig, type I18nAdapter, type I18nFacade, type I18nKeys, type I18nKeysWithParams, type I18nextAdapterConfig, type LocaleContribution, type LocaleContributionsFromGlobOptions, type LocaleGlobModule, type LocaleRegistry, type LocaleRegistryOptions, PACKAGE_NAME, PACKAGE_VERSION, type ResourceBundle, type ResourceI18n, type TranslationBundle, createI18n, createI18nFromRegistry, createI18nextAdapter, createLocaleRegistry, createResourceI18n, localeContributionsFromGlob, resolveKey };
326
+ //# sourceMappingURL=index.d.cts.map