intor 1.0.39 → 2.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/dist/config/index.cjs +44 -79
- package/dist/config/index.d.cts +69 -36
- package/dist/config/index.d.ts +69 -36
- package/dist/config/index.js +42 -80
- package/dist/index.cjs +482 -540
- package/dist/index.d.cts +163 -139
- package/dist/index.d.ts +163 -139
- package/dist/index.js +475 -537
- package/dist/next/index.cjs +399 -359
- package/dist/next/index.d.cts +82 -113
- package/dist/next/index.d.ts +82 -113
- package/dist/next/index.js +396 -351
- package/dist/next/middleware/index.cjs +79 -93
- package/dist/next/middleware/index.d.cts +59 -28
- package/dist/next/middleware/index.d.ts +59 -28
- package/dist/next/middleware/index.js +79 -93
- package/dist/next/server/index.cjs +886 -0
- package/dist/next/server/index.d.cts +149 -0
- package/dist/next/server/index.d.ts +149 -0
- package/dist/next/server/index.js +875 -0
- package/package.json +9 -12
- package/exports/next/provider/intor-provider.tsx +0 -25
- package/exports/next/provider/translate-handlers-provider.tsx +0 -19
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
|
|
2
|
+
import { Locale, LocaleNamespaceMessages, FallbackLocalesMap, TranslateConfig, Translator } from 'intor-translator';
|
|
3
|
+
|
|
4
|
+
type CookieRawOptions = {
|
|
5
|
+
/** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
/** Allow the system to automatically set cookies - default: true */
|
|
8
|
+
autoSetCookie?: boolean;
|
|
9
|
+
/** default: "intor.i18n.locale" */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** default: null */
|
|
12
|
+
domain?: string | null;
|
|
13
|
+
/** default: "/" */
|
|
14
|
+
path?: string;
|
|
15
|
+
/** default: 60 * 60 * 24 * 365 (365 days) */
|
|
16
|
+
maxAge?: number;
|
|
17
|
+
/** default: false */
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
/** default: process.env.NODE_ENV !== "development" */
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
/** default: lax */
|
|
22
|
+
sameSite?: "lax" | "strict" | "none";
|
|
23
|
+
};
|
|
24
|
+
type CookieResolvedOptions = Required<Omit<CookieRawOptions, "domain">> & {
|
|
25
|
+
domain: string | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ```ts
|
|
30
|
+
* {
|
|
31
|
+
* default: ["ui", "meta"],
|
|
32
|
+
* "/auth": ["auth", "admin"],
|
|
33
|
+
* }
|
|
34
|
+
* // When pathname is "/" => namespaces: ["ui", "meta"]
|
|
35
|
+
* // When pathname is "/auth" => namespaces: ["ui", "meta", "auth", "admin"]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type RouteNamespaces = {
|
|
39
|
+
[key: string]: string[];
|
|
40
|
+
} | {
|
|
41
|
+
[key: string]: string[];
|
|
42
|
+
default: string[];
|
|
43
|
+
};
|
|
44
|
+
interface ApiHeaders {
|
|
45
|
+
authorization?: string;
|
|
46
|
+
"x-api-key"?: string;
|
|
47
|
+
[key: string]: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
type BaseLoaderOptions = {
|
|
50
|
+
basePath?: string;
|
|
51
|
+
namespaces?: string[];
|
|
52
|
+
routeNamespaces?: RouteNamespaces;
|
|
53
|
+
concurrency?: number;
|
|
54
|
+
lazyLoad?: boolean;
|
|
55
|
+
};
|
|
56
|
+
type ImportLoader = BaseLoaderOptions & {
|
|
57
|
+
type: "import";
|
|
58
|
+
};
|
|
59
|
+
type ApiLoader = BaseLoaderOptions & {
|
|
60
|
+
type: "api";
|
|
61
|
+
apiUrl: string;
|
|
62
|
+
apiHeaders?: ApiHeaders;
|
|
63
|
+
fullReload?: boolean;
|
|
64
|
+
};
|
|
65
|
+
type LoaderOptions = ImportLoader | ApiLoader;
|
|
66
|
+
|
|
67
|
+
type LoggerOptions = {
|
|
68
|
+
level?: Level;
|
|
69
|
+
normalizerConfig?: NormalizerConfig;
|
|
70
|
+
formatterConfig?: FormatterConfig;
|
|
71
|
+
preset?: LoggerPreset;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
declare const routingPrefix: readonly ["none", "all", "except-default"];
|
|
75
|
+
declare const routingFirstVisitLocaleSource: readonly ["default", "browser"];
|
|
76
|
+
type RoutingRawOptions = {
|
|
77
|
+
/** default: "none" */
|
|
78
|
+
prefix?: (typeof routingPrefix)[number];
|
|
79
|
+
firstVisit?: {
|
|
80
|
+
/** default: "browser" */
|
|
81
|
+
localeSource?: (typeof routingFirstVisitLocaleSource)[number];
|
|
82
|
+
/** default: true */
|
|
83
|
+
redirect?: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** default: "" */
|
|
86
|
+
basePath?: string;
|
|
87
|
+
};
|
|
88
|
+
type RoutingResolvedOptions = Required<RoutingRawOptions>;
|
|
89
|
+
|
|
90
|
+
type CacheRawOptions = {
|
|
91
|
+
enabled?: boolean;
|
|
92
|
+
/** default: 60\*60\*1000 (1 hour) */
|
|
93
|
+
ttl?: number;
|
|
94
|
+
};
|
|
95
|
+
type CacheResolvedOptions = Required<CacheRawOptions>;
|
|
96
|
+
|
|
97
|
+
type TranslatorOptions = {
|
|
98
|
+
loadingMessage?: string;
|
|
99
|
+
placeholder?: string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type WithoutLoader = {
|
|
103
|
+
loader?: undefined;
|
|
104
|
+
supportedLocales?: readonly Locale[];
|
|
105
|
+
};
|
|
106
|
+
type WithLoader = {
|
|
107
|
+
loader: LoaderOptions;
|
|
108
|
+
supportedLocales: readonly Locale[];
|
|
109
|
+
};
|
|
110
|
+
type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
|
|
111
|
+
readonly id: string;
|
|
112
|
+
readonly messages?: LocaleNamespaceMessages;
|
|
113
|
+
readonly defaultLocale: Locale;
|
|
114
|
+
readonly fallbackLocales: FallbackLocalesMap;
|
|
115
|
+
readonly translator?: TranslatorOptions;
|
|
116
|
+
readonly cookie: CookieResolvedOptions;
|
|
117
|
+
readonly routing: RoutingResolvedOptions;
|
|
118
|
+
readonly logger?: LoggerOptions;
|
|
119
|
+
readonly cache: CacheResolvedOptions;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
interface AdapterRuntime {
|
|
123
|
+
locale: Locale;
|
|
124
|
+
pathname: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Prepares runtime data for Next.js.
|
|
129
|
+
*/
|
|
130
|
+
declare const nextAdapter: (config: IntorResolvedConfig) => Promise<AdapterRuntime>;
|
|
131
|
+
|
|
132
|
+
type MessagesLoaderResult = Promise<LocaleNamespaceMessages | undefined>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Retrieves messages in a Next.js SSR environment.
|
|
136
|
+
* This function wraps the standard `getMessages` with the Next.js adapter,
|
|
137
|
+
* automatically resolving runtime data.
|
|
138
|
+
*/
|
|
139
|
+
declare const getMessages: (config: IntorResolvedConfig) => Promise<MessagesLoaderResult>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a ready-to-use translation function (`t`) for the current
|
|
143
|
+
* Next.js SSR runtime environment. It automatically resolves the
|
|
144
|
+
* locale and pathname using the Next.js adapter, loads all
|
|
145
|
+
* corresponding messages, and returns a `t` function bound to them.
|
|
146
|
+
*/
|
|
147
|
+
declare const getTranslation: (config: IntorResolvedConfig, preKey?: string, options?: TranslateConfig<unknown>) => Promise<Translator["t"]>;
|
|
148
|
+
|
|
149
|
+
export { getMessages, getTranslation, nextAdapter };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
|
|
2
|
+
import { Locale, LocaleNamespaceMessages, FallbackLocalesMap, TranslateConfig, Translator } from 'intor-translator';
|
|
3
|
+
|
|
4
|
+
type CookieRawOptions = {
|
|
5
|
+
/** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
/** Allow the system to automatically set cookies - default: true */
|
|
8
|
+
autoSetCookie?: boolean;
|
|
9
|
+
/** default: "intor.i18n.locale" */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** default: null */
|
|
12
|
+
domain?: string | null;
|
|
13
|
+
/** default: "/" */
|
|
14
|
+
path?: string;
|
|
15
|
+
/** default: 60 * 60 * 24 * 365 (365 days) */
|
|
16
|
+
maxAge?: number;
|
|
17
|
+
/** default: false */
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
/** default: process.env.NODE_ENV !== "development" */
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
/** default: lax */
|
|
22
|
+
sameSite?: "lax" | "strict" | "none";
|
|
23
|
+
};
|
|
24
|
+
type CookieResolvedOptions = Required<Omit<CookieRawOptions, "domain">> & {
|
|
25
|
+
domain: string | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ```ts
|
|
30
|
+
* {
|
|
31
|
+
* default: ["ui", "meta"],
|
|
32
|
+
* "/auth": ["auth", "admin"],
|
|
33
|
+
* }
|
|
34
|
+
* // When pathname is "/" => namespaces: ["ui", "meta"]
|
|
35
|
+
* // When pathname is "/auth" => namespaces: ["ui", "meta", "auth", "admin"]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type RouteNamespaces = {
|
|
39
|
+
[key: string]: string[];
|
|
40
|
+
} | {
|
|
41
|
+
[key: string]: string[];
|
|
42
|
+
default: string[];
|
|
43
|
+
};
|
|
44
|
+
interface ApiHeaders {
|
|
45
|
+
authorization?: string;
|
|
46
|
+
"x-api-key"?: string;
|
|
47
|
+
[key: string]: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
type BaseLoaderOptions = {
|
|
50
|
+
basePath?: string;
|
|
51
|
+
namespaces?: string[];
|
|
52
|
+
routeNamespaces?: RouteNamespaces;
|
|
53
|
+
concurrency?: number;
|
|
54
|
+
lazyLoad?: boolean;
|
|
55
|
+
};
|
|
56
|
+
type ImportLoader = BaseLoaderOptions & {
|
|
57
|
+
type: "import";
|
|
58
|
+
};
|
|
59
|
+
type ApiLoader = BaseLoaderOptions & {
|
|
60
|
+
type: "api";
|
|
61
|
+
apiUrl: string;
|
|
62
|
+
apiHeaders?: ApiHeaders;
|
|
63
|
+
fullReload?: boolean;
|
|
64
|
+
};
|
|
65
|
+
type LoaderOptions = ImportLoader | ApiLoader;
|
|
66
|
+
|
|
67
|
+
type LoggerOptions = {
|
|
68
|
+
level?: Level;
|
|
69
|
+
normalizerConfig?: NormalizerConfig;
|
|
70
|
+
formatterConfig?: FormatterConfig;
|
|
71
|
+
preset?: LoggerPreset;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
declare const routingPrefix: readonly ["none", "all", "except-default"];
|
|
75
|
+
declare const routingFirstVisitLocaleSource: readonly ["default", "browser"];
|
|
76
|
+
type RoutingRawOptions = {
|
|
77
|
+
/** default: "none" */
|
|
78
|
+
prefix?: (typeof routingPrefix)[number];
|
|
79
|
+
firstVisit?: {
|
|
80
|
+
/** default: "browser" */
|
|
81
|
+
localeSource?: (typeof routingFirstVisitLocaleSource)[number];
|
|
82
|
+
/** default: true */
|
|
83
|
+
redirect?: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** default: "" */
|
|
86
|
+
basePath?: string;
|
|
87
|
+
};
|
|
88
|
+
type RoutingResolvedOptions = Required<RoutingRawOptions>;
|
|
89
|
+
|
|
90
|
+
type CacheRawOptions = {
|
|
91
|
+
enabled?: boolean;
|
|
92
|
+
/** default: 60\*60\*1000 (1 hour) */
|
|
93
|
+
ttl?: number;
|
|
94
|
+
};
|
|
95
|
+
type CacheResolvedOptions = Required<CacheRawOptions>;
|
|
96
|
+
|
|
97
|
+
type TranslatorOptions = {
|
|
98
|
+
loadingMessage?: string;
|
|
99
|
+
placeholder?: string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type WithoutLoader = {
|
|
103
|
+
loader?: undefined;
|
|
104
|
+
supportedLocales?: readonly Locale[];
|
|
105
|
+
};
|
|
106
|
+
type WithLoader = {
|
|
107
|
+
loader: LoaderOptions;
|
|
108
|
+
supportedLocales: readonly Locale[];
|
|
109
|
+
};
|
|
110
|
+
type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
|
|
111
|
+
readonly id: string;
|
|
112
|
+
readonly messages?: LocaleNamespaceMessages;
|
|
113
|
+
readonly defaultLocale: Locale;
|
|
114
|
+
readonly fallbackLocales: FallbackLocalesMap;
|
|
115
|
+
readonly translator?: TranslatorOptions;
|
|
116
|
+
readonly cookie: CookieResolvedOptions;
|
|
117
|
+
readonly routing: RoutingResolvedOptions;
|
|
118
|
+
readonly logger?: LoggerOptions;
|
|
119
|
+
readonly cache: CacheResolvedOptions;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
interface AdapterRuntime {
|
|
123
|
+
locale: Locale;
|
|
124
|
+
pathname: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Prepares runtime data for Next.js.
|
|
129
|
+
*/
|
|
130
|
+
declare const nextAdapter: (config: IntorResolvedConfig) => Promise<AdapterRuntime>;
|
|
131
|
+
|
|
132
|
+
type MessagesLoaderResult = Promise<LocaleNamespaceMessages | undefined>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Retrieves messages in a Next.js SSR environment.
|
|
136
|
+
* This function wraps the standard `getMessages` with the Next.js adapter,
|
|
137
|
+
* automatically resolving runtime data.
|
|
138
|
+
*/
|
|
139
|
+
declare const getMessages: (config: IntorResolvedConfig) => Promise<MessagesLoaderResult>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a ready-to-use translation function (`t`) for the current
|
|
143
|
+
* Next.js SSR runtime environment. It automatically resolves the
|
|
144
|
+
* locale and pathname using the Next.js adapter, loads all
|
|
145
|
+
* corresponding messages, and returns a `t` function bound to them.
|
|
146
|
+
*/
|
|
147
|
+
declare const getTranslation: (config: IntorResolvedConfig, preKey?: string, options?: TranslateConfig<unknown>) => Promise<Translator["t"]>;
|
|
148
|
+
|
|
149
|
+
export { getMessages, getTranslation, nextAdapter };
|