@entifix/next-i18n 0.1.0 → 0.1.2

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 ADDED
@@ -0,0 +1,28 @@
1
+ # @entifix/next-i18n
2
+
3
+ Locale routing and server-side translation for a Next.js app. The locale lives in the URL — `/es/catalog` — so a page can be shared in the language it was read in. An unprefixed request is negotiated from the cookie, then `Accept-Language`, and redirected; a prefixed one is rewritten so the rest of the app never sees the prefix.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @entifix/next-i18n next
9
+ ```
10
+
11
+ ## Entry points
12
+
13
+ | Import | What it holds |
14
+ | --------------------------- | -------------------------------------------------------------------------------------------- |
15
+ | `@entifix/next-i18n` | `resolveLocale`, `rewriteToLocale`, `rememberLocale` — for middleware |
16
+ | `@entifix/next-i18n/server` | `getRequestLocale`, `getServerT`, `getServerTranslateKey` — for server components and routes |
17
+
18
+ ## Optional peers
19
+
20
+ Install these only if you use what needs them.
21
+
22
+ | Peer | Needed by |
23
+ | --------- | --------------------------- |
24
+ | `i18next` | `@entifix/next-i18n/server` |
25
+
26
+ ---
27
+
28
+ Tier 4 (app framework) of entifix — a package depends only on its own tier or below. See [the tiers](https://github.com/r10c-technologies/entifix#the-tiers-and-what-you-are-allowed-to-install). MIT licensed.
package/dist/server.d.ts CHANGED
@@ -23,8 +23,8 @@ export declare function getRequestLocale(): Promise<Locale>;
23
23
  *
24
24
  * Re-exported rather than defined here so it sits next to `getServerT` at an
25
25
  * app's call sites while still being reachable from packages that may not
26
- * depend on this one: `layer:shell` forbids same-layer edges, and the
27
- * storefront shell is precisely the caller that needs it. The implementation
26
+ * depend on this one: the shells share T4, the tier register declares no edge
27
+ * between them, and the storefront shell is precisely the caller that needs it. The implementation
28
28
  * lives in `@entifix/i18n`.
29
29
  */
30
30
  export { getServerTFor } from '@entifix/i18n';
package/dist/server.js CHANGED
@@ -26,8 +26,8 @@ import { headers } from 'next/headers';
26
26
  *
27
27
  * Re-exported rather than defined here so it sits next to `getServerT` at an
28
28
  * app's call sites while still being reachable from packages that may not
29
- * depend on this one: `layer:shell` forbids same-layer edges, and the
30
- * storefront shell is precisely the caller that needs it. The implementation
29
+ * depend on this one: the shells share T4, the tier register declares no edge
30
+ * between them, and the storefront shell is precisely the caller that needs it. The implementation
31
31
  * lives in `@entifix/i18n`.
32
32
  */ export { getServerTFor } from '@entifix/i18n';
33
33
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import {\n DEFAULT_LOCALE,\n isLocale,\n type Locale,\n LOCALE_HEADER,\n} from '@entifix/core';\nimport { createI18n } from '@entifix/i18n';\nimport type { Namespace } from 'i18next';\nimport { headers } from 'next/headers';\n\n/**\n * The locale the middleware resolved for this request.\n *\n * Read from a header rather than a route param — that is the trade the rewrite\n * strategy makes, and it is why the back-office route trees have no\n * `app/[locale]` segment. Falls back to the fleet default for paths the\n * middleware matcher skips (`/api/health`, `/api/config`), which have no\n * user-facing copy anyway.\n *\n * A header is a **dynamic** request input, so a page that calls this — or\n * {@link getServerT}, which does — can never be prerendered. That is the right\n * trade for an auth-gated app whose every response is personal anyway, and the\n * wrong one for a public storefront: marketplace-app therefore carries a real\n * `[locale]` segment and reads its locale from the route param, through\n * {@link getServerTFor}.\n */\nexport async function getRequestLocale(): Promise<Locale> {\n const value = (await headers()).get(LOCALE_HEADER);\n return isLocale(value) ? value : DEFAULT_LOCALE;\n}\n\n/**\n * The request-free counterpart of {@link getServerT}, for a locale the caller\n * already holds — a route param, typically.\n *\n * Re-exported rather than defined here so it sits next to `getServerT` at an\n * app's call sites while still being reachable from packages that may not\n * depend on this one: `layer:shell` forbids same-layer edges, and the\n * storefront shell is precisely the caller that needs it. The implementation\n * lives in `@entifix/i18n`.\n */\nexport { getServerTFor } from '@entifix/i18n';\n\n/**\n * A translate function for a server component. A fresh instance per request,\n * because a module-level singleton would let one visitor's locale leak into\n * another's markup under concurrent rendering.\n */\nexport async function getServerT<N extends Namespace>(ns?: N) {\n const locale = await getRequestLocale();\n return createI18n(locale).getFixedT(locale, ns ?? null);\n}\n\nexport type TranslateKey = (\n key: string,\n params?: Record<string, unknown>,\n) => string;\n\n/**\n * The server counterpart of the controls package's `useTranslateKey`: resolves\n * keys that are only known at runtime — nav labels held in a route table, an\n * entity's `labelKey`.\n *\n * Separate from {@link getServerT}, which stays strict. This is the one place\n * the typed-key guarantee is traded away on the server, and authored copy must\n * keep going through `getServerT` so a typo stays a compile error.\n */\nexport async function getServerTranslateKey<N extends Namespace>(\n ns?: N,\n): Promise<TranslateKey> {\n const t = await getServerT(ns);\n return t as unknown as TranslateKey;\n}\n"],"names":["DEFAULT_LOCALE","isLocale","LOCALE_HEADER","createI18n","headers","getRequestLocale","value","get","getServerTFor","getServerT","ns","locale","getFixedT","getServerTranslateKey","t"],"mappings":"AAAA,SACEA,cAAc,EACdC,QAAQ,EAERC,aAAa,QACR,gBAAgB;AACvB,SAASC,UAAU,QAAQ,gBAAgB;AAE3C,SAASC,OAAO,QAAQ,eAAe;AAEvC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeC;IACpB,MAAMC,QAAQ,AAAC,CAAA,MAAMF,SAAQ,EAAGG,GAAG,CAACL;IACpC,OAAOD,SAASK,SAASA,QAAQN;AACnC;AAEA;;;;;;;;;CASC,GACD,SAASQ,aAAa,QAAQ,gBAAgB;AAE9C;;;;CAIC,GACD,OAAO,eAAeC,WAAgCC,EAAM;IAC1D,MAAMC,SAAS,MAAMN;IACrB,OAAOF,WAAWQ,QAAQC,SAAS,CAACD,QAAQD,aAAAA,KAAM;AACpD;AAOA;;;;;;;;CAQC,GACD,OAAO,eAAeG,sBACpBH,EAAM;IAEN,MAAMI,IAAI,MAAML,WAAWC;IAC3B,OAAOI;AACT"}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import {\n DEFAULT_LOCALE,\n isLocale,\n type Locale,\n LOCALE_HEADER,\n} from '@entifix/core';\nimport { createI18n } from '@entifix/i18n';\nimport type { Namespace } from 'i18next';\nimport { headers } from 'next/headers';\n\n/**\n * The locale the middleware resolved for this request.\n *\n * Read from a header rather than a route param — that is the trade the rewrite\n * strategy makes, and it is why the back-office route trees have no\n * `app/[locale]` segment. Falls back to the fleet default for paths the\n * middleware matcher skips (`/api/health`, `/api/config`), which have no\n * user-facing copy anyway.\n *\n * A header is a **dynamic** request input, so a page that calls this — or\n * {@link getServerT}, which does — can never be prerendered. That is the right\n * trade for an auth-gated app whose every response is personal anyway, and the\n * wrong one for a public storefront: marketplace-app therefore carries a real\n * `[locale]` segment and reads its locale from the route param, through\n * {@link getServerTFor}.\n */\nexport async function getRequestLocale(): Promise<Locale> {\n const value = (await headers()).get(LOCALE_HEADER);\n return isLocale(value) ? value : DEFAULT_LOCALE;\n}\n\n/**\n * The request-free counterpart of {@link getServerT}, for a locale the caller\n * already holds — a route param, typically.\n *\n * Re-exported rather than defined here so it sits next to `getServerT` at an\n * app's call sites while still being reachable from packages that may not\n * depend on this one: the shells share T4, the tier register declares no edge\n * between them, and the storefront shell is precisely the caller that needs it. The implementation\n * lives in `@entifix/i18n`.\n */\nexport { getServerTFor } from '@entifix/i18n';\n\n/**\n * A translate function for a server component. A fresh instance per request,\n * because a module-level singleton would let one visitor's locale leak into\n * another's markup under concurrent rendering.\n */\nexport async function getServerT<N extends Namespace>(ns?: N) {\n const locale = await getRequestLocale();\n return createI18n(locale).getFixedT(locale, ns ?? null);\n}\n\nexport type TranslateKey = (\n key: string,\n params?: Record<string, unknown>,\n) => string;\n\n/**\n * The server counterpart of the controls package's `useTranslateKey`: resolves\n * keys that are only known at runtime — nav labels held in a route table, an\n * entity's `labelKey`.\n *\n * Separate from {@link getServerT}, which stays strict. This is the one place\n * the typed-key guarantee is traded away on the server, and authored copy must\n * keep going through `getServerT` so a typo stays a compile error.\n */\nexport async function getServerTranslateKey<N extends Namespace>(\n ns?: N,\n): Promise<TranslateKey> {\n const t = await getServerT(ns);\n return t as unknown as TranslateKey;\n}\n"],"names":["DEFAULT_LOCALE","isLocale","LOCALE_HEADER","createI18n","headers","getRequestLocale","value","get","getServerTFor","getServerT","ns","locale","getFixedT","getServerTranslateKey","t"],"mappings":"AAAA,SACEA,cAAc,EACdC,QAAQ,EAERC,aAAa,QACR,gBAAgB;AACvB,SAASC,UAAU,QAAQ,gBAAgB;AAE3C,SAASC,OAAO,QAAQ,eAAe;AAEvC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeC;IACpB,MAAMC,QAAQ,AAAC,CAAA,MAAMF,SAAQ,EAAGG,GAAG,CAACL;IACpC,OAAOD,SAASK,SAASA,QAAQN;AACnC;AAEA;;;;;;;;;CASC,GACD,SAASQ,aAAa,QAAQ,gBAAgB;AAE9C;;;;CAIC,GACD,OAAO,eAAeC,WAAgCC,EAAM;IAC1D,MAAMC,SAAS,MAAMN;IACrB,OAAOF,WAAWQ,QAAQC,SAAS,CAACD,QAAQD,aAAAA,KAAM;AACpD;AAOA;;;;;;;;CAQC,GACD,OAAO,eAAeG,sBACpBH,EAAM;IAEN,MAAMI,IAAI,MAAML,WAAWC;IAC3B,OAAOI;AACT"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@entifix/next-i18n",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "description": "Next.js locale routing and server-side translation for @entifix/i18n, with the locale carried in the URL prefix.",
4
5
  "license": "MIT",
5
6
  "repository": {
6
7
  "type": "git",
@@ -36,9 +37,6 @@
36
37
  ],
37
38
  "nx": {
38
39
  "tags": [
39
- "layer:shell",
40
- "scope:shared",
41
- "shell:base",
42
40
  "tier:4"
43
41
  ],
44
42
  "sourceRoot": "packages/next/i18n/src",
@@ -60,8 +58,8 @@
60
58
  },
61
59
  "dependencies": {
62
60
  "@swc/helpers": "0.5.23",
63
- "@entifix/i18n": "0.1.0",
64
- "@entifix/core": "0.1.0"
61
+ "@entifix/i18n": "0.1.2",
62
+ "@entifix/core": "0.1.2"
65
63
  },
66
64
  "peerDependencies": {
67
65
  "next": ">=16",