@molecule/app-i18n-i18next 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +115 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +28 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +405 -0
- package/dist/provider.js.map +1 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +16 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +21 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic i18next provider for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Implements the I18nProvider interface using i18next directly,
|
|
5
|
+
* without any framework-specific bindings. Suitable for Vue, Angular,
|
|
6
|
+
* Svelte, Solid, and any other framework.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { setProvider } from '@molecule/app-i18n'
|
|
11
|
+
* import { createI18nextProvider } from '@molecule/app-i18n-i18next'
|
|
12
|
+
*
|
|
13
|
+
* const provider = createI18nextProvider({
|
|
14
|
+
* defaultLocale: 'en',
|
|
15
|
+
* locales: [
|
|
16
|
+
* { code: 'en', name: 'English', translations: { ... } },
|
|
17
|
+
* { code: 'fr', name: 'French', translations: { ... } },
|
|
18
|
+
* ],
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* setProvider(provider)
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* **Startup locale vs. `detection`:** with `detection: true` (the default),
|
|
26
|
+
* `defaultLocale` is only the FALLBACK — the actual startup locale is
|
|
27
|
+
* whatever the browser detector resolves (querystring, then `navigator`, by
|
|
28
|
+
* default). Apps that want a pinned startup locale must pass
|
|
29
|
+
* `detection: false` (or an explicit `i18nextOptions.lng`).
|
|
30
|
+
*
|
|
31
|
+
* **`setLocale()` contract:** THROWS `Error('Locale "<code>" not found')`
|
|
32
|
+
* for a locale that was never registered — via the `locales` config,
|
|
33
|
+
* `addLocale()`, or `addTranslations()` (all three register it). It does
|
|
34
|
+
* NOT fall through to real i18next's own `changeLanguage()` degrade-to-
|
|
35
|
+
* `fallbackLng` behavior, matching `@molecule/app-i18n`'s core simple
|
|
36
|
+
* provider and `@molecule/api-i18n-simple`.
|
|
37
|
+
*
|
|
38
|
+
* @module
|
|
39
|
+
*/
|
|
40
|
+
export * from './provider.js';
|
|
41
|
+
export * from './types.js';
|
|
42
|
+
export * from './utilities.js';
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic i18next provider for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Implements the I18nProvider interface using i18next directly,
|
|
5
|
+
* without any framework-specific bindings. Suitable for Vue, Angular,
|
|
6
|
+
* Svelte, Solid, and any other framework.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { setProvider } from '@molecule/app-i18n'
|
|
11
|
+
* import { createI18nextProvider } from '@molecule/app-i18n-i18next'
|
|
12
|
+
*
|
|
13
|
+
* const provider = createI18nextProvider({
|
|
14
|
+
* defaultLocale: 'en',
|
|
15
|
+
* locales: [
|
|
16
|
+
* { code: 'en', name: 'English', translations: { ... } },
|
|
17
|
+
* { code: 'fr', name: 'French', translations: { ... } },
|
|
18
|
+
* ],
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* setProvider(provider)
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* **Startup locale vs. `detection`:** with `detection: true` (the default),
|
|
26
|
+
* `defaultLocale` is only the FALLBACK — the actual startup locale is
|
|
27
|
+
* whatever the browser detector resolves (querystring, then `navigator`, by
|
|
28
|
+
* default). Apps that want a pinned startup locale must pass
|
|
29
|
+
* `detection: false` (or an explicit `i18nextOptions.lng`).
|
|
30
|
+
*
|
|
31
|
+
* **`setLocale()` contract:** THROWS `Error('Locale "<code>" not found')`
|
|
32
|
+
* for a locale that was never registered — via the `locales` config,
|
|
33
|
+
* `addLocale()`, or `addTranslations()` (all three register it). It does
|
|
34
|
+
* NOT fall through to real i18next's own `changeLanguage()` degrade-to-
|
|
35
|
+
* `fallbackLng` behavior, matching `@molecule/app-i18n`'s core simple
|
|
36
|
+
* provider and `@molecule/api-i18n-simple`.
|
|
37
|
+
*
|
|
38
|
+
* @module
|
|
39
|
+
*/
|
|
40
|
+
export * from './provider.js';
|
|
41
|
+
export * from './types.js';
|
|
42
|
+
export * from './utilities.js';
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic i18next provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Uses only i18next directly (no react-i18next), making it suitable
|
|
5
|
+
* for Vue, Angular, Svelte, Solid, and any other framework.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type i18n as I18nInstance } from 'i18next';
|
|
10
|
+
import type { I18nextProviderConfig, I18nProvider } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a framework-agnostic i18n provider backed by i18next. Supports eager and lazy-loaded
|
|
13
|
+
* locale translations, browser language detection, custom plugins, and Intl-based number/date/list formatting.
|
|
14
|
+
* @param config - i18next provider configuration including `defaultLocale`, `locales` (with optional `loader` for lazy loading), `detection` flag, `debug`, `plugins`, and raw `i18nextOptions`.
|
|
15
|
+
* @returns An `I18nProvider` with translation, formatting, locale management methods, plus the underlying `i18n` instance and `initialize()` function.
|
|
16
|
+
*/
|
|
17
|
+
export declare const createI18nextProvider: (config?: I18nextProviderConfig) => I18nProvider & {
|
|
18
|
+
i18n: I18nInstance;
|
|
19
|
+
initialize: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Default provider instance.
|
|
23
|
+
*/
|
|
24
|
+
export declare const provider: I18nProvider & {
|
|
25
|
+
i18n: I18nInstance;
|
|
26
|
+
initialize: () => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAgB,EAAE,KAAK,IAAI,IAAI,YAAY,EAAoB,MAAM,SAAS,CAAA;AAK9E,OAAO,KAAK,EAEV,qBAAqB,EACrB,YAAY,EAKb,MAAM,YAAY,CAAA;AAmBnB;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAQ,qBAA0B,KACjC,YAAY,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CA8atE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ;UAnbK,YAAY;gBAAc,MAAM,OAAO,CAAC,IAAI,CAAC;CAmbxB,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic i18next provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Uses only i18next directly (no react-i18next), making it suitable
|
|
5
|
+
* for Vue, Angular, Svelte, Solid, and any other framework.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import i18next from 'i18next';
|
|
10
|
+
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
11
|
+
import { error, getLogger } from '@molecule/app-logger';
|
|
12
|
+
import { localeConfigToResources } from './utilities.js';
|
|
13
|
+
/**
|
|
14
|
+
* Milliseconds per relative-time unit (calendar units are approximations:
|
|
15
|
+
* 30-day month, 90-day quarter, 365-day year — matching the auto-select
|
|
16
|
+
* thresholds in `formatRelativeTime`).
|
|
17
|
+
*/
|
|
18
|
+
const UNIT_MS = {
|
|
19
|
+
second: 1000,
|
|
20
|
+
minute: 60_000,
|
|
21
|
+
hour: 3_600_000,
|
|
22
|
+
day: 86_400_000,
|
|
23
|
+
week: 604_800_000,
|
|
24
|
+
month: 2_592_000_000,
|
|
25
|
+
quarter: 7_776_000_000,
|
|
26
|
+
year: 31_536_000_000,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Creates a framework-agnostic i18n provider backed by i18next. Supports eager and lazy-loaded
|
|
30
|
+
* locale translations, browser language detection, custom plugins, and Intl-based number/date/list formatting.
|
|
31
|
+
* @param config - i18next provider configuration including `defaultLocale`, `locales` (with optional `loader` for lazy loading), `detection` flag, `debug`, `plugins`, and raw `i18nextOptions`.
|
|
32
|
+
* @returns An `I18nProvider` with translation, formatting, locale management methods, plus the underlying `i18n` instance and `initialize()` function.
|
|
33
|
+
*/
|
|
34
|
+
export const createI18nextProvider = (config = {}) => {
|
|
35
|
+
const { defaultLocale = 'en', fallbackLocale, locales = [], detection = true, detectionOptions, debug = false, i18nextOptions = {}, plugins = [], } = config;
|
|
36
|
+
// Store locale configs for metadata
|
|
37
|
+
const localeConfigs = new Map();
|
|
38
|
+
for (const locale of locales) {
|
|
39
|
+
localeConfigs.set(locale.code, locale);
|
|
40
|
+
}
|
|
41
|
+
const logger = getLogger('i18n');
|
|
42
|
+
// Create i18next instance
|
|
43
|
+
const i18n = i18next.createInstance();
|
|
44
|
+
// Track which lazy locales have been loaded
|
|
45
|
+
const loadedLocales = new Set();
|
|
46
|
+
// Registry of lazily-loaded content modules for auto-reload on locale change
|
|
47
|
+
const contentLoaders = new Map();
|
|
48
|
+
// Initialize flag
|
|
49
|
+
let initialized = false;
|
|
50
|
+
// The provider-owned `supportedLngs` list — null when the initial `locales`
|
|
51
|
+
// config is empty (no anchor) or the caller manages `supportedLngs` via
|
|
52
|
+
// `i18nextOptions`. Passed BY REFERENCE into `init()` and mutated by
|
|
53
|
+
// `addLocale`/`removeLocale`/`addTranslations` so late-registered locales
|
|
54
|
+
// stay changeable: i18next consults `supportedLngs` on every
|
|
55
|
+
// `changeLanguage()`, and an unlisted code silently resolves to
|
|
56
|
+
// `fallbackLng` (a late `addLocale('de')` would render English while
|
|
57
|
+
// claiming to be German).
|
|
58
|
+
const supportedLngsList = localeConfigs.size > 0 ? Array.from(localeConfigs.keys()) : null;
|
|
59
|
+
/**
|
|
60
|
+
* Adds a locale to `supportedLngs` (see the `supportedLngsList` note). Covers
|
|
61
|
+
* both the pre-init window (mutates the list `init()` will read) and post-init
|
|
62
|
+
* (i18next may have cloned the array into `i18n.options`).
|
|
63
|
+
* @param code - The locale code to register.
|
|
64
|
+
*/
|
|
65
|
+
const registerSupportedLng = (code) => {
|
|
66
|
+
if (supportedLngsList && !supportedLngsList.includes(code))
|
|
67
|
+
supportedLngsList.push(code);
|
|
68
|
+
const live = i18n.options?.supportedLngs;
|
|
69
|
+
if (Array.isArray(live) && live !== supportedLngsList && !live.includes(code))
|
|
70
|
+
live.push(code);
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Removes a locale from `supportedLngs` (see {@link registerSupportedLng}).
|
|
74
|
+
* @param code - The locale code to unregister.
|
|
75
|
+
*/
|
|
76
|
+
const unregisterSupportedLng = (code) => {
|
|
77
|
+
if (supportedLngsList) {
|
|
78
|
+
const i = supportedLngsList.indexOf(code);
|
|
79
|
+
if (i !== -1)
|
|
80
|
+
supportedLngsList.splice(i, 1);
|
|
81
|
+
}
|
|
82
|
+
const live = i18n.options?.supportedLngs;
|
|
83
|
+
if (Array.isArray(live) && live !== supportedLngsList) {
|
|
84
|
+
const i = live.indexOf(code);
|
|
85
|
+
if (i !== -1)
|
|
86
|
+
live.splice(i, 1);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Mirrors the active locale onto `<html lang>` + `<html dir>` so browsers,
|
|
91
|
+
* assistive tech, and CSS (`:dir(rtl)`, logical properties) see the real
|
|
92
|
+
* locale. Without this, screen readers kept the boot-time `lang` (wrong
|
|
93
|
+
* pronunciation rules — WCAG 3.1.1) and RTL locales (Arabic, Hebrew, Farsi,
|
|
94
|
+
* Urdu) rendered left-to-right. Guarded for non-DOM runtimes (SSR, native,
|
|
95
|
+
* vitest node).
|
|
96
|
+
* @param lng - The resolved locale code (post-detection/fallback).
|
|
97
|
+
*/
|
|
98
|
+
const applyDocumentLocale = (lng) => {
|
|
99
|
+
if (typeof document === 'undefined')
|
|
100
|
+
return;
|
|
101
|
+
document.documentElement.lang = lng;
|
|
102
|
+
document.documentElement.dir = localeConfigs.get(lng)?.direction || i18n.dir(lng);
|
|
103
|
+
};
|
|
104
|
+
// Memoized so concurrent callers (the auto-init at create time + a consumer's
|
|
105
|
+
// own `await provider.initialize()` / `setLocale()`) share ONE `i18n.init()`
|
|
106
|
+
// instead of racing a second init against the first.
|
|
107
|
+
let initPromise = null;
|
|
108
|
+
// Bundles registered before i18next finished initializing. i18next's deferred
|
|
109
|
+
// init REPLACES the resource store with the `resources` passed to `init()`,
|
|
110
|
+
// silently WIPING any bundle added in the create → init window — which is
|
|
111
|
+
// exactly the standard startup sequence (`setProvider(provider)` followed
|
|
112
|
+
// synchronously by `registerLocaleModule(...)` / `addTranslations(...)`).
|
|
113
|
+
// Queue those bundles and replay them once init settles so startup-registered
|
|
114
|
+
// translations survive.
|
|
115
|
+
const pendingBundles = [];
|
|
116
|
+
// Locale change listeners
|
|
117
|
+
const listeners = new Set();
|
|
118
|
+
const doInitialize = async () => {
|
|
119
|
+
const initOptions = {
|
|
120
|
+
// When detection is enabled, `lng` MUST stay unset: i18next only consults
|
|
121
|
+
// the language detector when no explicit `lng` is configured
|
|
122
|
+
// (`changeLanguage(lng)` skips `detect()` for a defined lng). Passing
|
|
123
|
+
// `lng: defaultLocale` unconditionally made `detection: true` (the
|
|
124
|
+
// default) silently dead — every browser started in `defaultLocale`
|
|
125
|
+
// regardless of `?lng=` or `navigator.language`. `fallbackLng` still
|
|
126
|
+
// anchors rendering to the default locale when nothing is detected or a
|
|
127
|
+
// key is missing. Callers can force a fixed startup locale with
|
|
128
|
+
// `detection: false` (or an explicit `i18nextOptions.lng`).
|
|
129
|
+
...(detection ? {} : { lng: defaultLocale }),
|
|
130
|
+
fallbackLng: fallbackLocale || defaultLocale,
|
|
131
|
+
debug,
|
|
132
|
+
resources: localeConfigToResources(locales),
|
|
133
|
+
// Anchor detection to the registered locale set: i18next's
|
|
134
|
+
// `getBestMatchFromCodes` resolves a detected regional variant (`en-US`,
|
|
135
|
+
// `pt-BR`) to its registered base (`en`, `pt`) — but ONLY when the exact
|
|
136
|
+
// code isn't claimed supported. Without `supportedLngs`, detection
|
|
137
|
+
// reported the raw code as `i18n.language`, no locale config matched it,
|
|
138
|
+
// and language pickers rendered a BLANK current-language label. Exact
|
|
139
|
+
// registered codes still win (`zh-TW` detects as `zh-TW`, not `zh`).
|
|
140
|
+
// NOTE: `nonExplicitSupportedLngs: true` would DEFEAT this — it makes
|
|
141
|
+
// `isSupportedCode('en-US')` true via the base, so the raw `en-US` is
|
|
142
|
+
// accepted on the first pass instead of normalized to `en`. Callers can
|
|
143
|
+
// still override via `i18nextOptions.supportedLngs`. The list is the
|
|
144
|
+
// provider-owned `supportedLngsList` (mutated by addLocale/removeLocale
|
|
145
|
+
// — see above).
|
|
146
|
+
...(supportedLngsList ? { supportedLngs: supportedLngsList } : {}),
|
|
147
|
+
interpolation: {
|
|
148
|
+
escapeValue: false, // Frameworks handle escaping
|
|
149
|
+
},
|
|
150
|
+
...i18nextOptions,
|
|
151
|
+
};
|
|
152
|
+
// Add language detector if enabled
|
|
153
|
+
if (detection) {
|
|
154
|
+
i18n.use(LanguageDetector);
|
|
155
|
+
// Default: detect from querystring and navigator only, no caching.
|
|
156
|
+
// Users can explicitly enable localStorage caching via detectionOptions.
|
|
157
|
+
initOptions.detection = detectionOptions || {
|
|
158
|
+
order: ['querystring', 'navigator'],
|
|
159
|
+
caches: [], // No default caching - storage must be explicitly configured
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// Apply custom plugins (e.g. react-i18next's initReactI18next)
|
|
163
|
+
for (const plugin of plugins) {
|
|
164
|
+
i18n.use(plugin);
|
|
165
|
+
}
|
|
166
|
+
await i18n.init(initOptions);
|
|
167
|
+
// If detection landed on a locale whose translations are lazy-loaded,
|
|
168
|
+
// load them now — loaders otherwise only run inside setLocale(), so the
|
|
169
|
+
// provider would REPORT the detected locale while rendering fallbackLng
|
|
170
|
+
// text (language picker says "Français", every string is English).
|
|
171
|
+
// `i18n.languages` is the resolution chain (detected code, its base
|
|
172
|
+
// language, fallbacks), so a detected `fr-FR` also loads a `fr` config.
|
|
173
|
+
for (const lng of i18n.languages ?? []) {
|
|
174
|
+
const config = localeConfigs.get(lng);
|
|
175
|
+
if (config?.loader && !loadedLocales.has(lng)) {
|
|
176
|
+
const translations = await config.loader();
|
|
177
|
+
i18n.addResourceBundle(lng, 'translation', translations, true, true);
|
|
178
|
+
loadedLocales.add(lng);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Listen for language changes
|
|
182
|
+
i18n.on('languageChanged', (lng) => {
|
|
183
|
+
applyDocumentLocale(lng);
|
|
184
|
+
listeners.forEach((listener) => listener(lng));
|
|
185
|
+
});
|
|
186
|
+
initialized = true;
|
|
187
|
+
// Apply the initial (detected or default) locale to the document — the
|
|
188
|
+
// languageChanged listener only fires on *changes* after this point.
|
|
189
|
+
applyDocumentLocale(i18n.language || defaultLocale);
|
|
190
|
+
// Replay bundles that were registered while init was still settling —
|
|
191
|
+
// init just reset the store to `initOptions.resources`, dropping them.
|
|
192
|
+
for (const bundle of pendingBundles) {
|
|
193
|
+
i18n.addResourceBundle(bundle.lng, bundle.ns, bundle.translations, true, true);
|
|
194
|
+
}
|
|
195
|
+
pendingBundles.length = 0;
|
|
196
|
+
};
|
|
197
|
+
const initialize = () => {
|
|
198
|
+
if (!initPromise) {
|
|
199
|
+
initPromise = doInitialize();
|
|
200
|
+
}
|
|
201
|
+
return initPromise;
|
|
202
|
+
};
|
|
203
|
+
// Auto-initialize
|
|
204
|
+
initialize().catch((err) => error('i18next provider initialization failed', err));
|
|
205
|
+
// Named (rather than `return { ... }`) so methods can reference each other
|
|
206
|
+
// without `this` — `formatDate({ relative: true })` crashed with an opaque
|
|
207
|
+
// "Cannot read properties of undefined" when callers destructured methods
|
|
208
|
+
// off the provider (`const { formatDate } = getProvider()`).
|
|
209
|
+
const provider = {
|
|
210
|
+
i18n,
|
|
211
|
+
initialize,
|
|
212
|
+
getLocale: () => i18n.language || defaultLocale,
|
|
213
|
+
async setLocale(locale) {
|
|
214
|
+
if (!initialized)
|
|
215
|
+
await initialize();
|
|
216
|
+
// Fleet contract (documented on `I18nProvider.setLocale` in
|
|
217
|
+
// @molecule/app-i18n): reject an unregistered locale instead of
|
|
218
|
+
// silently degrading to `fallbackLng` text. Real i18next's own
|
|
219
|
+
// `changeLanguage()` never throws for an unknown code — it just
|
|
220
|
+
// renders fallback translations while `getLocale()` reports the
|
|
221
|
+
// unregistered code — which let this bond diverge from the core
|
|
222
|
+
// simple provider (which throws). "Registered" means added via the
|
|
223
|
+
// `locales` config, `addLocale()`, or `addTranslations()` (all three
|
|
224
|
+
// populate `localeConfigs`).
|
|
225
|
+
if (!localeConfigs.has(locale)) {
|
|
226
|
+
throw new Error(`Locale "${locale}" not found`);
|
|
227
|
+
}
|
|
228
|
+
// Load lazy translations if this locale has a loader and hasn't been loaded yet
|
|
229
|
+
const localeConfig = localeConfigs.get(locale);
|
|
230
|
+
if (localeConfig?.loader && !loadedLocales.has(locale)) {
|
|
231
|
+
const translations = await localeConfig.loader();
|
|
232
|
+
i18n.addResourceBundle(locale, 'translation', translations, true, true);
|
|
233
|
+
loadedLocales.add(locale);
|
|
234
|
+
}
|
|
235
|
+
// Reload all registered content modules for the new locale.
|
|
236
|
+
// This happens BEFORE changeLanguage so content keys are available
|
|
237
|
+
// when the languageChanged event fires and UI components re-render.
|
|
238
|
+
if (contentLoaders.size > 0) {
|
|
239
|
+
logger.debug('Reloading content modules', contentLoaders.size, locale);
|
|
240
|
+
await Promise.all(Array.from(contentLoaders.values()).map((loader) => loader(locale)));
|
|
241
|
+
}
|
|
242
|
+
await i18n.changeLanguage(locale);
|
|
243
|
+
},
|
|
244
|
+
getLocales: () => {
|
|
245
|
+
return Array.from(localeConfigs.values());
|
|
246
|
+
},
|
|
247
|
+
addLocale(config) {
|
|
248
|
+
localeConfigs.set(config.code, config);
|
|
249
|
+
registerSupportedLng(config.code);
|
|
250
|
+
if (!initialized) {
|
|
251
|
+
pendingBundles.push({
|
|
252
|
+
lng: config.code,
|
|
253
|
+
ns: 'translation',
|
|
254
|
+
translations: config.translations ?? {},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
i18n.addResourceBundle(config.code, 'translation', config.translations ?? {}, true, true);
|
|
258
|
+
listeners.forEach((listener) => listener(i18n.language));
|
|
259
|
+
},
|
|
260
|
+
removeLocale(code) {
|
|
261
|
+
const removed = localeConfigs.delete(code);
|
|
262
|
+
if (removed) {
|
|
263
|
+
unregisterSupportedLng(code);
|
|
264
|
+
// Also drop any not-yet-replayed startup bundle so the deferred init
|
|
265
|
+
// replay can't resurrect a locale that was explicitly removed.
|
|
266
|
+
for (let i = pendingBundles.length - 1; i >= 0; i--) {
|
|
267
|
+
if (pendingBundles[i].lng === code)
|
|
268
|
+
pendingBundles.splice(i, 1);
|
|
269
|
+
}
|
|
270
|
+
i18n.removeResourceBundle(code, 'translation');
|
|
271
|
+
listeners.forEach((listener) => listener(i18n.language));
|
|
272
|
+
}
|
|
273
|
+
return removed;
|
|
274
|
+
},
|
|
275
|
+
addTranslations(locale, translations, namespace = 'translation') {
|
|
276
|
+
if (!initialized) {
|
|
277
|
+
pendingBundles.push({ lng: locale, ns: namespace, translations });
|
|
278
|
+
}
|
|
279
|
+
i18n.addResourceBundle(locale, namespace, translations, true, true);
|
|
280
|
+
// Auto-register the locale's metadata entry if it doesn't exist yet —
|
|
281
|
+
// mirrors the api-i18n-simple bond and the app-i18n core provider,
|
|
282
|
+
// whose addTranslations() auto-creates an unknown locale rather than
|
|
283
|
+
// leaving it unregistered. Without this, a locale populated ONLY via
|
|
284
|
+
// addTranslations() (no `locales` config entry, no addLocale() call)
|
|
285
|
+
// never satisfies setLocale()'s "is this locale registered?" check,
|
|
286
|
+
// and getLocales() silently omits it too.
|
|
287
|
+
let existing = localeConfigs.get(locale);
|
|
288
|
+
if (!existing) {
|
|
289
|
+
existing = { code: locale, name: locale, translations: {} };
|
|
290
|
+
localeConfigs.set(locale, existing);
|
|
291
|
+
registerSupportedLng(locale);
|
|
292
|
+
}
|
|
293
|
+
existing.translations = {
|
|
294
|
+
...existing.translations,
|
|
295
|
+
...translations,
|
|
296
|
+
};
|
|
297
|
+
// Notify listeners when translations are added for the active locale
|
|
298
|
+
// so that UI components re-render with the new content.
|
|
299
|
+
if (locale === i18n.language) {
|
|
300
|
+
listeners.forEach((listener) => listener(locale));
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
t(key, values, options) {
|
|
304
|
+
const opts = { ...values };
|
|
305
|
+
if (options?.defaultValue !== undefined)
|
|
306
|
+
opts.defaultValue = options.defaultValue;
|
|
307
|
+
if (options?.count !== undefined)
|
|
308
|
+
opts.count = options.count;
|
|
309
|
+
return i18n.t(key, opts);
|
|
310
|
+
},
|
|
311
|
+
exists(key) {
|
|
312
|
+
return i18n.exists(key);
|
|
313
|
+
},
|
|
314
|
+
formatNumber(value, options) {
|
|
315
|
+
const locale = i18n.language;
|
|
316
|
+
return new Intl.NumberFormat(locale, options).format(value);
|
|
317
|
+
},
|
|
318
|
+
formatDate(value, options) {
|
|
319
|
+
const locale = i18n.language;
|
|
320
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
321
|
+
// Handle invalid dates gracefully
|
|
322
|
+
if (isNaN(date.getTime())) {
|
|
323
|
+
return i18n.t('i18n.date.invalidDate', { defaultValue: 'Invalid Date' });
|
|
324
|
+
}
|
|
325
|
+
if (options?.relative) {
|
|
326
|
+
return provider.formatRelativeTime(date);
|
|
327
|
+
}
|
|
328
|
+
return new Intl.DateTimeFormat(locale, {
|
|
329
|
+
dateStyle: options?.dateStyle,
|
|
330
|
+
timeStyle: options?.timeStyle,
|
|
331
|
+
}).format(date);
|
|
332
|
+
},
|
|
333
|
+
formatRelativeTime(value, options) {
|
|
334
|
+
const locale = i18n.language;
|
|
335
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
336
|
+
const now = Date.now();
|
|
337
|
+
const diff = date.getTime() - now;
|
|
338
|
+
// An explicit unit means "express the difference IN that unit" — convert
|
|
339
|
+
// the millisecond diff before formatting. Previously the raw seconds
|
|
340
|
+
// count was labeled with the unit ("7,200 hours ago" for 2 hours).
|
|
341
|
+
if (options?.unit) {
|
|
342
|
+
const unitMs = UNIT_MS[options.unit.replace(/s$/, '')] ?? 1000;
|
|
343
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(Math.round(diff / unitMs), options.unit);
|
|
344
|
+
}
|
|
345
|
+
const absDiff = Math.abs(diff);
|
|
346
|
+
// Declared without initializers: the if/else chain below is exhaustive (its final
|
|
347
|
+
// `else` always assigns), so any seed value here is dead code.
|
|
348
|
+
let unit;
|
|
349
|
+
let unitValue;
|
|
350
|
+
if (absDiff < 60000) {
|
|
351
|
+
unit = 'second';
|
|
352
|
+
unitValue = Math.round(diff / 1000);
|
|
353
|
+
}
|
|
354
|
+
else if (absDiff < 3600000) {
|
|
355
|
+
unit = 'minute';
|
|
356
|
+
unitValue = Math.round(diff / 60000);
|
|
357
|
+
}
|
|
358
|
+
else if (absDiff < 86400000) {
|
|
359
|
+
unit = 'hour';
|
|
360
|
+
unitValue = Math.round(diff / 3600000);
|
|
361
|
+
}
|
|
362
|
+
else if (absDiff < 2592000000) {
|
|
363
|
+
unit = 'day';
|
|
364
|
+
unitValue = Math.round(diff / 86400000);
|
|
365
|
+
}
|
|
366
|
+
else if (absDiff < 31536000000) {
|
|
367
|
+
unit = 'month';
|
|
368
|
+
unitValue = Math.round(diff / 2592000000);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
unit = 'year';
|
|
372
|
+
unitValue = Math.round(diff / 31536000000);
|
|
373
|
+
}
|
|
374
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(Math.round(unitValue), unit);
|
|
375
|
+
},
|
|
376
|
+
formatList(values, options) {
|
|
377
|
+
const locale = i18n.language;
|
|
378
|
+
return new Intl.ListFormat(locale, { type: options?.type || 'conjunction' }).format(values);
|
|
379
|
+
},
|
|
380
|
+
onLocaleChange(listener) {
|
|
381
|
+
listeners.add(listener);
|
|
382
|
+
return () => listeners.delete(listener);
|
|
383
|
+
},
|
|
384
|
+
getDirection() {
|
|
385
|
+
const locale = i18n.language;
|
|
386
|
+
const config = localeConfigs.get(locale);
|
|
387
|
+
// An explicit LocaleConfig.direction wins; otherwise ask i18next, which
|
|
388
|
+
// knows the RTL language set — a hardcoded 'ltr' fallback rendered Arabic/
|
|
389
|
+
// Hebrew/Farsi/Urdu left-to-right whenever `direction` wasn't declared.
|
|
390
|
+
return config?.direction || i18n.dir(locale);
|
|
391
|
+
},
|
|
392
|
+
registerContent(module, loader) {
|
|
393
|
+
if (contentLoaders.has(module))
|
|
394
|
+
return;
|
|
395
|
+
contentLoaders.set(module, loader);
|
|
396
|
+
logger.debug('Registered content module', module);
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
return provider;
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Default provider instance.
|
|
403
|
+
*/
|
|
404
|
+
export const provider = createI18nextProvider();
|
|
405
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,OAAwD,MAAM,SAAS,CAAA;AAC9E,OAAO,gBAAgB,MAAM,kCAAkC,CAAA;AAE/D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAWvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAExD;;;;GAIG;AACH,MAAM,OAAO,GAA2B;IACtC,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,UAAU;IACf,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,cAAc;CACrB,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,SAAgC,EAAE,EACsC,EAAE;IAC1E,MAAM,EACJ,aAAa,GAAG,IAAI,EACpB,cAAc,EACd,OAAO,GAAG,EAAE,EACZ,SAAS,GAAG,IAAI,EAChB,gBAAgB,EAChB,KAAK,GAAG,KAAK,EACb,cAAc,GAAG,EAAE,EACnB,OAAO,GAAG,EAAE,GACb,GAAG,MAAM,CAAA;IAEV,oCAAoC;IACpC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAwB,CAAA;IACrD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,aAAa,CAAC,GA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,EAChB,OAA2D;YAE3D,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAA;YAC5B,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC7F,CAAC;QAED,cAAc,CAAC,QAAkC;YAC/C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACzC,CAAC;QAED,YAAY;YACV,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAA;YAC5B,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACxC,wEAAwE;YACxE,2EAA2E;YAC3E,wEAAwE;YACxE,OAAO,MAAM,EAAE,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAC9C,CAAC;QAED,eAAe,CAAC,MAAc,EAAE,MAAyC;YACvE,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAM;YACtC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YAClC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAA;QACnD,CAAC;KACF,CAAA;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for i18next provider.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { InitOptions } from 'i18next';
|
|
7
|
+
import type { DateFormatOptions, I18nProvider, InterpolationValues, LocaleConfig, NumberFormatOptions, Translations } from '@molecule/app-i18n';
|
|
8
|
+
export type { DateFormatOptions, I18nProvider, InterpolationValues, LocaleConfig, NumberFormatOptions, Translations, };
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for the i18next provider.
|
|
11
|
+
*/
|
|
12
|
+
export interface I18nextProviderConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Default locale code.
|
|
15
|
+
*/
|
|
16
|
+
defaultLocale?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Fallback locale code.
|
|
19
|
+
*/
|
|
20
|
+
fallbackLocale?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Available locales with translations.
|
|
23
|
+
*/
|
|
24
|
+
locales?: LocaleConfig[];
|
|
25
|
+
/**
|
|
26
|
+
* Enable language detection.
|
|
27
|
+
*/
|
|
28
|
+
detection?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Language detection options.
|
|
31
|
+
*/
|
|
32
|
+
detectionOptions?: {
|
|
33
|
+
order?: ('querystring' | 'cookie' | 'localStorage' | 'sessionStorage' | 'navigator' | 'htmlTag')[];
|
|
34
|
+
lookupQuerystring?: string;
|
|
35
|
+
lookupCookie?: string;
|
|
36
|
+
lookupLocalStorage?: string;
|
|
37
|
+
lookupSessionStorage?: string;
|
|
38
|
+
caches?: ('localStorage' | 'cookie')[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Debug mode.
|
|
42
|
+
*/
|
|
43
|
+
debug?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Custom i18next initialization options.
|
|
46
|
+
*/
|
|
47
|
+
i18nextOptions?: Partial<InitOptions>;
|
|
48
|
+
/**
|
|
49
|
+
* i18next plugins to apply before initialization.
|
|
50
|
+
*
|
|
51
|
+
* Each plugin is passed to `i18n.use()` before `i18n.init()`.
|
|
52
|
+
* Useful for framework integrations (e.g. react-i18next's `initReactI18next`).
|
|
53
|
+
*/
|
|
54
|
+
plugins?: unknown[];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACb,MAAM,oBAAoB,CAAA;AAG3B,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,YAAY,GACb,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,EAAE,CAAA;IAExB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,gBAAgB,CAAC,EAAE;QACjB,KAAK,CAAC,EAAE,CACN,aAAa,GAAG,QAAQ,GAAG,cAAc,GAAG,gBAAgB,GAAG,WAAW,GAAG,SAAS,CACvF,EAAE,CAAA;QACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;QAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,kBAAkB,CAAC,EAAE,MAAM,CAAA;QAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAA;QAC7B,MAAM,CAAC,EAAE,CAAC,cAAc,GAAG,QAAQ,CAAC,EAAE,CAAA;KACvC,CAAA;IAED;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAErC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for i18next provider.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { LocaleConfig, Translations } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Converts an array of molecule `LocaleConfig` objects to the i18next resource bundle format.
|
|
9
|
+
* Each locale's translations are placed under a `translation` namespace keyed by locale code.
|
|
10
|
+
* @param locales - The locale configurations with code and translations.
|
|
11
|
+
* @returns An i18next-compatible resources object (e.g. `{ en: { translation: { ... } } }`).
|
|
12
|
+
*/
|
|
13
|
+
export declare const localeConfigToResources: (locales: LocaleConfig[]) => Record<string, {
|
|
14
|
+
translation: Translations;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,YAAY,EAAE,KACtB,MAAM,CAAC,MAAM,EAAE;IAAE,WAAW,EAAE,YAAY,CAAA;CAAE,CAQ9C,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for i18next provider.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts an array of molecule `LocaleConfig` objects to the i18next resource bundle format.
|
|
8
|
+
* Each locale's translations are placed under a `translation` namespace keyed by locale code.
|
|
9
|
+
* @param locales - The locale configurations with code and translations.
|
|
10
|
+
* @returns An i18next-compatible resources object (e.g. `{ en: { translation: { ... } } }`).
|
|
11
|
+
*/
|
|
12
|
+
export const localeConfigToResources = (locales) => {
|
|
13
|
+
const resources = {};
|
|
14
|
+
for (const locale of locales) {
|
|
15
|
+
resources[locale.code] = {
|
|
16
|
+
translation: locale.translations ?? {},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return resources;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,OAAuB,EACwB,EAAE;IACjD,MAAM,SAAS,GAAkD,EAAE,CAAA;IACnE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;YACvB,WAAW,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE;SACvC,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-i18n-i18next",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Framework-agnostic i18next provider for molecule.dev",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"i18next": "26.3.6",
|
|
24
|
+
"i18next-browser-languagedetector": "8.2.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "26.1.2",
|
|
28
|
+
"typescript": "6.0.3",
|
|
29
|
+
"vitest": "4.1.10"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@molecule/app-i18n": "^1.0.0",
|
|
33
|
+
"@molecule/app-logger": "^1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
38
|
+
"directory": "packages/app/bonds/i18n/i18next"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/bonds/i18n/i18next",
|
|
41
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|