@burojs/i18n-core 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -6
- package/dist/index.cjs +245 -215
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +215 -150
- package/dist/index.d.ts +215 -150
- package/dist/index.js +221 -209
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -35,6 +35,29 @@ resources.<resource>.fields.<field>.label → fields.<field>.label → <
|
|
|
35
35
|
|
|
36
36
|
`resolveKey` implements that chain and is exported for callers that need to know *which* key won.
|
|
37
37
|
|
|
38
|
+
## Counts
|
|
39
|
+
|
|
40
|
+
Text that shows a number is a **count family**: one key per CLDR plural
|
|
41
|
+
category of the locale, `<key>_one`, `<key>_few`, `<key>_many`, `<key>_other`.
|
|
42
|
+
Ask for it with `count` — the facade picks the form with the locale's own
|
|
43
|
+
rules and interpolates `{{count}}`:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// ru: count_one «{{count}} документ», count_few «{{count}} документа», count_many «{{count}} документов»
|
|
47
|
+
i18n.t('resources.document.count', { count: 2 }); // «2 документа»
|
|
48
|
+
i18n.t('resources.document.count', { count: 5 }); // «5 документов»
|
|
49
|
+
i18n.has('resources.document.count', { count: 5 }); // true
|
|
50
|
+
i18n.has('resources.document.count'); // false — a family is only present for a count
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A count family is for counted text only. A collection title is not a count
|
|
54
|
+
form — Russian «Документы» is none of `one`, `few` or `many` — so a resource's
|
|
55
|
+
title is its own key, `labelPlural`.
|
|
56
|
+
|
|
57
|
+
An empty-string translation counts as missing: the adapter walks on to the
|
|
58
|
+
fallback locale, then the caller's default in code. Which key each element of
|
|
59
|
+
an app reads is in one table in [`docs/i18n-guide.md`](../../docs/i18n-guide.md).
|
|
60
|
+
|
|
38
61
|
## Locale registry
|
|
39
62
|
|
|
40
63
|
Most apps assemble their `resources` from more than one place: the framework
|
|
@@ -51,7 +74,9 @@ import {
|
|
|
51
74
|
} from '@burojs/i18n-core';
|
|
52
75
|
import { en as frameworkEn } from '@burojs/react';
|
|
53
76
|
|
|
54
|
-
|
|
77
|
+
// `primary` is the locale whose text is the default in code. It is required, and it is the only
|
|
78
|
+
// place the app names it: everything else reads `registry.primary()`.
|
|
79
|
+
const registry = createLocaleRegistry({ primary: 'en' });
|
|
55
80
|
registry.register({ locale: 'en', priority: 0, source: '@burojs/react', bundle: frameworkEn });
|
|
56
81
|
|
|
57
82
|
// One file per locale, globbed by the bundler — dropping in `es.ts` is the
|
|
@@ -61,12 +86,19 @@ for (const c of localeContributionsFromGlob(glob, { source: 'app', priority: 10
|
|
|
61
86
|
registry.register(c);
|
|
62
87
|
}
|
|
63
88
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
// Starts in, and falls back to, registry.primary(). Override either when needed:
|
|
90
|
+
// `defaultLocale` for a stored choice, `fallbackLocale` for a per-locale chain
|
|
91
|
+
// such as { fr: ['es'], default: ['en'] }.
|
|
92
|
+
const i18n = await createI18nFromRegistry(registry);
|
|
68
93
|
```
|
|
69
94
|
|
|
95
|
+
`buildResources()` — and so `createI18nFromRegistry` — throws when no
|
|
96
|
+
contribution is registered for the primary locale: the fallback chain would
|
|
97
|
+
end at a locale with no bundle, and a language switcher built from
|
|
98
|
+
`registry.locales()` would not offer it. That is almost always a typo or a
|
|
99
|
+
glob that missed its file; an app with genuinely no strings of its own for the
|
|
100
|
+
primary locale registers an empty bundle for it.
|
|
101
|
+
|
|
70
102
|
A key collision within one (locale, namespace) resolves by the higher
|
|
71
103
|
DECLARED `priority`, never by which contribution happened to register last.
|
|
72
104
|
`localeContributionsFromGlob` is bundler-agnostic (same reasoning as
|
|
@@ -80,7 +112,7 @@ this package — is the one that actually calls the bundler API.
|
|
|
80
112
|
- **`createI18nextAdapter`** — the default backend; swap it to use another i18n runtime.
|
|
81
113
|
- **`createResourceI18n` / `ResourceI18n`** — a resource-scoped view of the facade.
|
|
82
114
|
- **`resolveKey`** — the fallback-chain resolver, usable standalone.
|
|
83
|
-
- **`createLocaleRegistry` / `LocaleRegistry`** — merges per-source locale contributions by declared priority.
|
|
115
|
+
- **`createLocaleRegistry({ primary })` / `LocaleRegistry`** — merges per-source locale contributions by declared priority, and declares the primary locale (`registry.primary()`).
|
|
84
116
|
- **`localeContributionsFromGlob`** — turns a bundler glob of per-locale files into contributions.
|
|
85
117
|
- **`createI18nFromRegistry`** — wires a `LocaleRegistry` straight into `createI18nextAdapter` + `createI18n`.
|
|
86
118
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,235 +1,265 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let i18next = require("i18next");
|
|
25
|
+
i18next = __toESM(i18next, 1);
|
|
26
|
+
//#region src/lookup.ts
|
|
10
27
|
function resolveKey(key, resource) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
candidates.push(`resources._.${key}`);
|
|
20
|
-
candidates.push(`common.${key}`);
|
|
21
|
-
candidates.push(key);
|
|
22
|
-
return candidates;
|
|
28
|
+
if (!key) return [];
|
|
29
|
+
if (key.startsWith("resources.") || key.startsWith("enums.") || key.startsWith("common.") || key.startsWith("blocks.")) return [key];
|
|
30
|
+
const candidates = [];
|
|
31
|
+
if (resource) candidates.push(`resources.${resource}.${key}`);
|
|
32
|
+
candidates.push(`resources._.${key}`);
|
|
33
|
+
candidates.push(`common.${key}`);
|
|
34
|
+
candidates.push(key);
|
|
35
|
+
return candidates;
|
|
23
36
|
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/i18next-adapter.ts
|
|
39
|
+
const MISSING = "\0";
|
|
24
40
|
async function createI18nextAdapter(config) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
41
|
+
const instance = i18next.default.createInstance();
|
|
42
|
+
await instance.init({
|
|
43
|
+
lng: config.defaultLocale,
|
|
44
|
+
fallbackLng: config.fallbackLocale ?? config.defaultLocale,
|
|
45
|
+
supportedLngs: config.locales,
|
|
46
|
+
resources: config.resources,
|
|
47
|
+
keySeparator: config.keySeparator ?? ".",
|
|
48
|
+
nsSeparator: config.nsSeparator ?? false,
|
|
49
|
+
defaultNS: "common",
|
|
50
|
+
interpolation: { escapeValue: false },
|
|
51
|
+
returnNull: false,
|
|
52
|
+
returnEmptyString: false
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
t(key, params) {
|
|
56
|
+
const dotIdx = key.indexOf(".");
|
|
57
|
+
if (dotIdx === -1) return instance.t(key, params);
|
|
58
|
+
const ns = key.substring(0, dotIdx);
|
|
59
|
+
const subKey = key.substring(dotIdx + 1);
|
|
60
|
+
const result = instance.t(subKey, {
|
|
61
|
+
ns,
|
|
62
|
+
...params ?? {}
|
|
63
|
+
});
|
|
64
|
+
const count = typeof params?.count === "number" ? params.count : void 0;
|
|
65
|
+
if (result === subKey && !instance.exists(subKey, count === void 0 ? { ns } : {
|
|
66
|
+
ns,
|
|
67
|
+
count
|
|
68
|
+
})) return key;
|
|
69
|
+
return result;
|
|
70
|
+
},
|
|
71
|
+
async changeLocale(locale) {
|
|
72
|
+
await instance.changeLanguage(locale);
|
|
73
|
+
},
|
|
74
|
+
async loadNamespace(namespace, _locale) {
|
|
75
|
+
await instance.loadNamespaces(namespace);
|
|
76
|
+
},
|
|
77
|
+
getCurrentLocale() {
|
|
78
|
+
return instance.language;
|
|
79
|
+
},
|
|
80
|
+
onLocaleChange(cb) {
|
|
81
|
+
instance.on("languageChanged", cb);
|
|
82
|
+
return () => instance.off("languageChanged", cb);
|
|
83
|
+
},
|
|
84
|
+
hasKey(key, options) {
|
|
85
|
+
const dotIdx = key.indexOf(".");
|
|
86
|
+
const ns = dotIdx === -1 ? void 0 : key.substring(0, dotIdx);
|
|
87
|
+
const subKey = dotIdx === -1 ? key : key.substring(dotIdx + 1);
|
|
88
|
+
const lookup = {
|
|
89
|
+
...ns === void 0 ? {} : { ns },
|
|
90
|
+
...options?.count === void 0 ? {} : { count: options.count }
|
|
91
|
+
};
|
|
92
|
+
const value = instance.t(subKey, {
|
|
93
|
+
...lookup,
|
|
94
|
+
returnObjects: true,
|
|
95
|
+
defaultValue: MISSING
|
|
96
|
+
});
|
|
97
|
+
return value !== MISSING && (typeof value !== "object" || value === null);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
78
100
|
}
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/i18n.ts
|
|
81
103
|
function createI18n(config) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
adapter
|
|
115
|
-
};
|
|
104
|
+
const { adapter, warnOnMissing = true, locales } = config;
|
|
105
|
+
return {
|
|
106
|
+
t(key, options) {
|
|
107
|
+
const count = options?.count;
|
|
108
|
+
const params = count === void 0 ? options?.params : {
|
|
109
|
+
...options?.params,
|
|
110
|
+
count
|
|
111
|
+
};
|
|
112
|
+
const candidates = resolveKey(key, options?.resource);
|
|
113
|
+
for (const candidate of candidates) if (count === void 0 ? adapter.hasKey(candidate) : adapter.hasKey(candidate, { count })) return adapter.t(candidate, params);
|
|
114
|
+
if (warnOnMissing && typeof console !== "undefined") console.warn(`[@burojs/i18n-core] Missing translation: '${key}'${options?.resource ? ` (resource: ${options.resource})` : ""}`);
|
|
115
|
+
return key;
|
|
116
|
+
},
|
|
117
|
+
has(key, options) {
|
|
118
|
+
const count = options?.count;
|
|
119
|
+
return resolveKey(key, options?.resource).some((candidate) => count === void 0 ? adapter.hasKey(candidate) : adapter.hasKey(candidate, { count }));
|
|
120
|
+
},
|
|
121
|
+
async changeLocale(locale) {
|
|
122
|
+
await adapter.changeLocale(locale);
|
|
123
|
+
},
|
|
124
|
+
getCurrentLocale() {
|
|
125
|
+
return adapter.getCurrentLocale();
|
|
126
|
+
},
|
|
127
|
+
onLocaleChange(cb) {
|
|
128
|
+
return adapter.onLocaleChange?.(cb) ?? (() => {});
|
|
129
|
+
},
|
|
130
|
+
async loadNamespace(namespace, locale) {
|
|
131
|
+
await adapter.loadNamespace(namespace, locale);
|
|
132
|
+
},
|
|
133
|
+
...locales === void 0 ? {} : { locales },
|
|
134
|
+
adapter
|
|
135
|
+
};
|
|
116
136
|
}
|
|
117
|
-
|
|
118
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/resource-context.ts
|
|
119
139
|
function createResourceI18n(i18n, resource) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
return {
|
|
141
|
+
t(key, options) {
|
|
142
|
+
return i18n.t(key, {
|
|
143
|
+
resource: options?.resource ?? resource,
|
|
144
|
+
params: options?.params,
|
|
145
|
+
...options?.count === void 0 ? {} : { count: options.count }
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
changeLocale: i18n.changeLocale,
|
|
149
|
+
getCurrentLocale: i18n.getCurrentLocale,
|
|
150
|
+
resource
|
|
151
|
+
};
|
|
131
152
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/locale-registry.ts
|
|
155
|
+
const DEFAULT_NAMESPACE = "common";
|
|
135
156
|
function isPlainObject(value) {
|
|
136
|
-
|
|
157
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
137
158
|
}
|
|
138
159
|
function mergeBundle(base, overlay) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
160
|
+
const out = { ...base };
|
|
161
|
+
for (const [key, overlayValue] of Object.entries(overlay)) {
|
|
162
|
+
const baseValue = out[key];
|
|
163
|
+
out[key] = isPlainObject(baseValue) && isPlainObject(overlayValue) ? mergeBundle(baseValue, overlayValue) : overlayValue;
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
145
166
|
}
|
|
146
|
-
function createLocaleRegistry() {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
167
|
+
function createLocaleRegistry(options) {
|
|
168
|
+
const primary = options?.primary;
|
|
169
|
+
if (typeof primary !== "string" || primary === "") throw new TypeError(`createLocaleRegistry needs { primary }, the locale whose text is the default in code; received ${JSON.stringify(primary)}.`);
|
|
170
|
+
const registered = [];
|
|
171
|
+
return {
|
|
172
|
+
primary() {
|
|
173
|
+
return primary;
|
|
174
|
+
},
|
|
175
|
+
register(contribution) {
|
|
176
|
+
registered.push(contribution);
|
|
177
|
+
},
|
|
178
|
+
locales() {
|
|
179
|
+
return Array.from(new Set(registered.map((c) => c.locale))).sort();
|
|
180
|
+
},
|
|
181
|
+
namespaces() {
|
|
182
|
+
return Array.from(new Set(registered.map((c) => c.namespace ?? DEFAULT_NAMESPACE))).sort();
|
|
183
|
+
},
|
|
184
|
+
contributions() {
|
|
185
|
+
return registered;
|
|
186
|
+
},
|
|
187
|
+
buildResources() {
|
|
188
|
+
if (!registered.some((c) => c.locale === primary)) {
|
|
189
|
+
const known = Array.from(new Set(registered.map((c) => c.locale))).sort();
|
|
190
|
+
throw new Error(`The locale registry's primary locale ${JSON.stringify(primary)} has no contribution (registered: ${known.length === 0 ? "none" : known.join(", ")}). Register its bundle, an empty one if the app has no strings of its own, or declare the primary it does register.`);
|
|
191
|
+
}
|
|
192
|
+
const byLocale = new Map();
|
|
193
|
+
for (const contribution of registered) {
|
|
194
|
+
const namespace = contribution.namespace ?? DEFAULT_NAMESPACE;
|
|
195
|
+
let byNamespace = byLocale.get(contribution.locale);
|
|
196
|
+
if (!byNamespace) {
|
|
197
|
+
byNamespace = new Map();
|
|
198
|
+
byLocale.set(contribution.locale, byNamespace);
|
|
199
|
+
}
|
|
200
|
+
const group = byNamespace.get(namespace);
|
|
201
|
+
if (group) group.push(contribution);
|
|
202
|
+
else byNamespace.set(namespace, [contribution]);
|
|
203
|
+
}
|
|
204
|
+
const resources = {};
|
|
205
|
+
for (const [locale, byNamespace] of byLocale) {
|
|
206
|
+
const namespaces = {};
|
|
207
|
+
for (const [namespace, group] of byNamespace) {
|
|
208
|
+
const ordered = [...group].sort((a, b) => a.priority - b.priority);
|
|
209
|
+
let merged = {};
|
|
210
|
+
for (const contribution of ordered) merged = mergeBundle(merged, contribution.bundle);
|
|
211
|
+
namespaces[namespace] = merged;
|
|
212
|
+
}
|
|
213
|
+
resources[locale] = namespaces;
|
|
214
|
+
}
|
|
215
|
+
return resources;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
193
218
|
}
|
|
194
|
-
|
|
219
|
+
const DEFAULT_LOCALE_PATTERN = /(?:^|\/)([A-Za-z0-9-]+)\.(?:ts|tsx|js|jsx|mjs|cjs)$/;
|
|
195
220
|
function defaultLocaleOf(path) {
|
|
196
|
-
|
|
221
|
+
return DEFAULT_LOCALE_PATTERN.exec(path)?.[1];
|
|
197
222
|
}
|
|
198
223
|
function localeContributionsFromGlob(glob, options) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
224
|
+
const localeOf = options.localeOf ?? defaultLocaleOf;
|
|
225
|
+
const out = [];
|
|
226
|
+
for (const [path, mod] of Object.entries(glob)) {
|
|
227
|
+
const locale = localeOf(path);
|
|
228
|
+
if (locale === void 0) continue;
|
|
229
|
+
const bundle = isPlainObject(mod.default) ? mod.default : mod;
|
|
230
|
+
out.push({
|
|
231
|
+
locale,
|
|
232
|
+
priority: options.priority,
|
|
233
|
+
source: options.source,
|
|
234
|
+
bundle,
|
|
235
|
+
...options.namespace !== void 0 ? { namespace: options.namespace } : {}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
214
239
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
async function createI18nFromRegistry(registry, config) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/create-i18n-from-registry.ts
|
|
242
|
+
async function createI18nFromRegistry(registry, config = {}) {
|
|
243
|
+
const resources = registry.buildResources();
|
|
244
|
+
const primary = registry.primary();
|
|
245
|
+
return createI18n({
|
|
246
|
+
adapter: await createI18nextAdapter({
|
|
247
|
+
defaultLocale: config.defaultLocale ?? primary,
|
|
248
|
+
locales: registry.locales(),
|
|
249
|
+
resources,
|
|
250
|
+
fallbackLocale: config.fallbackLocale ?? primary,
|
|
251
|
+
...config.keySeparator !== void 0 ? { keySeparator: config.keySeparator } : {},
|
|
252
|
+
...config.nsSeparator !== void 0 ? { nsSeparator: config.nsSeparator } : {}
|
|
253
|
+
}),
|
|
254
|
+
warnOnMissing: config.warnOnMissing,
|
|
255
|
+
locales: () => registry.locales()
|
|
256
|
+
});
|
|
227
257
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/index.ts
|
|
260
|
+
const PACKAGE_NAME = "@burojs/i18n-core";
|
|
261
|
+
const PACKAGE_VERSION = "0.0.0";
|
|
262
|
+
//#endregion
|
|
233
263
|
exports.PACKAGE_NAME = PACKAGE_NAME;
|
|
234
264
|
exports.PACKAGE_VERSION = PACKAGE_VERSION;
|
|
235
265
|
exports.createI18n = createI18n;
|
|
@@ -239,5 +269,5 @@ exports.createLocaleRegistry = createLocaleRegistry;
|
|
|
239
269
|
exports.createResourceI18n = createResourceI18n;
|
|
240
270
|
exports.localeContributionsFromGlob = localeContributionsFromGlob;
|
|
241
271
|
exports.resolveKey = resolveKey;
|
|
242
|
-
|
|
272
|
+
|
|
243
273
|
//# sourceMappingURL=index.cjs.map
|