@entifix/i18n 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/instance.d.ts.map +1 -1
- package/dist/instance.js +3 -3
- package/dist/instance.js.map +1 -1
- package/package.json +2 -2
package/dist/instance.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAgB,EACd,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,gBAAgB,EACtB,MAAM,SAAS,CAAC;AAEjB,iDAAiD;AACjD,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC/C,QAAQ,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;CAC5D;AAKD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAiB3D;AAaD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,SAAS,gBAAgB,EAAO,GACxC,IAAI,CAsBN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,gGAOxE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,SAAS,gBAAgB,EAAO,GACxC,IAAI,CAGN;AAED,uEAAuE;AACvE,wBAAgB,aAAa,IAAI,IAAI,CAGpC"}
|
package/dist/instance.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultLocale, defineLocales
|
|
1
|
+
import { defaultLocale, defineLocales } from '@entifix/core';
|
|
2
2
|
import i18next from 'i18next';
|
|
3
3
|
let installed;
|
|
4
4
|
let shared;
|
|
@@ -19,7 +19,7 @@ let shared;
|
|
|
19
19
|
*/ export function defineCatalogs(catalogs) {
|
|
20
20
|
if (catalogs.locales !== undefined || catalogs.defaultLocale !== undefined) {
|
|
21
21
|
if (catalogs.locales === undefined || catalogs.defaultLocale === undefined) {
|
|
22
|
-
throw new
|
|
22
|
+
throw new Error('defineCatalogs takes `locales` and `defaultLocale` together, or neither.');
|
|
23
23
|
}
|
|
24
24
|
defineLocales({
|
|
25
25
|
locales: catalogs.locales,
|
|
@@ -31,7 +31,7 @@ let shared;
|
|
|
31
31
|
}
|
|
32
32
|
const required = ()=>{
|
|
33
33
|
if (installed === undefined) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new Error('No i18n catalogs are installed. Call `defineCatalogs({ resources, ' + 'namespaces, defaultNS })` once from a module every entry point ' + 'imports, before the first server render.');
|
|
35
35
|
}
|
|
36
36
|
return installed;
|
|
37
37
|
};
|
package/dist/instance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instance.ts"],"sourcesContent":["import {\n defaultLocale,\n defineLocales,\n
|
|
1
|
+
{"version":3,"sources":["../src/instance.ts"],"sourcesContent":["import {\n defaultLocale,\n defineLocales,\n type Locale,\n type LocaleDefinition,\n} from '@entifix/core';\nimport i18next, {\n type i18n,\n type Namespace,\n type ThirdPartyModule,\n} from 'i18next';\n\n/** One locale's catalogs, keyed by namespace. */\nexport type LocaleCatalogs = Readonly<Record<string, object>>;\n\n/**\n * Every catalog an application renders: entifix's framework namespaces plus the\n * host's own, already merged.\n *\n * ⚠️ **Supplied by the host, never assembled here.** This package used to import\n * five namespaces directly, two of which were one host's product copy — its\n * product name shipped inside the framework. Taking them as a value is what lets two\n * applications with different copy share one i18next setup.\n */\nexport interface I18nCatalogs {\n readonly resources: Readonly<Record<string, LocaleCatalogs>>;\n readonly namespaces: readonly string[];\n readonly defaultNS: string;\n /**\n * The host's locales, when it declares them here rather than through\n * `defineLocales` from `@entifix/core` — the same call, made for it. A host\n * whose middleware routes by locale still declares them there too: the\n * middleware is bundled apart and never loads this package.\n */\n readonly locales?: LocaleDefinition['locales'];\n readonly defaultLocale?: LocaleDefinition['defaultLocale'];\n}\n\nlet installed: I18nCatalogs | undefined;\nlet shared: i18n | undefined;\n\n/**\n * Hand this package the application's catalogs. Call it once, from a module\n * every entry point imports.\n *\n * ⚠️ **A registry rather than an argument, and the reason is the call site.**\n * Every other seam in entifix takes its value at a composition root — a `Layer`,\n * a React provider, a hook option. `getServerT` has neither: it is called\n * directly inside React server components scattered across an application, with\n * nothing in between to thread a parameter through. So the seam is module\n * initialization, and the failure mode is made loud below rather than silent.\n *\n * Locale *routing* needs none of this. `@entifix/core`'s locale helpers carry\n * no catalogs, so Next middleware reads a cookie and a header without ever\n * loading i18next or a single translation.\n */\nexport function defineCatalogs(catalogs: I18nCatalogs): void {\n if (catalogs.locales !== undefined || catalogs.defaultLocale !== undefined) {\n if (\n catalogs.locales === undefined ||\n catalogs.defaultLocale === undefined\n ) {\n throw new Error(\n 'defineCatalogs takes `locales` and `defaultLocale` together, or neither.',\n );\n }\n defineLocales({\n locales: catalogs.locales,\n defaultLocale: catalogs.defaultLocale,\n });\n }\n installed = catalogs;\n shared = undefined;\n}\n\nconst required = (): I18nCatalogs => {\n if (installed === undefined) {\n throw new Error(\n 'No i18n catalogs are installed. Call `defineCatalogs({ resources, ' +\n 'namespaces, defaultNS })` once from a module every entry point ' +\n 'imports, before the first server render.',\n );\n }\n return installed;\n};\n\n/**\n * Builds an isolated i18next instance for one locale.\n *\n * Always an *instance*, never the `i18next` singleton: a server renders several\n * locales concurrently, and a shared singleton would let one request's `lng`\n * leak into another's markup.\n *\n * Catalogs are bundled rather than fetched, so `init` completes synchronously\n * (`initAsync: false`) and the first paint is already translated — no Suspense\n * boundary, no flash of untranslated keys.\n *\n * `modules` is how the React binding passes `initReactI18next` without this\n * package taking a dependency on React.\n */\nexport function createI18n(\n locale: Locale,\n modules: readonly ThirdPartyModule[] = [],\n): i18n {\n const catalogs = required();\n const instance = modules.reduce<i18n>(\n (acc, module) => acc.use(module),\n i18next.createInstance(),\n );\n\n instance.init({\n lng: locale,\n // Read per instance, so a host's `defineLocales` decides it (#35).\n fallbackLng: defaultLocale(),\n ns: [...catalogs.namespaces],\n defaultNS: catalogs.defaultNS,\n resources: catalogs.resources,\n initAsync: false,\n interpolation: {\n // React escapes for us; double-escaping turns \"Café\" into \"Café\".\n escapeValue: false,\n },\n });\n\n return instance;\n}\n\n/**\n * A translate function for a locale the caller already holds — a route param,\n * typically — bound to one namespace.\n *\n * Request-free by construction, and that is the point: a component built on it\n * touches neither `headers()` nor `cookies()`, so the page containing it stays\n * statically renderable and can be prerendered once per locale. Its\n * request-reading counterpart is `getServerT` in `@entifix/next-i18n`,\n * which re-exports this one for symmetry at app call sites.\n *\n * It lives here rather than in the Next i18n shell because the shells share\n * T4 and the tier register declares no edge between them — and the storefront\n * shell, which has a real `[locale]` segment and therefore never reads a\n * request, is exactly the caller that needs it.\n */\nexport function getServerTFor<N extends Namespace>(locale: Locale, ns?: N) {\n // `Namespace` is i18next's own, so it resolves to whatever union the *host*\n // declared in `CustomTypeOptions`. This package names no namespace of its own\n // and imports no catalog — which is the whole point — while a caller still\n // gets a `t` bound to the namespace it asked for, and an unknown key stays a\n // compile error.\n return createI18n(locale).getFixedT(locale, ns ?? null);\n}\n\n/**\n * The instance used when no provider is mounted — Storybook, a unit spec, a\n * screen that forgot.\n *\n * One per process, shared across packages on purpose. Each React package\n * resolves copy through its own `useTranslation`, and react-i18next falls back\n * to its *uninitialized* global when no provider is in the tree — which renders\n * raw keys at the user. Handing every caller the same initialized default\n * instance makes that failure mode \"the host's default locale\" instead.\n *\n * Built lazily, so an app that always mounts a provider never pays for it.\n */\nexport function sharedFallbackI18n(\n modules: readonly ThirdPartyModule[] = [],\n): i18n {\n shared ??= createI18n(defaultLocale(), modules);\n return shared;\n}\n\n/** Drops the installed catalogs and the shared instance. For specs. */\nexport function resetCatalogs(): void {\n installed = undefined;\n shared = undefined;\n}\n"],"names":["defaultLocale","defineLocales","i18next","installed","shared","defineCatalogs","catalogs","locales","undefined","Error","required","createI18n","locale","modules","instance","reduce","acc","module","use","createInstance","init","lng","fallbackLng","ns","namespaces","defaultNS","resources","initAsync","interpolation","escapeValue","getServerTFor","getFixedT","sharedFallbackI18n","resetCatalogs"],"mappings":"AAAA,SACEA,aAAa,EACbC,aAAa,QAGR,gBAAgB;AACvB,OAAOC,aAIA,UAAU;AA4BjB,IAAIC;AACJ,IAAIC;AAEJ;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,eAAeC,QAAsB;IACnD,IAAIA,SAASC,OAAO,KAAKC,aAAaF,SAASN,aAAa,KAAKQ,WAAW;QAC1E,IACEF,SAASC,OAAO,KAAKC,aACrBF,SAASN,aAAa,KAAKQ,WAC3B;YACA,MAAM,IAAIC,MACR;QAEJ;QACAR,cAAc;YACZM,SAASD,SAASC,OAAO;YACzBP,eAAeM,SAASN,aAAa;QACvC;IACF;IACAG,YAAYG;IACZF,SAASI;AACX;AAEA,MAAME,WAAW;IACf,IAAIP,cAAcK,WAAW;QAC3B,MAAM,IAAIC,MACR,uEACE,oEACA;IAEN;IACA,OAAON;AACT;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASQ,WACdC,MAAc,EACdC,UAAuC,EAAE;IAEzC,MAAMP,WAAWI;IACjB,MAAMI,WAAWD,QAAQE,MAAM,CAC7B,CAACC,KAAKC,SAAWD,IAAIE,GAAG,CAACD,SACzBf,QAAQiB,cAAc;IAGxBL,SAASM,IAAI,CAAC;QACZC,KAAKT;QACL,mEAAmE;QACnEU,aAAatB;QACbuB,IAAI;eAAIjB,SAASkB,UAAU;SAAC;QAC5BC,WAAWnB,SAASmB,SAAS;QAC7BC,WAAWpB,SAASoB,SAAS;QAC7BC,WAAW;QACXC,eAAe;YACb,uEAAuE;YACvEC,aAAa;QACf;IACF;IAEA,OAAOf;AACT;AAEA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASgB,cAAmClB,MAAc,EAAEW,EAAM;IACvE,4EAA4E;IAC5E,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,iBAAiB;IACjB,OAAOZ,WAAWC,QAAQmB,SAAS,CAACnB,QAAQW,aAAAA,KAAM;AACpD;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASS,mBACdnB,UAAuC,EAAE;IAEzCT,iBAAAA,SAAAA,SAAWO,WAAWX,iBAAiBa;IACvC,OAAOT;AACT;AAEA,qEAAqE,GACrE,OAAO,SAAS6B;IACd9B,YAAYK;IACZJ,SAASI;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "i18next binding: install each package's catalogs once, translate with typed keys, and negotiate a locale.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@swc/helpers": "0.5.23",
|
|
59
|
-
"@entifix/core": "0.
|
|
59
|
+
"@entifix/core": "0.10.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"i18next": ">=26 <27"
|