@owlmeans/client-i18n 0.1.18-rc.49 → 0.1.18-rc.50

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 CHANGED
@@ -12,7 +12,7 @@ React i18next adapter that loads translations registered via `@owlmeans/i18n` in
12
12
  ## Installation
13
13
 
14
14
  ```bash
15
- bun add @owlmeans/client-i18n@^0.1.18-rc.49
15
+ bun add @owlmeans/client-i18n@^0.1.18-rc.50
16
16
  ```
17
17
 
18
18
  ## Usage
@@ -58,7 +58,7 @@ Returns a `t()` function for shared/common translations.
58
58
 
59
59
  ## Related Packages
60
60
 
61
- - [`@owlmeans/i18n`](../i18n) — `addI18nApp`, `addI18n` to register translations before render
61
+ - [`@owlmeans/i18n`](../i18n) — `i18nHelper.addI18nApp` / `i18nHelper.addI18nLib` to register translations before render
62
62
 
63
63
  <!-- owlmeans:agent-guidance:start -->
64
64
  ## Agent guidance
@@ -68,7 +68,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
68
68
  your project's skill store (`.agents/skills/`):
69
69
 
70
70
  ```sh
71
- npx @owlmeans/agent-skills@^0.1.18-rc.48
71
+ npx @owlmeans/agent-skills@^0.1.18-rc.49
72
72
  ```
73
73
 
74
74
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/client-i18n",
4
- "version": "0.1.18-rc.49",
5
- "generatedAt": "2026-10-05T08:32:19.120Z",
4
+ "version": "0.1.18-rc.50",
5
+ "generatedAt": "2026-10-05T21:03:06.397Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: client-i18n
3
- description: How to use @owlmeans/client-i18n — React i18n context built on i18next. Auto-invoked when setting up translation in a React app, using translation hooks, working with language switching, or awaiting deferred language packs with prepareI18n.
3
+ description: How to use @owlmeans/client-i18n — React i18n context built on i18next. Auto-invoked when setting up translation in a React app, using translation hooks, working with language switching, or awaiting deferred language packs with i18nInstanceHelper.prepareI18n.
4
4
  user-invocable: false
5
5
  ---
6
6
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
@@ -8,11 +8,11 @@ user-invocable: false
8
8
  # @owlmeans/client-i18n
9
9
 
10
10
  **Layer:** Client (React)
11
- **Install:** `"@owlmeans/client-i18n": "^0.1.18-rc.49"` in `dependencies`
11
+ **Install:** `"@owlmeans/client-i18n": "^0.1.18-rc.50"` in `dependencies`
12
12
 
13
13
  ## Purpose
14
14
 
15
- Wraps i18next + react-i18next, lazily loads registered bundles from `@owlmeans/i18n` storage into the i18next instance, awaits deferred language packs (`prepareI18n`, `setLanguage`), and provides hooks for translating strings.
15
+ Wraps i18next + react-i18next, lazily loads registered bundles from `@owlmeans/i18n` storage into the i18next instance, awaits deferred language packs (`i18nInstanceHelper.prepareI18n`, `setLanguage`), and provides hooks for translating strings.
16
16
 
17
17
  ## Key Exports
18
18
 
@@ -23,7 +23,7 @@ Wraps i18next + react-i18next, lazily loads registered bundles from `@owlmeans/i
23
23
  | `useI18nApp(resource?, prefix?)` | Hook for app strings (ns=resource name; defaults to `context.cfg.service`) |
24
24
  | `useI18n(resource, ns?, prefix?)` | Low-level hook with explicit ns — use when ns ≠ resource |
25
25
  | `useLanguage()` | `[currentLng, setLng]` — the i18next instance's language, and an async switch — see Language persistence |
26
- | `prepareI18n`, `resolveInitialLanguage`, `setLanguage` | Re-exported from `./utils` — see below |
26
+ | `i18nInstanceHelper` / `createI18nInstanceHelper()` | Re-exported from `./utils` — see below |
27
27
  | `composePrefix(parent?, child?)` | Canonical dot-join for prefix chaining; never call manually in panel code — used internally |
28
28
  | `I18nBaseProps` | `{ resource?, ns?, prefix?, suppress? }` |
29
29
  | `I18nProps` | `{ i18n?: I18nBaseProps }` |
@@ -36,27 +36,28 @@ The instance itself, for a host that has to configure i18next before the tree re
36
36
  | Export | Description |
37
37
  |---|---|
38
38
  | `useI18nInstance(config)` | The i18next instance for this application, memoised for the mount |
39
- | `getI18nInstance(config)` | The same instance outside React |
40
- | `setLanguage(lng)` | Async: load `lng`'s pack (`loadI18nLanguage`), then persist and switch — what `useLanguage`'s setter calls |
41
- | `prepareI18n(config)` | Await the fallback language's loaders, then the initial language's; resolves to the language the instance will start in. Call once, before the first render |
42
- | `resolveInitialLanguage(config)` | The persisted `owlmeans-lng` when it is in `supportedLngs`, else the browser's language (`preferredLanguageOf`), else `fallbackLng ?? defaultLng ?? DEFAULT_LNG` |
43
- | `preferredLanguageOf(supportedLngs, preferred)` | Pure: the first preferred tag the config supports, exact or by base (`de-DE` → `de`), else `null` |
39
+ | `i18nInstanceHelper.getI18nInstance(config)` | The same instance outside React |
40
+ | `i18nInstanceHelper.setLanguage(lng)` | Async: load `lng`'s pack (`i18nHelper.loadI18nLanguage`), then persist and switch — what `useLanguage`'s setter calls |
41
+ | `i18nInstanceHelper.prepareI18n(config)` | Await the fallback language's loaders, then the initial language's; resolves to the language the instance will start in. Call once, before the first render |
42
+ | `i18nInstanceHelper.resolveInitialLanguage(config)` | The persisted `owlmeans-lng` when it is in `supportedLngs`, else the browser's language (`preferredLanguageOf`), else `fallbackLng ?? defaultLng ?? DEFAULT_LNG` |
43
+ | `i18nInstanceHelper.preferredLanguageOf(supportedLngs, preferred)` | Pure: the first preferred tag the config supports, exact or by base (`de-DE` → `de`), else `null` |
44
44
 
45
- All of these live in `src/utils/instance.ts`; the package root re-exports `prepareI18n`,
46
- `resolveInitialLanguage` and `setLanguage`.
45
+ The helper lives in `src/utils/instance.ts`, its interface in `src/utils/instance/types.ts`; the
46
+ package root re-exports `i18nInstanceHelper` and `createI18nInstanceHelper`.
47
47
 
48
48
  **There is exactly one instance per document**, created on first request and reused by every later
49
49
  call whatever config is passed. So configuration is read once, at the first creation, and a plugin
50
50
  is installed on the instance rather than passed to a second factory.
51
51
 
52
52
  **The instance is initialized at creation with an explicit `lng`**, which is why the language is
53
- resolved there and not by a plugin — by `resolveInitialLanguage` (or `prepareI18n`, which runs it):
54
- the persisted choice (`owlmeans-lng`, when supported), else the browser's own language
55
- (`navigator.languages` through `preferredLanguageOf` — a first visit from a German browser opens in
56
- German), else `fallbackLng`. A language detector installed afterwards (`instance.use(detector)`,
57
- which `@owlmeans/web-panel`'s `render` still does) is never consulted — harmless, but not what
58
- detects. A detected language is not persisted, not even by the start-up switch that follows a
59
- deferred pack's load; only an explicit choice (`setLanguage`) is.
53
+ resolved there and not by a plugin — by `i18nInstanceHelper.resolveInitialLanguage` (or
54
+ `prepareI18n`, which runs it): the persisted choice (`owlmeans-lng`, when supported), else the
55
+ browser's own language (`navigator.languages` through `preferredLanguageOf` — a first visit from a
56
+ German browser opens in German), else `fallbackLng`. A language detector installed afterwards
57
+ (`instance.use(detector)`, which `@owlmeans/web-panel`'s `render` still does) is never consulted —
58
+ harmless, but not what detects. A detected language is not persisted, not even by the start-up
59
+ switch that follows a deferred pack's load; only an explicit choice
60
+ (`i18nInstanceHelper.setLanguage`) is.
60
61
 
61
62
  ## Setup (app root)
62
63
 
@@ -74,24 +75,24 @@ function App() {
74
75
 
75
76
  `clientConfig.i18n` is optional; it defaults to `SUPPORTED_LNGS` and `'en'` fallback.
76
77
 
77
- **An app that defers language packs** (`addI18nLoader`, the `i18n` skill) calls
78
- `await prepareI18n(config)` BEFORE its first render — never after:
78
+ **An app that defers language packs** (`i18nHelper.addI18nLoader`, the `i18n` skill) calls
79
+ `await i18nInstanceHelper.prepareI18n(config)` BEFORE its first render — never after:
79
80
 
80
81
  ```ts
81
- import { prepareI18n } from '@owlmeans/client-i18n'
82
+ import { i18nInstanceHelper } from '@owlmeans/client-i18n'
82
83
 
83
- await prepareI18n(context.cfg) // fallback pack first, then the persisted / browser / fallback one
84
+ await i18nInstanceHelper.prepareI18n(context.cfg) // fallback pack first, then the persisted / browser / fallback one
84
85
  render(context)
85
86
  ```
86
87
 
87
88
  This composes with an async boot because `@owlmeans/web-client`'s `render` (and so `renderApp` and
88
89
  `@owlmeans/web-panel`'s `render`) checks `document.readyState` instead of waiting for a
89
- `DOMContentLoaded` that already fired. `prepareI18n` rejects only when the FALLBACK pack fails; when
90
- the initial language's pack fails it logs, resolves to the fallback and leaves the persisted choice
91
- alone, so the next visit retries it rather than stranding the user. Without `prepareI18n`, the
92
- instance starts in the fallback whenever the wanted language is not loaded yet and switches once its
93
- loaders finish (a brief fallback flash) — but nothing awaits a deferred FALLBACK pack, whose slots
94
- are then drained empty for the session.
90
+ `DOMContentLoaded` that already fired. `i18nInstanceHelper.prepareI18n` rejects only when the
91
+ FALLBACK pack fails; when the initial language's pack fails it logs, resolves to the fallback and
92
+ leaves the persisted choice alone, so the next visit retries it rather than stranding the user.
93
+ Without `prepareI18n`, the instance starts in the fallback whenever the wanted language is not
94
+ loaded yet and switches once its loaders finish (a brief fallback flash) — but nothing awaits a
95
+ deferred FALLBACK pack, whose slots are then drained empty for the session.
95
96
 
96
97
  ## Language persistence
97
98
 
@@ -100,23 +101,24 @@ only when it is in `supportedLngs`, so a stored value that a later release dropp
100
101
  the browser's language, then `fallbackLng`, instead of resolving nothing. Every storage and
101
102
  `navigator` access is guarded, so a browser that refuses site data (or no browser) still renders.
102
103
 
103
- `tests/instance.spec.ts` pins `preferredLanguageOf` (base matching, browser order, exact tag first,
104
- `null` when nothing matches) and that an explicit choice is always stored and read back.
104
+ `tests/instance.spec.ts` pins `i18nInstanceHelper.preferredLanguageOf` (base matching, browser
105
+ order, exact tag first, `null` when nothing matches) and that an explicit choice is always stored
106
+ and read back.
105
107
 
106
108
  **Persistence is unconditional.** The interface language is strictly necessary storage — the visitor
107
- asked for it by choosing it — so `setLanguage` writes `owlmeans-lng` on every explicit switch and
108
- `resolveInitialLanguage` reads it at every start, whatever cookie decision was made (the `consent`
109
- skill has the reasoning, and how a language carried by a link from another OwlMeans domain lands in
110
- the same key before the app renders). There is no guard to install and no consent hook: the
111
- earlier `setLanguagePersistence` / `persistLanguage` / `getExplicitLanguage` are gone, and
112
- `@owlmeans/web-panel/consent`'s `installConsentLanguage()` is a deprecated no-op kept for
113
- applications that still call it. A start-up switch to a language nobody chose (the browser's) is never
114
- written — only an explicit choice is.
115
-
116
- `setLanguage(lng)` is async: it awaits `loadI18nLanguage(lng)`, then persists and calls i18next's
117
- `changeLanguage` — before the instance exists it records the language the instance will start in
118
- instead. The LAST call wins: an earlier call whose load finishes later does nothing. A failed load
119
- rejects, and nothing is persisted or switched.
109
+ asked for it by choosing it — so `i18nInstanceHelper.setLanguage` writes `owlmeans-lng` on every
110
+ explicit switch and `resolveInitialLanguage` reads it at every start, whatever cookie decision was
111
+ made (the `consent` skill has the reasoning, and how a language carried by a link from another
112
+ OwlMeans domain lands in the same key before the app renders). There is no guard to install and no
113
+ consent hook: the earlier `setLanguagePersistence` / `persistLanguage` / `getExplicitLanguage` are
114
+ gone, and `@owlmeans/web-panel/consent`'s `installConsentLanguage()` is a deprecated no-op kept for
115
+ applications that still call it. A start-up switch to a language nobody chose (the browser's) is
116
+ never written — only an explicit choice is.
117
+
118
+ `i18nInstanceHelper.setLanguage(lng)` is async: it awaits `i18nHelper.loadI18nLanguage(lng)`, then
119
+ persists and calls i18next's `changeLanguage` — before the instance exists it records the language
120
+ the instance will start in instead. The LAST call wins: an earlier call whose load finishes later
121
+ does nothing. A failed load rejects, and nothing is persisted or switched.
120
122
 
121
123
  `useLanguage()` returns `i18n.language` from `useTranslation()`, not local state, so every caller
122
124
  re-renders on i18next's `languageChanged` and shows the same language whoever switched it. Its
@@ -185,16 +187,17 @@ Import the library's i18n registration **and** register your own version at App
185
187
  library's namespace**:
186
188
  ```typescript
187
189
  import '@owlmeans/error' // the library bundle, registered by side effect
188
- import { addI18nApp, LIB_NAMESPACE } from '@owlmeans/i18n'
190
+ import { i18nHelper, LIB_NAMESPACE } from '@owlmeans/i18n'
189
191
  import myErrors from './i18n/en.json' with { type: 'json' }
190
192
 
191
193
  // App tier merges last within (ns, resource, lng) — these override the library's 'errors' strings
192
- addI18nApp('en', 'errors', myErrors, { ns: LIB_NAMESPACE })
194
+ i18nHelper.addI18nApp('en', 'errors', myErrors, { ns: LIB_NAMESPACE })
193
195
  ```
194
196
 
195
- `{ ns: LIB_NAMESPACE }` is what makes it an override. `addI18nApp` defaults the namespace to the
196
- **resource** name, so without it the bundle lands in namespace `errors` while `useI18nLib('errors')`
197
- reads namespace `lib` — nothing errors, nothing merges, and the library strings keep rendering.
197
+ `{ ns: LIB_NAMESPACE }` is what makes it an override. `i18nHelper.addI18nApp` defaults the namespace
198
+ to the **resource** name, so without it the bundle lands in namespace `errors` while
199
+ `useI18nLib('errors')` reads namespace `lib` — nothing errors, nothing merges, and the library
200
+ strings keep rendering.
198
201
 
199
202
  A package registers its strings from its own root: `src/i18n.ts` is re-exported by `src/index.ts`,
200
203
  so importing the package is what loads them. No package publishes an `./i18n` subpath.
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAMxC,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAI3C,CAAA;AAEF,kGAAkG;AAClG,eAAO,MAAM,aAAa,YAAa,MAAM,UAAU,MAAM,KAAG,MAK/D,CAAA;AAyCD;4FAC4F;AAC5F,eAAO,MAAM,OAAO,aAAc,MAAM,OAAO,MAAM,WAAW,MAAM,KAAG,SAExE,CAAA;AAED,eAAO,MAAM,UAAU,YAAa,MAAM,WAAW,MAAM,KAAG,SAE7D,CAAA;AAED,eAAO,MAAM,UAAU,aAAc,MAAM,WAAW,MAAM,KAAG,SAK9D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAYrE,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAOxC,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAI3C,CAAA;AAEF,kGAAkG;AAClG,eAAO,MAAM,aAAa,YAAa,MAAM,UAAU,MAAM,KAAG,MAK/D,CAAA;AAyCD;4FAC4F;AAC5F,eAAO,MAAM,OAAO,aAAc,MAAM,OAAO,MAAM,WAAW,MAAM,KAAG,SAExE,CAAA;AAED,eAAO,MAAM,UAAU,YAAa,MAAM,WAAW,MAAM,KAAG,SAE7D,CAAA;AAED,eAAO,MAAM,UAAU,aAAc,MAAM,WAAW,MAAM,KAAG,SAK9D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAYrE,CAAA"}
package/build/context.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { memo, useCallback } from 'react';
3
3
  import { I18nextProvider, useTranslation } from 'react-i18next';
4
- import { setLanguage, useI18nInstance } from './utils/instance.js';
5
- import { DEFAULT_LNG, DEFAULT_NAMESPACE, initI18nResource, LIB_NAMESPACE } from '@owlmeans/i18n';
4
+ import { i18nInstanceHelper } from './utils/instance.js';
5
+ import { useI18nInstance } from './utils/hook.js';
6
+ import { DEFAULT_LNG, DEFAULT_NAMESPACE, i18nHelper, LIB_NAMESPACE } from '@owlmeans/i18n';
6
7
  import { useContext } from '@owlmeans/client';
7
8
  import { logger } from '@owlmeans/log';
8
9
  export const I18nContext = memo(({ config, children }) => {
@@ -25,7 +26,7 @@ const useI18nResource = (resourceName, ns, prefix) => {
25
26
  const key = `${i18n.language}:${resourceName}:${resolvedNs}`;
26
27
  if (!i18nLoadingCache.has(key)) {
27
28
  i18nLoadingCache.add(key);
28
- const resources = initI18nResource(i18n.language, resourceName, resolvedNs);
29
+ const resources = i18nHelper.initI18nResource(i18n.language, resourceName, resolvedNs);
29
30
  if (resources != null) {
30
31
  resources.forEach(resource => i18n.addResourceBundle(i18n.language, resolvedNs, { [resourceName]: resource.data }, true, true));
31
32
  }
@@ -35,7 +36,7 @@ const useI18nResource = (resourceName, ns, prefix) => {
35
36
  const fallbackKey = `${defLng}:${resourceName}:${resolvedNs}`;
36
37
  if (!i18nLoadingCache.has(fallbackKey)) {
37
38
  i18nLoadingCache.add(fallbackKey);
38
- const defResources = initI18nResource(defLng, resourceName, resolvedNs);
39
+ const defResources = i18nHelper.initI18nResource(defLng, resourceName, resolvedNs);
39
40
  defResources?.forEach(resource => i18n.addResourceBundle(defLng, resolvedNs, { [resourceName]: resource.data }, true, true));
40
41
  }
41
42
  }
@@ -68,7 +69,7 @@ export const useLanguage = () => {
68
69
  const { i18n } = useTranslation();
69
70
  const changeLng = useCallback(async (next) => {
70
71
  try {
71
- await setLanguage(next);
72
+ await i18nInstanceHelper.setLanguage(next);
72
73
  }
73
74
  catch (error) {
74
75
  logger('i18n').error('language switch failed', error);
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,gBAA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AY,EAAE,YAAY,EAAE,MAAM,CAAC,CAAA;AAC5D,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAA6C,EAAE;IACxE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAA;IAEjC,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,MAAM,kBAAkB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;QACvD,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AACnC,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './types.js';
2
+ export type * from './utils/instance/types.js';
2
3
  export { I18nContext, composePrefix, useI18n, useI18nLib, useI18nApp, useLanguage } from './context.js';
3
- export { prepareI18n, resolveInitialLanguage, setLanguage } from './utils/instance.js';
4
+ export { i18nInstanceHelper, createI18nInstanceHelper, prepareI18n, setLanguage } from './utils/instance.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACvG,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,mBAAmB,2BAA2B,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACvG,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA"}
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './types.js';
2
2
  export { I18nContext, composePrefix, useI18n, useI18nLib, useI18nApp, useLanguage } from './context.js';
3
- export { prepareI18n, resolveInitialLanguage, setLanguage } from './utils/instance.js';
3
+ export { i18nInstanceHelper, createI18nInstanceHelper, prepareI18n, setLanguage } from './utils/instance.js';
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACvG,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAE1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACvG,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { i18n } from 'i18next';
2
+ import type { ClientConfig } from '@owlmeans/client-context';
3
+ /** The process's i18next instance, created on the first render that asks. */
4
+ export declare const useI18nInstance: (config: ClientConfig) => i18n;
5
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/utils/hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAG5D,6EAA6E;AAC7E,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,IAItD,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { useMemo } from 'react';
2
+ import { i18nInstanceHelper } from './instance.js';
3
+ /** The process's i18next instance, created on the first render that asks. */
4
+ export const useI18nInstance = (config) => {
5
+ const instance = useMemo(() => i18nInstanceHelper.getI18nInstance(config), []);
6
+ return instance;
7
+ };
8
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/utils/hook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAoB,EAAQ,EAAE;IAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAE9E,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
@@ -1,2 +1,4 @@
1
+ export type * from './instance/types.js';
1
2
  export * from './instance.js';
3
+ export * from './hook.js';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,mBAAmB,qBAAqB,CAAA;AACxC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
@@ -1,2 +1,3 @@
1
1
  export * from './instance.js';
2
+ export * from './hook.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,40 @@
1
+ import type { i18n } from 'i18next';
2
+ import type { ClientConfig } from '@owlmeans/client-context';
3
+ /** The process's one i18next instance and the language it runs in. */
4
+ export interface I18nInstanceHelper {
5
+ /** The process's i18next instance, created on first use from `config`. */
6
+ getI18nInstance: (config: ClientConfig) => i18n;
7
+ /**
8
+ * Load `lng`'s registered loaders, then persist it and switch the instance to it. Race-safe:
9
+ * when several calls overlap, the latest one wins whatever order their loads finish in.
10
+ * Rejects when the language's pack fails to load; nothing is persisted or switched then.
11
+ *
12
+ * The choice is stored unconditionally: the interface language is strictly necessary storage — the
13
+ * visitor asked for it by choosing it — so no cookie decision stands between a switch and
14
+ * `owlmeans-lng`.
15
+ */
16
+ setLanguage: (lng: string) => Promise<void>;
17
+ /**
18
+ * Await the app's fallback language and its initial one (`resolveInitialLanguage`) before the app
19
+ * renders, so the first paint is already in the right language instead of flashing the
20
+ * fallback and then switching. Call it BEFORE `render(...)`. Resolves to the language the
21
+ * instance will start in: the fallback when the initial language's pack fails to load — the
22
+ * persisted choice is kept then, so the next visit retries it. Rejects only when the fallback
23
+ * language's own pack fails.
24
+ */
25
+ prepareI18n: (config: ClientConfig) => Promise<string>;
26
+ /**
27
+ * The language the app starts in: the one persisted under `owlmeans-lng` when it is still in
28
+ * `supportedLngs` (a person's explicit choice); else, on a first visit, the browser's own language
29
+ * (`navigator.languages` through `preferredLanguageOf` — a German browser opens in German); else
30
+ * `fallbackLng ?? defaultLng ?? DEFAULT_LNG`. The instance is initialized with this explicit `lng`,
31
+ * so a detector plugin installed afterwards (`instance.use(detector)`) is never consulted.
32
+ */
33
+ resolveInitialLanguage: (config: ClientConfig) => string;
34
+ /**
35
+ * The first of the browser's preferred languages the application supports — exact (`pt-BR`) or by
36
+ * its base (`de-DE` → `de`) — or `null` when none is. Pure, so a host (or a test) can pass the list.
37
+ */
38
+ preferredLanguageOf: (supportedLngs: readonly string[], preferred: readonly (string | null | undefined)[]) => string | null;
39
+ }
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/instance/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D,sEAAsE;AACtE,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,eAAe,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAA;IAC/C;;;;;;;;OAQG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACtD;;;;;;OAMG;IACH,sBAAsB,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAA;IACxD;;;OAGG;IACH,mBAAmB,EAAE,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,MAAM,GAAG,IAAI,CAAA;CAC5H"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/instance/types.ts"],"names":[],"mappings":""}
@@ -1,37 +1,14 @@
1
1
  import { type i18n } from 'i18next';
2
2
  import type { ClientConfig } from '@owlmeans/client-context';
3
- export declare const useI18nInstance: (config: ClientConfig) => i18n;
3
+ import type { I18nInstanceHelper } from './instance/types.js';
4
+ export declare const createI18nInstanceHelper: () => I18nInstanceHelper;
5
+ export declare const i18nInstanceHelper: I18nInstanceHelper;
6
+ /** @deprecated compat:factory-refactor — use `i18nInstanceHelper.getI18nInstance(…)` */
4
7
  export declare const getI18nInstance: (config: ClientConfig) => i18n;
5
- /**
6
- * Load `lng`'s registered loaders, then persist it and switch the instance to it. Race-safe:
7
- * when several calls overlap, the latest one wins whatever order their loads finish in.
8
- * Rejects when the language's pack fails to load; nothing is persisted or switched then.
9
- *
10
- * The choice is stored unconditionally: the interface language is strictly necessary storage — the
11
- * visitor asked for it by choosing it — so no cookie decision stands between a switch and
12
- * `owlmeans-lng`.
13
- */
8
+ /** @deprecated compat:factory-refactor — use `i18nInstanceHelper.setLanguage(…)` */
14
9
  export declare const setLanguage: (lng: string) => Promise<void>;
15
- /**
16
- * Await the app's fallback language and its initial one (`resolveInitialLanguage`) before the app
17
- * renders, so the first paint is already in the right language instead of flashing the
18
- * fallback and then switching. Call it BEFORE `render(...)`. Resolves to the language the
19
- * instance will start in: the fallback when the initial language's pack fails to load — the
20
- * persisted choice is kept then, so the next visit retries it. Rejects only when the fallback
21
- * language's own pack fails.
22
- */
10
+ /** @deprecated compat:factory-refactor — use `i18nInstanceHelper.prepareI18n(…)` */
23
11
  export declare const prepareI18n: (config: ClientConfig) => Promise<string>;
24
- /**
25
- * The language the app starts in: the one persisted under `owlmeans-lng` when it is still in
26
- * `supportedLngs` (a person's explicit choice); else, on a first visit, the browser's own language
27
- * (`navigator.languages` through `preferredLanguageOf` — a German browser opens in German); else
28
- * `fallbackLng ?? defaultLng ?? DEFAULT_LNG`. The instance is initialized with this explicit `lng`,
29
- * so a detector plugin installed afterwards (`instance.use(detector)`) is never consulted.
30
- */
31
- export declare const resolveInitialLanguage: (config: ClientConfig) => string;
32
- /**
33
- * The first of the browser's preferred languages the application supports — exact (`pt-BR`) or by
34
- * its base (`de-DE` → `de`) — or `null` when none is. Pure, so a host (or a test) can pass the list.
35
- */
12
+ /** @deprecated compat:factory-refactor — use `i18nInstanceHelper.preferredLanguageOf(…)` */
36
13
  export declare const preferredLanguageOf: (supportedLngs: readonly string[], preferred: readonly (string | null | undefined)[]) => string | null;
37
14
  //# sourceMappingURL=instance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/utils/instance.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,SAAS,CAAA;AAGnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAuB5D,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,IAItD,CAAA;AAED,eAAO,MAAM,eAAe,WAAY,YAAY,KAAG,IAC3B,CAAA;AAE5B;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAA8B,CAAA;AAwBpF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,WAAkB,YAAY,KAAG,OAAO,CAAC,MAAM,CAatE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,WAAY,YAAY,KAAG,MAO7D,CAAA;AAaD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,kBACf,SAAS,MAAM,EAAE,aAAa,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAClF,MAAM,GAAG,IAUX,CAAA"}
1
+ {"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/utils/instance.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,KAAK,EAAE,YA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