@adaptive-js/extension-i18n 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -2
- package/dist/index.d.ts +43 -0
- package/dist/index.js +113 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +9 -0
- package/dist/loader.js +182 -0
- package/dist/loader.js.map +1 -0
- package/dist/locale.d.ts +3 -0
- package/dist/locale.js +11 -0
- package/dist/locale.js.map +1 -0
- package/dist/messages.d.ts +11 -0
- package/dist/messages.js +90 -0
- package/dist/messages.js.map +1 -0
- package/package.json +55 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Antonio Johnathan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @adaptive-js/extension-i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reactive internationalization for AdaptiveJS: locale signals, nested message keys, fallback locales, interpolation, and a server-side loader.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @adaptive-js/extension-i18n
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { createI18n, defineMessages } from "@adaptive-js/extension-i18n";
|
|
15
|
+
|
|
16
|
+
const messages = defineMessages({
|
|
17
|
+
en: { greeting: "Hello, {name}!" },
|
|
18
|
+
"pt-BR": { greeting: "Olá, {name}!" },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const { I18nProvider, useI18n } = createI18n({
|
|
22
|
+
locale: "en",
|
|
23
|
+
fallbackLocale: "en",
|
|
24
|
+
messages,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function Greeting() {
|
|
28
|
+
const { t, setLocale } = useI18n();
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<p onClick={() => setLocale("pt-BR")}>
|
|
32
|
+
{t("greeting", { name: "Ada" })}
|
|
33
|
+
</p>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Server-side loader
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { loadProjectLanguages, resolveLanguageDirectory } from "@adaptive-js/extension-i18n/loader";
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`loadProjectLanguages` reads JSON message files from the app's `language` directory (configurable) so the server can render the right locale before hydration.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type AdaptiveNode, type MaybeSignal } from "@adaptive-js/web";
|
|
2
|
+
import { type I18nMessages, type I18nParams } from "./messages.js";
|
|
3
|
+
export { DEFAULT_I18N_LANGUAGE, canonicalizeLocale, normalizeLocale } from "./locale.js";
|
|
4
|
+
export type { I18nMessageTree, I18nMessageValue, I18nMessages, I18nParams, I18nPrimitive, } from "./messages.js";
|
|
5
|
+
export type I18nConfig<TLocale extends string = string> = {
|
|
6
|
+
locale?: TLocale;
|
|
7
|
+
fallbackLocale?: TLocale;
|
|
8
|
+
messages: I18nMessages<TLocale>;
|
|
9
|
+
};
|
|
10
|
+
export type I18nProviderProps<TLocale extends string = string> = {
|
|
11
|
+
locale?: MaybeSignal<TLocale>;
|
|
12
|
+
fallbackLocale?: MaybeSignal<TLocale>;
|
|
13
|
+
messages?: MaybeSignal<I18nMessages<TLocale>>;
|
|
14
|
+
children?: AdaptiveNode;
|
|
15
|
+
};
|
|
16
|
+
export type I18nApi<TLocale extends string = string> = {
|
|
17
|
+
locale: () => TLocale;
|
|
18
|
+
fallbackLocale: () => TLocale;
|
|
19
|
+
setLocale: (next: TLocale | ((prev: TLocale) => TLocale)) => void;
|
|
20
|
+
t: (key: string, params?: I18nParams) => string;
|
|
21
|
+
has: (key: string, locale?: TLocale) => boolean;
|
|
22
|
+
messages: () => I18nMessages<TLocale>;
|
|
23
|
+
};
|
|
24
|
+
export type HtmlLanguageOptions = {
|
|
25
|
+
defaultValue?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function getHtmlLanguage(options?: HtmlLanguageOptions): string;
|
|
28
|
+
export declare function setHtmlLanguage(locale: string): void;
|
|
29
|
+
export declare function syncHtmlLanguage(locale: string): string;
|
|
30
|
+
export declare function getBrowserLanguage(options?: HtmlLanguageOptions): string;
|
|
31
|
+
export declare function useHtmlLanguage(locale: MaybeSignal<string>): void;
|
|
32
|
+
export declare function createI18n<TLocale extends string>(config: I18nConfig<TLocale>): {
|
|
33
|
+
I18nProvider: (props: I18nProviderProps<TLocale>) => {
|
|
34
|
+
tag: symbol;
|
|
35
|
+
props: {
|
|
36
|
+
context: import("@adaptive-js/web").AdaptiveContext<I18nApi<TLocale> | null>;
|
|
37
|
+
value: I18nApi<TLocale> | null;
|
|
38
|
+
};
|
|
39
|
+
children: any;
|
|
40
|
+
};
|
|
41
|
+
useI18n: () => I18nApi<TLocale>;
|
|
42
|
+
};
|
|
43
|
+
export declare function defineMessages<TLocale extends string>(messages: I18nMessages<TLocale>): I18nMessages<TLocale>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createContext, events, signal, useContext, } from "@adaptive-js/web";
|
|
2
|
+
import { DEFAULT_I18N_LANGUAGE, normalizeLocale, } from "./locale.js";
|
|
3
|
+
import { hasMessage, normalizeMessages, resolveMessage, } from "./messages.js";
|
|
4
|
+
export { DEFAULT_I18N_LANGUAGE, canonicalizeLocale, normalizeLocale } from "./locale.js";
|
|
5
|
+
function readMaybeSignal(value) {
|
|
6
|
+
return typeof value === "function" ? value() : value;
|
|
7
|
+
}
|
|
8
|
+
function requireLocale(messages, value, label) {
|
|
9
|
+
const locale = normalizeLocale(value);
|
|
10
|
+
if (!Object.hasOwn(messages, locale)) {
|
|
11
|
+
throw new Error(`[AdaptiveJS i18n] ${label} "${locale}" is not present in messages.`);
|
|
12
|
+
}
|
|
13
|
+
return locale;
|
|
14
|
+
}
|
|
15
|
+
export function getHtmlLanguage(options = {}) {
|
|
16
|
+
const defaultValue = options.defaultValue ?? DEFAULT_I18N_LANGUAGE;
|
|
17
|
+
if (typeof document === "undefined")
|
|
18
|
+
return defaultValue;
|
|
19
|
+
return document.documentElement.lang || defaultValue;
|
|
20
|
+
}
|
|
21
|
+
export function setHtmlLanguage(locale) {
|
|
22
|
+
if (typeof document === "undefined")
|
|
23
|
+
return;
|
|
24
|
+
document.documentElement.lang = normalizeLocale(locale);
|
|
25
|
+
}
|
|
26
|
+
export function syncHtmlLanguage(locale) {
|
|
27
|
+
const normalized = normalizeLocale(locale);
|
|
28
|
+
setHtmlLanguage(normalized);
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
export function getBrowserLanguage(options = {}) {
|
|
32
|
+
const defaultValue = options.defaultValue ?? DEFAULT_I18N_LANGUAGE;
|
|
33
|
+
if (typeof navigator === "undefined")
|
|
34
|
+
return defaultValue;
|
|
35
|
+
return normalizeLocale(navigator.language, defaultValue);
|
|
36
|
+
}
|
|
37
|
+
export function useHtmlLanguage(locale) {
|
|
38
|
+
events(() => {
|
|
39
|
+
setHtmlLanguage(readMaybeSignal(locale));
|
|
40
|
+
}, [locale]);
|
|
41
|
+
}
|
|
42
|
+
export function createI18n(config) {
|
|
43
|
+
const I18nContext = createContext(null);
|
|
44
|
+
const configMessages = normalizeMessages(config.messages);
|
|
45
|
+
const availableLocales = Object.keys(configMessages);
|
|
46
|
+
const defaultLocale = config.locale !== undefined
|
|
47
|
+
? requireLocale(configMessages, config.locale, "Configured locale")
|
|
48
|
+
: (availableLocales.includes(DEFAULT_I18N_LANGUAGE)
|
|
49
|
+
? DEFAULT_I18N_LANGUAGE
|
|
50
|
+
: availableLocales[0]);
|
|
51
|
+
const defaultFallbackLocale = config.fallbackLocale !== undefined
|
|
52
|
+
? requireLocale(configMessages, config.fallbackLocale, "Configured fallbackLocale")
|
|
53
|
+
: defaultLocale;
|
|
54
|
+
function I18nProvider(props) {
|
|
55
|
+
const initialMessages = normalizeMessages(readMaybeSignal(props.messages) ?? configMessages);
|
|
56
|
+
const initialLocale = props.locale !== undefined
|
|
57
|
+
? requireLocale(initialMessages, readMaybeSignal(props.locale), "Provider locale")
|
|
58
|
+
: defaultLocale;
|
|
59
|
+
const initialFallbackLocale = props.fallbackLocale !== undefined
|
|
60
|
+
? requireLocale(initialMessages, readMaybeSignal(props.fallbackLocale), "Provider fallbackLocale")
|
|
61
|
+
: defaultFallbackLocale;
|
|
62
|
+
const [locale, setLocale] = signal(initialLocale);
|
|
63
|
+
const [fallbackLocale, setFallbackLocale] = signal(initialFallbackLocale);
|
|
64
|
+
const [messages, setMessages] = signal(initialMessages);
|
|
65
|
+
events(() => {
|
|
66
|
+
const nextMessages = normalizeMessages(readMaybeSignal(props.messages) ?? configMessages);
|
|
67
|
+
const nextFallbackLocale = props.fallbackLocale !== undefined
|
|
68
|
+
? requireLocale(nextMessages, readMaybeSignal(props.fallbackLocale), "Provider fallbackLocale")
|
|
69
|
+
: defaultFallbackLocale;
|
|
70
|
+
setMessages(nextMessages);
|
|
71
|
+
setFallbackLocale(nextFallbackLocale);
|
|
72
|
+
if (props.locale !== undefined) {
|
|
73
|
+
setLocale(requireLocale(nextMessages, readMaybeSignal(props.locale), "Provider locale"));
|
|
74
|
+
}
|
|
75
|
+
}, [props.locale, props.fallbackLocale, props.messages]);
|
|
76
|
+
useHtmlLanguage(locale);
|
|
77
|
+
const api = {
|
|
78
|
+
locale,
|
|
79
|
+
fallbackLocale,
|
|
80
|
+
setLocale: (next) => {
|
|
81
|
+
if (typeof next === "function") {
|
|
82
|
+
setLocale((previous) => requireLocale(messages(), next(previous), "Locale"));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setLocale(requireLocale(messages(), next, "Locale"));
|
|
86
|
+
},
|
|
87
|
+
t: (key, params) => resolveMessage(messages(), locale(), fallbackLocale(), key, params),
|
|
88
|
+
has: (key, overrideLocale) => {
|
|
89
|
+
const requestedLocale = overrideLocale === undefined
|
|
90
|
+
? locale()
|
|
91
|
+
: normalizeLocale(overrideLocale);
|
|
92
|
+
return hasMessage(messages(), requestedLocale, fallbackLocale(), key);
|
|
93
|
+
},
|
|
94
|
+
messages: () => messages(),
|
|
95
|
+
};
|
|
96
|
+
return I18nContext.Provider({
|
|
97
|
+
value: api,
|
|
98
|
+
children: props.children,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function useI18n() {
|
|
102
|
+
const api = useContext(I18nContext);
|
|
103
|
+
if (!api) {
|
|
104
|
+
throw new Error("useI18n must be used inside an I18nProvider in the same boundary.");
|
|
105
|
+
}
|
|
106
|
+
return api;
|
|
107
|
+
}
|
|
108
|
+
return { I18nProvider, useI18n };
|
|
109
|
+
}
|
|
110
|
+
export function defineMessages(messages) {
|
|
111
|
+
return messages;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,MAAM,EACN,MAAM,EACN,UAAU,GAGX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,cAAc,GAGf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmCzF,SAAS,eAAe,CAAI,KAAqB;IAC/C,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAiB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACpE,CAAC;AAED,SAAS,aAAa,CACpB,QAA+B,EAC/B,KAAc,EACd,KAAa;IAEb,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAY,CAAC;IACjD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,KAAK,MAAM,+BAA+B,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,UAA+B,EAAE;IAC/D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,qBAAqB,CAAC;IACnE,IAAI,O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K,SAAS;oBAClD,CAAC,CAAC,MAAM,EAAE;oBACV,CAAC,CAAC,eAAe,CAAC,cAAc,CAAY,CAAC;gBAC/C,OAAO,UAAU,CAAC,QAAQ,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE,EAAE,GAAG,CAAC,CAAC;YACxE,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE;SAC3B,CAAC;QAEF,OAAO,WAAW,CAAC,QAAQ,CAAC;YAC1B,KAAK,EAAE,GAAG;YACV,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,OAAO;QACd,MAAM,GAAG,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;QACpC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,cAAc,CAAyB,QAA+B;IACpF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type I18nMessageTree, type I18nMessages } from "./messages.js";
|
|
2
|
+
export type LoadProjectLanguagesOptions<TLocale extends string = string> = {
|
|
3
|
+
rootDir?: string;
|
|
4
|
+
folderName?: string;
|
|
5
|
+
extensions?: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function resolveLanguageDirectory(rootDir?: string, folderName?: string): string;
|
|
8
|
+
export declare function loadLanguage<TLocale extends string = string>(locale: TLocale, options?: LoadProjectLanguagesOptions<TLocale>): I18nMessageTree;
|
|
9
|
+
export declare function loadProjectLanguages<TLocale extends string = string>(options?: LoadProjectLanguagesOptions<TLocale>): I18nMessages<TLocale>;
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { canonicalizeLocale, normalizeLocale } from "./locale.js";
|
|
4
|
+
import { normalizeMessageTree, } from "./messages.js";
|
|
5
|
+
const unsafeKeys = new Set(["__proto__", "prototype", "constructor"]);
|
|
6
|
+
function isPlainObject(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function assertSafeSegment(segment, path) {
|
|
10
|
+
if (!segment || segment === "." || segment === ".." || unsafeKeys.has(segment)) {
|
|
11
|
+
throw new Error(`[AdaptiveJS i18n] Unsafe message path segment "${segment}" at "${path}".`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function resolveLanguageDirectory(rootDir = process.cwd(), folderName = "language") {
|
|
15
|
+
const root = resolve(rootDir);
|
|
16
|
+
const directory = resolve(root, folderName);
|
|
17
|
+
const pathFromRoot = relative(root, directory);
|
|
18
|
+
if (pathFromRoot === ".." || pathFromRoot.startsWith(`..${sep}`) || isAbsolute(pathFromRoot)) {
|
|
19
|
+
throw new Error(`[AdaptiveJS i18n] Language folder "${folderName}" must stay inside "${root}".`);
|
|
20
|
+
}
|
|
21
|
+
return directory;
|
|
22
|
+
}
|
|
23
|
+
function resolveExtensions(extensions) {
|
|
24
|
+
const resolved = extensions ?? [".json"];
|
|
25
|
+
for (const extension of resolved) {
|
|
26
|
+
if (!/^\.[a-z0-9]+$/i.test(extension)) {
|
|
27
|
+
throw new Error(`[AdaptiveJS i18n] Invalid language file extension "${extension}".`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
32
|
+
function readMessageFile(filePath) {
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(readFileSync(filePath, "utf8"));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new Error(`[AdaptiveJS i18n] Could not read messages from "${filePath}".`, {
|
|
39
|
+
cause: error,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return normalizeMessageTree(parsed, filePath);
|
|
43
|
+
}
|
|
44
|
+
function collectJsonFiles(directory, extensions, files = []) {
|
|
45
|
+
const entries = readdirSync(directory, { withFileTypes: true })
|
|
46
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const filePath = join(directory, entry.name);
|
|
49
|
+
if (entry.isDirectory()) {
|
|
50
|
+
collectJsonFiles(filePath, extensions, files);
|
|
51
|
+
}
|
|
52
|
+
else if (entry.isFile() && extensions.includes(extname(entry.name))) {
|
|
53
|
+
files.push(filePath);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return files;
|
|
57
|
+
}
|
|
58
|
+
function mergeTrees(target, source, path) {
|
|
59
|
+
const output = Object.create(null);
|
|
60
|
+
for (const [key, value] of Object.entries(target))
|
|
61
|
+
output[key] = value;
|
|
62
|
+
for (const [key, value] of Object.entries(source)) {
|
|
63
|
+
if (!Object.hasOwn(output, key)) {
|
|
64
|
+
output[key] = value;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const existing = output[key];
|
|
68
|
+
if (isPlainObject(existing) && isPlainObject(value)) {
|
|
69
|
+
output[key] = mergeTrees(existing, value, `${path}.${key}`);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`[AdaptiveJS i18n] Conflicting message path "${path}.${key}".`);
|
|
73
|
+
}
|
|
74
|
+
return output;
|
|
75
|
+
}
|
|
76
|
+
function assignNestedTree(target, pathSegments, value, path) {
|
|
77
|
+
if (pathSegments.length === 0)
|
|
78
|
+
return mergeTrees(target, value, path);
|
|
79
|
+
const [head, ...tail] = pathSegments;
|
|
80
|
+
assertSafeSegment(head, path);
|
|
81
|
+
const current = Object.hasOwn(target, head) ? target[head] : undefined;
|
|
82
|
+
if (current !== undefined && !isPlainObject(current)) {
|
|
83
|
+
throw new Error(`[AdaptiveJS i18n] Conflicting message path "${path}.${head}".`);
|
|
84
|
+
}
|
|
85
|
+
const base = (current ?? Object.create(null));
|
|
86
|
+
target[head] = assignNestedTree(base, tail, value, `${path}.${head}`);
|
|
87
|
+
return target;
|
|
88
|
+
}
|
|
89
|
+
function loadLocaleDirectory(localeDir, extensions) {
|
|
90
|
+
const files = collectJsonFiles(localeDir, extensions);
|
|
91
|
+
if (files.length === 0) {
|
|
92
|
+
throw new Error(`[AdaptiveJS i18n] The locale folder "${localeDir}" does not contain supported language files.`);
|
|
93
|
+
}
|
|
94
|
+
let localeTree = Object.create(null);
|
|
95
|
+
for (const filePath of files) {
|
|
96
|
+
const parsed = readMessageFile(filePath);
|
|
97
|
+
const normalized = relative(localeDir, filePath).split(sep).join("/");
|
|
98
|
+
const withoutExtension = normalized.replace(/\.[^.]+$/, "");
|
|
99
|
+
const pathSegments = withoutExtension === "index"
|
|
100
|
+
? []
|
|
101
|
+
: withoutExtension.split("/").map((segment) => segment.trim()).filter(Boolean);
|
|
102
|
+
localeTree = assignNestedTree(localeTree, pathSegments, parsed, withoutExtension);
|
|
103
|
+
}
|
|
104
|
+
return localeTree;
|
|
105
|
+
}
|
|
106
|
+
function findLocaleSource(languageDir, locale, extensions) {
|
|
107
|
+
const entries = readdirSync(languageDir, { withFileTypes: true })
|
|
108
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
109
|
+
const matches = [];
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
const name = canonicalizeLocale(entry.name);
|
|
113
|
+
if (name === locale)
|
|
114
|
+
matches.push({ directory: join(languageDir, entry.name) });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (entry.isFile() && extensions.includes(extname(entry.name))) {
|
|
118
|
+
const name = canonicalizeLocale(entry.name.slice(0, -extname(entry.name).length));
|
|
119
|
+
if (name === locale)
|
|
120
|
+
matches.push({ file: join(languageDir, entry.name) });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (matches.length > 1) {
|
|
124
|
+
throw new Error(`[AdaptiveJS i18n] Locale "${locale}" has multiple matching folders or files.`);
|
|
125
|
+
}
|
|
126
|
+
return matches[0] ?? null;
|
|
127
|
+
}
|
|
128
|
+
export function loadLanguage(locale, options = {}) {
|
|
129
|
+
const normalizedLocale = normalizeLocale(locale, "");
|
|
130
|
+
if (!normalizedLocale) {
|
|
131
|
+
throw new Error(`[AdaptiveJS i18n] Invalid locale "${locale}".`);
|
|
132
|
+
}
|
|
133
|
+
const languageDir = resolveLanguageDirectory(options.rootDir ?? process.cwd(), options.folderName ?? "language");
|
|
134
|
+
if (!existsSync(languageDir)) {
|
|
135
|
+
throw new Error(`[AdaptiveJS i18n] No language folder was found at "${languageDir}".`);
|
|
136
|
+
}
|
|
137
|
+
const source = findLocaleSource(languageDir, normalizedLocale, resolveExtensions(options.extensions));
|
|
138
|
+
if (!source) {
|
|
139
|
+
throw new Error(`[AdaptiveJS i18n] Locale "${normalizedLocale}" was not found in "${languageDir}".`);
|
|
140
|
+
}
|
|
141
|
+
return "directory" in source
|
|
142
|
+
? loadLocaleDirectory(source.directory, resolveExtensions(options.extensions))
|
|
143
|
+
: readMessageFile(source.file);
|
|
144
|
+
}
|
|
145
|
+
export function loadProjectLanguages(options = {}) {
|
|
146
|
+
const languageDir = resolveLanguageDirectory(options.rootDir ?? process.cwd(), options.folderName ?? "language");
|
|
147
|
+
if (!existsSync(languageDir)) {
|
|
148
|
+
throw new Error(`[AdaptiveJS i18n] No language folder was found at "${languageDir}".`);
|
|
149
|
+
}
|
|
150
|
+
const extensions = resolveExtensions(options.extensions);
|
|
151
|
+
const messages = Object.create(null);
|
|
152
|
+
const entries = readdirSync(languageDir, { withFileTypes: true })
|
|
153
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
if (entry.isDirectory()) {
|
|
156
|
+
const locale = canonicalizeLocale(entry.name);
|
|
157
|
+
if (!locale) {
|
|
158
|
+
throw new Error(`[AdaptiveJS i18n] Invalid locale folder "${entry.name}".`);
|
|
159
|
+
}
|
|
160
|
+
if (Object.hasOwn(messages, locale)) {
|
|
161
|
+
throw new Error(`[AdaptiveJS i18n] Duplicate locale "${locale}" after normalization.`);
|
|
162
|
+
}
|
|
163
|
+
messages[locale] = loadLocaleDirectory(join(languageDir, entry.name), extensions);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (!entry.isFile() || !extensions.includes(extname(entry.name)))
|
|
167
|
+
continue;
|
|
168
|
+
const locale = canonicalizeLocale(entry.name.slice(0, -extname(entry.name).length));
|
|
169
|
+
if (!locale) {
|
|
170
|
+
throw new Error(`[AdaptiveJS i18n] Invalid locale file "${entry.name}".`);
|
|
171
|
+
}
|
|
172
|
+
if (Object.hasOwn(messages, locale)) {
|
|
173
|
+
throw new Error(`[AdaptiveJS i18n] Duplicate locale "${locale}" after normalization.`);
|
|
174
|
+
}
|
|
175
|
+
messages[locale] = readMessageFile(join(languageDir, entry.name));
|
|
176
|
+
}
|
|
177
|
+
if (Object.keys(messages).length === 0) {
|
|
178
|
+
throw new Error(`[AdaptiveJS i18n] No locales were found in "${languageDir}".`);
|
|
179
|
+
}
|
|
180
|
+
return messages;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,O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
|
|
2
|
+
export function canonicalizeLocale(locale) {
|
|
3
|
+
if (typeof locale !== "string")
|
|
4
|
+
return null;
|
|
5
|
+
const normalized = locale.trim().replace(/_/g, "-").toLowerCase();
|
|
6
|
+
return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(normalized) ? normalized : null;
|
|
7
|
+
}
|
|
8
|
+
export function normalizeLocale(locale, fallback = DEFAULT_I18N_LANGUAGE) {
|
|
9
|
+
return canonicalizeLocale(locale) ?? fallback;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C,MAAM,UAAU,kBAAkB,CAAC,MAAiC;IAClE,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE5C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAClE,OAAO,4BAA4B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,MAAiC,EACjC,QAAQ,GAAG,qBAAqB;IAEhC,OAAO,kBAAkB,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type I18nPrimitive = string | number | boolean | null | undefined;
|
|
2
|
+
export type I18nParams = Record<string, I18nPrimitive>;
|
|
3
|
+
export type I18nMessageValue = string | I18nMessageTree;
|
|
4
|
+
export type I18nMessageTree = {
|
|
5
|
+
[key: string]: I18nMessageValue;
|
|
6
|
+
};
|
|
7
|
+
export type I18nMessages<TLocale extends string = string> = Record<TLocale, I18nMessageTree>;
|
|
8
|
+
export declare function normalizeMessageTree(value: unknown, path?: string): I18nMessageTree;
|
|
9
|
+
export declare function normalizeMessages<TLocale extends string>(messages: I18nMessages<TLocale>): I18nMessages<TLocale>;
|
|
10
|
+
export declare function resolveMessage<TLocale extends string>(messages: I18nMessages<TLocale>, locale: TLocale, fallbackLocale: TLocale, key: string, params?: I18nParams): string;
|
|
11
|
+
export declare function hasMessage<TLocale extends string>(messages: I18nMessages<TLocale>, locale: TLocale, fallbackLocale: TLocale, key: string): boolean;
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { canonicalizeLocale } from "./locale.js";
|
|
2
|
+
const unsafeKeys = new Set(["__proto__", "prototype", "constructor"]);
|
|
3
|
+
const normalizedMessages = new WeakMap();
|
|
4
|
+
function isPlainObject(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function assertSafeKey(key, path) {
|
|
8
|
+
if (unsafeKeys.has(key)) {
|
|
9
|
+
throw new Error(`[AdaptiveJS i18n] Unsafe message key "${key}" at "${path}".`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function normalizeMessageTree(value, path = "messages") {
|
|
13
|
+
if (!isPlainObject(value)) {
|
|
14
|
+
throw new Error(`[AdaptiveJS i18n] "${path}" must be an object of messages.`);
|
|
15
|
+
}
|
|
16
|
+
const output = Object.create(null);
|
|
17
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
18
|
+
assertSafeKey(key, path);
|
|
19
|
+
if (typeof entry === "string") {
|
|
20
|
+
output[key] = entry;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (isPlainObject(entry)) {
|
|
24
|
+
output[key] = normalizeMessageTree(entry, `${path}.${key}`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`[AdaptiveJS i18n] "${path}.${key}" must be a string or a nested message object. Functions are not serializable across hydration boundaries.`);
|
|
28
|
+
}
|
|
29
|
+
return output;
|
|
30
|
+
}
|
|
31
|
+
export function normalizeMessages(messages) {
|
|
32
|
+
if (!isPlainObject(messages)) {
|
|
33
|
+
throw new Error("[AdaptiveJS i18n] messages must be an object keyed by locale.");
|
|
34
|
+
}
|
|
35
|
+
const cached = normalizedMessages.get(messages);
|
|
36
|
+
if (cached)
|
|
37
|
+
return cached;
|
|
38
|
+
const output = Object.create(null);
|
|
39
|
+
for (const [key, tree] of Object.entries(messages)) {
|
|
40
|
+
const locale = canonicalizeLocale(key);
|
|
41
|
+
if (!locale) {
|
|
42
|
+
throw new Error(`[AdaptiveJS i18n] Invalid locale key "${key}".`);
|
|
43
|
+
}
|
|
44
|
+
if (Object.hasOwn(output, locale)) {
|
|
45
|
+
throw new Error(`[AdaptiveJS i18n] Duplicate locale "${locale}" after normalization.`);
|
|
46
|
+
}
|
|
47
|
+
output[locale] = normalizeMessageTree(tree, `messages.${key}`);
|
|
48
|
+
}
|
|
49
|
+
if (Object.keys(output).length === 0) {
|
|
50
|
+
throw new Error("[AdaptiveJS i18n] At least one locale is required.");
|
|
51
|
+
}
|
|
52
|
+
normalizedMessages.set(messages, output);
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
function resolvePathValue(tree, key) {
|
|
56
|
+
if (!tree)
|
|
57
|
+
return undefined;
|
|
58
|
+
if (Object.hasOwn(tree, key))
|
|
59
|
+
return tree[key];
|
|
60
|
+
let current = tree;
|
|
61
|
+
for (const segment of key.split(".")) {
|
|
62
|
+
if (!current || typeof current === "string")
|
|
63
|
+
return undefined;
|
|
64
|
+
if (!Object.hasOwn(current, segment))
|
|
65
|
+
return undefined;
|
|
66
|
+
current = current[segment];
|
|
67
|
+
}
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
function interpolateMessage(template, params) {
|
|
71
|
+
if (!params)
|
|
72
|
+
return template;
|
|
73
|
+
return template.replace(/\{([^}]+)\}/g, (_, token) => {
|
|
74
|
+
const key = token.trim();
|
|
75
|
+
if (!Object.hasOwn(params, key))
|
|
76
|
+
return "";
|
|
77
|
+
const value = params[key];
|
|
78
|
+
return value == null ? "" : String(value);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export function resolveMessage(messages, locale, fallbackLocale, key, params) {
|
|
82
|
+
const message = resolvePathValue(messages[locale], key)
|
|
83
|
+
?? resolvePathValue(messages[fallbackLocale], key);
|
|
84
|
+
return typeof message === "string" ? interpolateMessage(message, params) : key;
|
|
85
|
+
}
|
|
86
|
+
export function hasMessage(messages, locale, fallbackLocale, key) {
|
|
87
|
+
return resolvePathValue(messages[locale], key) !== undefined
|
|
88
|
+
|| resolvePathValue(messages[fallbackLocale], key) !== undefined;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAUjD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;AACtE,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAA6B,CAAC;AAEpE,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,aAAa,CAAC,GAAW,EAAE,IAAY;IAC9C,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,yCAAyC,GAAG,SAAS,IAAI,IAAI,CAAC,CAAC;IACjF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc,EAAE,IAAI,GAAG,UAAU;IACpE,I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|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Reactive internationalization utilities for AdaptiveJS applications.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"adaptive-js",
|
|
7
|
+
"i18n",
|
|
8
|
+
"internationalization",
|
|
9
|
+
"locale"
|
|
10
|
+
],
|
|
11
|
+
"author": "Antonio Johnathan",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/SrJohnathan/adaptive-js.git",
|
|
16
|
+
"directory": "extension/i18n"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/SrJohnathan/adaptive-js/tree/main/extension/i18n#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/SrJohnathan/adaptive-js/issues"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./loader": {
|
|
31
|
+
"types": "./dist/loader.d.ts",
|
|
32
|
+
"import": "./dist/loader.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
40
|
+
"test": "npm run build && tsc -p tsconfig.test.json && node --test dist-test/*.test.js",
|
|
41
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
42
|
+
"prepublishOnly": "npm run build"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20.0.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@adaptive-js/web": "0.0.2"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^25.6.0",
|
|
55
|
+
"typescript": "^6.0.3"
|
|
56
|
+
}
|
|
57
|
+
}
|