@comvi/next 0.1.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 +21 -0
- package/README.md +256 -0
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/client/I18nProvider.cjs +101 -0
- package/dist/client/I18nProvider.d.ts +84 -0
- package/dist/client/I18nProvider.d.ts.map +1 -0
- package/dist/client/I18nProvider.js +99 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client.cjs +31 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +5 -0
- package/dist/createNextI18n.cjs +153 -0
- package/dist/createNextI18n.d.ts +183 -0
- package/dist/createNextI18n.d.ts.map +1 -0
- package/dist/createNextI18n.js +152 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/middleware/createMiddleware.cjs +185 -0
- package/dist/middleware/createMiddleware.d.ts +38 -0
- package/dist/middleware/createMiddleware.d.ts.map +1 -0
- package/dist/middleware/createMiddleware.js +184 -0
- package/dist/middleware/types.d.ts +87 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware.cjs +3 -0
- package/dist/middleware.d.ts +3 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +2 -0
- package/dist/navigation.cjs +8 -0
- package/dist/navigation.d.ts +5 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +5 -0
- package/dist/routing/Link.cjs +42 -0
- package/dist/routing/Link.d.ts +25 -0
- package/dist/routing/Link.d.ts.map +1 -0
- package/dist/routing/Link.js +39 -0
- package/dist/routing/context.cjs +21 -0
- package/dist/routing/context.d.ts +9 -0
- package/dist/routing/context.d.ts.map +1 -0
- package/dist/routing/context.js +18 -0
- package/dist/routing/defineRouting.cjs +141 -0
- package/dist/routing/defineRouting.d.ts +123 -0
- package/dist/routing/defineRouting.d.ts.map +1 -0
- package/dist/routing/defineRouting.js +139 -0
- package/dist/routing/hooks.cjs +104 -0
- package/dist/routing/hooks.d.ts +66 -0
- package/dist/routing/hooks.d.ts.map +1 -0
- package/dist/routing/hooks.js +102 -0
- package/dist/routing/types.d.ts +35 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/utils.cjs +94 -0
- package/dist/routing/utils.d.ts +8 -0
- package/dist/routing/utils.d.ts.map +1 -0
- package/dist/routing/utils.js +91 -0
- package/dist/routing.cjs +5 -0
- package/dist/routing.d.ts +4 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +2 -0
- package/dist/server/cache.cjs +69 -0
- package/dist/server/cache.d.ts +42 -0
- package/dist/server/cache.d.ts.map +1 -0
- package/dist/server/cache.js +66 -0
- package/dist/server/ensureInitialized.cjs +19 -0
- package/dist/server/ensureInitialized.d.ts +7 -0
- package/dist/server/ensureInitialized.d.ts.map +1 -0
- package/dist/server/ensureInitialized.js +19 -0
- package/dist/server/getI18n.cjs +115 -0
- package/dist/server/getI18n.d.ts +61 -0
- package/dist/server/getI18n.d.ts.map +1 -0
- package/dist/server/getI18n.js +114 -0
- package/dist/server/getLocale.cjs +37 -0
- package/dist/server/getLocale.d.ts +22 -0
- package/dist/server/getLocale.d.ts.map +1 -0
- package/dist/server/getLocale.js +36 -0
- package/dist/server/loadTranslations.cjs +54 -0
- package/dist/server/loadTranslations.d.ts +34 -0
- package/dist/server/loadTranslations.d.ts.map +1 -0
- package/dist/server/loadTranslations.js +54 -0
- package/dist/server/setRequestLocale.cjs +31 -0
- package/dist/server/setRequestLocale.d.ts +26 -0
- package/dist/server/setRequestLocale.d.ts.map +1 -0
- package/dist/server/setRequestLocale.js +31 -0
- package/dist/server/types.d.ts +43 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server.cjs +11 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +6 -0
- package/package.json +111 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_defineRouting = require("./routing/defineRouting.cjs");
|
|
3
|
+
let _comvi_core = require("@comvi/core");
|
|
4
|
+
//#region src/createNextI18n.ts
|
|
5
|
+
var resolveLazyPlugin = (moduleOrPlugin) => {
|
|
6
|
+
if (typeof moduleOrPlugin === "function") return moduleOrPlugin;
|
|
7
|
+
if (moduleOrPlugin && typeof moduleOrPlugin.default === "function") return moduleOrPlugin.default;
|
|
8
|
+
throw new Error("[comvi/next] Invalid lazy plugin module. Expected a plugin function or { default: pluginFunction }.");
|
|
9
|
+
};
|
|
10
|
+
var isClientRuntime = () => {
|
|
11
|
+
if (process.env.NEXT_RUNTIME) return false;
|
|
12
|
+
return typeof window !== "undefined";
|
|
13
|
+
};
|
|
14
|
+
var shouldRunForRuntime = (runtime) => {
|
|
15
|
+
const isClient = isClientRuntime();
|
|
16
|
+
return runtime === "client" ? isClient : !isClient;
|
|
17
|
+
};
|
|
18
|
+
var shouldRunForEnvironment = (environment) => {
|
|
19
|
+
if (environment === "all") return true;
|
|
20
|
+
return environment === (process.env.NODE_ENV === "production" ? "production" : "development");
|
|
21
|
+
};
|
|
22
|
+
var createScopedPlugin = (plugin, runtime, environment) => {
|
|
23
|
+
return (i18n) => {
|
|
24
|
+
if (!shouldRunForRuntime(runtime) || !shouldRunForEnvironment(environment)) return;
|
|
25
|
+
return plugin(i18n);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
var createScopedLazyPlugin = (loadPlugin, runtime, environment) => {
|
|
29
|
+
let pluginPromise = null;
|
|
30
|
+
return (i18n) => {
|
|
31
|
+
if (!shouldRunForRuntime(runtime) || !shouldRunForEnvironment(environment)) return;
|
|
32
|
+
if (!pluginPromise) pluginPromise = loadPlugin().then(resolveLazyPlugin);
|
|
33
|
+
return pluginPromise.then((plugin) => plugin(i18n));
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
var normalizeScopedOptions = (options) => {
|
|
37
|
+
const { environment = "all", ...pluginOptions } = options ?? {};
|
|
38
|
+
return {
|
|
39
|
+
environment,
|
|
40
|
+
pluginOptions
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Create a fully configured Next.js i18n setup with a single function call.
|
|
45
|
+
*
|
|
46
|
+
* This factory creates:
|
|
47
|
+
* - i18n instance
|
|
48
|
+
* - Routing configuration for middleware and navigation
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // i18n/config.ts
|
|
53
|
+
* import { createNextI18n } from "@comvi/next";
|
|
54
|
+
*
|
|
55
|
+
* export const { i18n, routing } = createNextI18n({
|
|
56
|
+
* // Routing
|
|
57
|
+
* locales: ["en", "de", "uk"],
|
|
58
|
+
* defaultLocale: "en",
|
|
59
|
+
*
|
|
60
|
+
* // Optional
|
|
61
|
+
* basicHtmlTags: ["strong", "em", "br", "a"],
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Optional plugin registration (same DX as core/react)
|
|
68
|
+
* import { FetchLoader } from "@comvi/plugin-fetch-loader";
|
|
69
|
+
*
|
|
70
|
+
* const nextI18n = createNextI18n({
|
|
71
|
+
* locales: ["en", "de"],
|
|
72
|
+
* defaultLocale: "en",
|
|
73
|
+
* })
|
|
74
|
+
* .use(
|
|
75
|
+
* FetchLoader({
|
|
76
|
+
* cdnUrl: "https://cdn.comvi.io/your-distribution-id",
|
|
77
|
+
* loadOnInit: false,
|
|
78
|
+
* }),
|
|
79
|
+
* )
|
|
80
|
+
* .useServer(MyServerPlugin())
|
|
81
|
+
* .useClientLazy(
|
|
82
|
+
* () => import("@comvi/plugin-in-context-editor").then((m) => m.InContextEditorPlugin()),
|
|
83
|
+
* { environment: "development", required: false },
|
|
84
|
+
* )
|
|
85
|
+
* .use(MyPlugin())
|
|
86
|
+
* .use(AnotherPlugin(), { required: false });
|
|
87
|
+
*
|
|
88
|
+
* export const { i18n, routing } = nextI18n;
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // i18n/server.ts - Server entry point
|
|
94
|
+
* import "server-only";
|
|
95
|
+
* import { setI18n } from "@comvi/next/server";
|
|
96
|
+
* import { i18n } from "./config";
|
|
97
|
+
*
|
|
98
|
+
* setI18n(i18n);
|
|
99
|
+
*
|
|
100
|
+
* export { i18n, routing } from "./config";
|
|
101
|
+
* export { getI18n, loadTranslations } from "@comvi/next/server";
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
function createNextI18n(options) {
|
|
105
|
+
const { locales, defaultLocale, localePrefix = "as-needed", pathnames, apiKey, ns, translation, fallbackLocale = defaultLocale, defaultNs = "default", devMode: devModeOption, basicHtmlTags, onMissingKey } = options;
|
|
106
|
+
const i18n = (0, _comvi_core.createI18n)({
|
|
107
|
+
locale: defaultLocale,
|
|
108
|
+
fallbackLocale,
|
|
109
|
+
defaultNs,
|
|
110
|
+
ns,
|
|
111
|
+
translation,
|
|
112
|
+
apiKey,
|
|
113
|
+
devMode: devModeOption ?? process.env.NODE_ENV === "development",
|
|
114
|
+
onMissingKey,
|
|
115
|
+
tagInterpolation: basicHtmlTags ? { basicHtmlTags } : void 0
|
|
116
|
+
});
|
|
117
|
+
const result = {
|
|
118
|
+
i18n,
|
|
119
|
+
routing: require_defineRouting.defineRouting({
|
|
120
|
+
locales,
|
|
121
|
+
defaultLocale,
|
|
122
|
+
localePrefix,
|
|
123
|
+
pathnames
|
|
124
|
+
}),
|
|
125
|
+
use(plugin, pluginOptions) {
|
|
126
|
+
i18n.use(plugin, pluginOptions);
|
|
127
|
+
return result;
|
|
128
|
+
},
|
|
129
|
+
useClient(plugin, options) {
|
|
130
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
131
|
+
i18n.use(createScopedPlugin(plugin, "client", environment), pluginOptions);
|
|
132
|
+
return result;
|
|
133
|
+
},
|
|
134
|
+
useServer(plugin, options) {
|
|
135
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
136
|
+
i18n.use(createScopedPlugin(plugin, "server", environment), pluginOptions);
|
|
137
|
+
return result;
|
|
138
|
+
},
|
|
139
|
+
useClientLazy(loadPlugin, options) {
|
|
140
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
141
|
+
i18n.use(createScopedLazyPlugin(loadPlugin, "client", environment), pluginOptions);
|
|
142
|
+
return result;
|
|
143
|
+
},
|
|
144
|
+
useServerLazy(loadPlugin, options) {
|
|
145
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
146
|
+
i18n.use(createScopedLazyPlugin(loadPlugin, "server", environment), pluginOptions);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
exports.createNextI18n = createNextI18n;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { I18nOptions, I18n, I18nPlugin, PluginOptions } from '@comvi/core';
|
|
2
|
+
import { RoutingConfig, LocalePrefixMode } from './routing/types';
|
|
3
|
+
type PluginEnvironment = "all" | "development" | "production";
|
|
4
|
+
export interface ScopedPluginOptions extends PluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Environment where plugin should run.
|
|
7
|
+
* @default "all"
|
|
8
|
+
*/
|
|
9
|
+
environment?: PluginEnvironment;
|
|
10
|
+
}
|
|
11
|
+
export type LazyPluginModule = I18nPlugin | {
|
|
12
|
+
default: I18nPlugin;
|
|
13
|
+
};
|
|
14
|
+
export type LazyPluginLoader = () => Promise<LazyPluginModule>;
|
|
15
|
+
/**
|
|
16
|
+
* Options for createNextI18n factory
|
|
17
|
+
*/
|
|
18
|
+
export interface CreateNextI18nOptions {
|
|
19
|
+
/**
|
|
20
|
+
* List of supported locales
|
|
21
|
+
* @example ['en', 'de', 'uk', 'fr']
|
|
22
|
+
*/
|
|
23
|
+
locales: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Default locale (used when no locale is detected)
|
|
26
|
+
* @example 'en'
|
|
27
|
+
*/
|
|
28
|
+
defaultLocale: string;
|
|
29
|
+
/**
|
|
30
|
+
* Locale prefix mode for URLs
|
|
31
|
+
* - 'always': Always include locale in URL (/en/about, /de/about)
|
|
32
|
+
* - 'as-needed': Only include for non-default locales (/about, /de/about)
|
|
33
|
+
* - 'never': Never include locale in URL (use cookies/headers)
|
|
34
|
+
* @default 'as-needed'
|
|
35
|
+
*/
|
|
36
|
+
localePrefix?: LocalePrefixMode;
|
|
37
|
+
/**
|
|
38
|
+
* Localized public pathnames for exact static routes.
|
|
39
|
+
* Keys are canonical internal routes, values are public localized slugs.
|
|
40
|
+
*/
|
|
41
|
+
pathnames?: RoutingConfig["pathnames"];
|
|
42
|
+
/**
|
|
43
|
+
* API key available to plugins/loaders that need authenticated requests.
|
|
44
|
+
*/
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Namespaces to load during init.
|
|
48
|
+
* If omitted, only default namespace is loaded.
|
|
49
|
+
*/
|
|
50
|
+
ns?: I18nOptions["ns"];
|
|
51
|
+
/**
|
|
52
|
+
* Static translations to seed i18n cache (no loader required).
|
|
53
|
+
*/
|
|
54
|
+
translation?: I18nOptions["translation"];
|
|
55
|
+
/**
|
|
56
|
+
* Fallback locale when translation is missing
|
|
57
|
+
* @default same as defaultLocale
|
|
58
|
+
*/
|
|
59
|
+
fallbackLocale?: string | string[];
|
|
60
|
+
/**
|
|
61
|
+
* Default namespace for translations
|
|
62
|
+
* @default 'default'
|
|
63
|
+
*/
|
|
64
|
+
defaultNs?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Development mode (uses API instead of CDN)
|
|
67
|
+
* @default process.env.NODE_ENV === 'development'
|
|
68
|
+
*/
|
|
69
|
+
devMode?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* HTML tags allowed in translations (for tag interpolation)
|
|
72
|
+
* @example ['strong', 'em', 'br', 'a']
|
|
73
|
+
*/
|
|
74
|
+
basicHtmlTags?: string[];
|
|
75
|
+
/**
|
|
76
|
+
* Callback for missing translation keys
|
|
77
|
+
*/
|
|
78
|
+
onMissingKey?: I18nOptions["onMissingKey"];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Result of createNextI18n factory
|
|
82
|
+
*/
|
|
83
|
+
export interface CreateNextI18nResult {
|
|
84
|
+
/**
|
|
85
|
+
* The i18n instance (use with I18nProvider and setI18n)
|
|
86
|
+
*/
|
|
87
|
+
i18n: I18n;
|
|
88
|
+
/**
|
|
89
|
+
* Routing configuration (use with middleware and navigation)
|
|
90
|
+
*/
|
|
91
|
+
routing: Required<RoutingConfig>;
|
|
92
|
+
/**
|
|
93
|
+
* Register an additional i18n plugin (chainable).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const nextI18n = createNextI18n({...})
|
|
98
|
+
* .use(MyPlugin())
|
|
99
|
+
* .use(AnotherPlugin(), { required: false });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
use(plugin: I18nPlugin, options?: PluginOptions): CreateNextI18nResult;
|
|
103
|
+
/**
|
|
104
|
+
* Register a client-only plugin.
|
|
105
|
+
*/
|
|
106
|
+
useClient(plugin: I18nPlugin, options?: ScopedPluginOptions): CreateNextI18nResult;
|
|
107
|
+
/**
|
|
108
|
+
* Register a server-only plugin.
|
|
109
|
+
*/
|
|
110
|
+
useServer(plugin: I18nPlugin, options?: ScopedPluginOptions): CreateNextI18nResult;
|
|
111
|
+
/**
|
|
112
|
+
* Register a lazily imported client-only plugin.
|
|
113
|
+
*/
|
|
114
|
+
useClientLazy(loadPlugin: LazyPluginLoader, options?: ScopedPluginOptions): CreateNextI18nResult;
|
|
115
|
+
/**
|
|
116
|
+
* Register a lazily imported server-only plugin.
|
|
117
|
+
*/
|
|
118
|
+
useServerLazy(loadPlugin: LazyPluginLoader, options?: ScopedPluginOptions): CreateNextI18nResult;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a fully configured Next.js i18n setup with a single function call.
|
|
122
|
+
*
|
|
123
|
+
* This factory creates:
|
|
124
|
+
* - i18n instance
|
|
125
|
+
* - Routing configuration for middleware and navigation
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // i18n/config.ts
|
|
130
|
+
* import { createNextI18n } from "@comvi/next";
|
|
131
|
+
*
|
|
132
|
+
* export const { i18n, routing } = createNextI18n({
|
|
133
|
+
* // Routing
|
|
134
|
+
* locales: ["en", "de", "uk"],
|
|
135
|
+
* defaultLocale: "en",
|
|
136
|
+
*
|
|
137
|
+
* // Optional
|
|
138
|
+
* basicHtmlTags: ["strong", "em", "br", "a"],
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* // Optional plugin registration (same DX as core/react)
|
|
145
|
+
* import { FetchLoader } from "@comvi/plugin-fetch-loader";
|
|
146
|
+
*
|
|
147
|
+
* const nextI18n = createNextI18n({
|
|
148
|
+
* locales: ["en", "de"],
|
|
149
|
+
* defaultLocale: "en",
|
|
150
|
+
* })
|
|
151
|
+
* .use(
|
|
152
|
+
* FetchLoader({
|
|
153
|
+
* cdnUrl: "https://cdn.comvi.io/your-distribution-id",
|
|
154
|
+
* loadOnInit: false,
|
|
155
|
+
* }),
|
|
156
|
+
* )
|
|
157
|
+
* .useServer(MyServerPlugin())
|
|
158
|
+
* .useClientLazy(
|
|
159
|
+
* () => import("@comvi/plugin-in-context-editor").then((m) => m.InContextEditorPlugin()),
|
|
160
|
+
* { environment: "development", required: false },
|
|
161
|
+
* )
|
|
162
|
+
* .use(MyPlugin())
|
|
163
|
+
* .use(AnotherPlugin(), { required: false });
|
|
164
|
+
*
|
|
165
|
+
* export const { i18n, routing } = nextI18n;
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // i18n/server.ts - Server entry point
|
|
171
|
+
* import "server-only";
|
|
172
|
+
* import { setI18n } from "@comvi/next/server";
|
|
173
|
+
* import { i18n } from "./config";
|
|
174
|
+
*
|
|
175
|
+
* setI18n(i18n);
|
|
176
|
+
*
|
|
177
|
+
* export { i18n, routing } from "./config";
|
|
178
|
+
* export { getI18n, loadTranslations } from "@comvi/next/server";
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare function createNextI18n(options: CreateNextI18nOptions): CreateNextI18nResult;
|
|
182
|
+
export {};
|
|
183
|
+
//# sourceMappingURL=createNextI18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNextI18n.d.ts","sourceRoot":"","sources":["../src/createNextI18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEhF,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGvE,KAAK,iBAAiB,GAAG,KAAK,GAAG,aAAa,GAAG,YAAY,CAAC;AAI9D,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD;;;OAGG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,CAAC;AACpE,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAwE/D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAKpC;;;OAGG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAEhC;;;OAGG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAMvC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,EAAE,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IAEzC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEnC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEjC;;;;;;;;;OASG;IACH,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,oBAAoB,CAAC;IAEvE;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;IAEnF;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;IAEnF;;OAEG;IACH,aAAa,CAAC,UAAU,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;IAEjG;;OAEG;IACH,aAAa,CAAC,UAAU,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;CAClG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CA0EnF"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { defineRouting } from "./routing/defineRouting.js";
|
|
2
|
+
import { createI18n } from "@comvi/core";
|
|
3
|
+
//#region src/createNextI18n.ts
|
|
4
|
+
var resolveLazyPlugin = (moduleOrPlugin) => {
|
|
5
|
+
if (typeof moduleOrPlugin === "function") return moduleOrPlugin;
|
|
6
|
+
if (moduleOrPlugin && typeof moduleOrPlugin.default === "function") return moduleOrPlugin.default;
|
|
7
|
+
throw new Error("[comvi/next] Invalid lazy plugin module. Expected a plugin function or { default: pluginFunction }.");
|
|
8
|
+
};
|
|
9
|
+
var isClientRuntime = () => {
|
|
10
|
+
if (process.env.NEXT_RUNTIME) return false;
|
|
11
|
+
return typeof window !== "undefined";
|
|
12
|
+
};
|
|
13
|
+
var shouldRunForRuntime = (runtime) => {
|
|
14
|
+
const isClient = isClientRuntime();
|
|
15
|
+
return runtime === "client" ? isClient : !isClient;
|
|
16
|
+
};
|
|
17
|
+
var shouldRunForEnvironment = (environment) => {
|
|
18
|
+
if (environment === "all") return true;
|
|
19
|
+
return environment === (process.env.NODE_ENV === "production" ? "production" : "development");
|
|
20
|
+
};
|
|
21
|
+
var createScopedPlugin = (plugin, runtime, environment) => {
|
|
22
|
+
return (i18n) => {
|
|
23
|
+
if (!shouldRunForRuntime(runtime) || !shouldRunForEnvironment(environment)) return;
|
|
24
|
+
return plugin(i18n);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
var createScopedLazyPlugin = (loadPlugin, runtime, environment) => {
|
|
28
|
+
let pluginPromise = null;
|
|
29
|
+
return (i18n) => {
|
|
30
|
+
if (!shouldRunForRuntime(runtime) || !shouldRunForEnvironment(environment)) return;
|
|
31
|
+
if (!pluginPromise) pluginPromise = loadPlugin().then(resolveLazyPlugin);
|
|
32
|
+
return pluginPromise.then((plugin) => plugin(i18n));
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
var normalizeScopedOptions = (options) => {
|
|
36
|
+
const { environment = "all", ...pluginOptions } = options ?? {};
|
|
37
|
+
return {
|
|
38
|
+
environment,
|
|
39
|
+
pluginOptions
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Create a fully configured Next.js i18n setup with a single function call.
|
|
44
|
+
*
|
|
45
|
+
* This factory creates:
|
|
46
|
+
* - i18n instance
|
|
47
|
+
* - Routing configuration for middleware and navigation
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // i18n/config.ts
|
|
52
|
+
* import { createNextI18n } from "@comvi/next";
|
|
53
|
+
*
|
|
54
|
+
* export const { i18n, routing } = createNextI18n({
|
|
55
|
+
* // Routing
|
|
56
|
+
* locales: ["en", "de", "uk"],
|
|
57
|
+
* defaultLocale: "en",
|
|
58
|
+
*
|
|
59
|
+
* // Optional
|
|
60
|
+
* basicHtmlTags: ["strong", "em", "br", "a"],
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Optional plugin registration (same DX as core/react)
|
|
67
|
+
* import { FetchLoader } from "@comvi/plugin-fetch-loader";
|
|
68
|
+
*
|
|
69
|
+
* const nextI18n = createNextI18n({
|
|
70
|
+
* locales: ["en", "de"],
|
|
71
|
+
* defaultLocale: "en",
|
|
72
|
+
* })
|
|
73
|
+
* .use(
|
|
74
|
+
* FetchLoader({
|
|
75
|
+
* cdnUrl: "https://cdn.comvi.io/your-distribution-id",
|
|
76
|
+
* loadOnInit: false,
|
|
77
|
+
* }),
|
|
78
|
+
* )
|
|
79
|
+
* .useServer(MyServerPlugin())
|
|
80
|
+
* .useClientLazy(
|
|
81
|
+
* () => import("@comvi/plugin-in-context-editor").then((m) => m.InContextEditorPlugin()),
|
|
82
|
+
* { environment: "development", required: false },
|
|
83
|
+
* )
|
|
84
|
+
* .use(MyPlugin())
|
|
85
|
+
* .use(AnotherPlugin(), { required: false });
|
|
86
|
+
*
|
|
87
|
+
* export const { i18n, routing } = nextI18n;
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // i18n/server.ts - Server entry point
|
|
93
|
+
* import "server-only";
|
|
94
|
+
* import { setI18n } from "@comvi/next/server";
|
|
95
|
+
* import { i18n } from "./config";
|
|
96
|
+
*
|
|
97
|
+
* setI18n(i18n);
|
|
98
|
+
*
|
|
99
|
+
* export { i18n, routing } from "./config";
|
|
100
|
+
* export { getI18n, loadTranslations } from "@comvi/next/server";
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
function createNextI18n(options) {
|
|
104
|
+
const { locales, defaultLocale, localePrefix = "as-needed", pathnames, apiKey, ns, translation, fallbackLocale = defaultLocale, defaultNs = "default", devMode: devModeOption, basicHtmlTags, onMissingKey } = options;
|
|
105
|
+
const i18n = createI18n({
|
|
106
|
+
locale: defaultLocale,
|
|
107
|
+
fallbackLocale,
|
|
108
|
+
defaultNs,
|
|
109
|
+
ns,
|
|
110
|
+
translation,
|
|
111
|
+
apiKey,
|
|
112
|
+
devMode: devModeOption ?? process.env.NODE_ENV === "development",
|
|
113
|
+
onMissingKey,
|
|
114
|
+
tagInterpolation: basicHtmlTags ? { basicHtmlTags } : void 0
|
|
115
|
+
});
|
|
116
|
+
const result = {
|
|
117
|
+
i18n,
|
|
118
|
+
routing: defineRouting({
|
|
119
|
+
locales,
|
|
120
|
+
defaultLocale,
|
|
121
|
+
localePrefix,
|
|
122
|
+
pathnames
|
|
123
|
+
}),
|
|
124
|
+
use(plugin, pluginOptions) {
|
|
125
|
+
i18n.use(plugin, pluginOptions);
|
|
126
|
+
return result;
|
|
127
|
+
},
|
|
128
|
+
useClient(plugin, options) {
|
|
129
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
130
|
+
i18n.use(createScopedPlugin(plugin, "client", environment), pluginOptions);
|
|
131
|
+
return result;
|
|
132
|
+
},
|
|
133
|
+
useServer(plugin, options) {
|
|
134
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
135
|
+
i18n.use(createScopedPlugin(plugin, "server", environment), pluginOptions);
|
|
136
|
+
return result;
|
|
137
|
+
},
|
|
138
|
+
useClientLazy(loadPlugin, options) {
|
|
139
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
140
|
+
i18n.use(createScopedLazyPlugin(loadPlugin, "client", environment), pluginOptions);
|
|
141
|
+
return result;
|
|
142
|
+
},
|
|
143
|
+
useServerLazy(loadPlugin, options) {
|
|
144
|
+
const { environment, pluginOptions } = normalizeScopedOptions(options);
|
|
145
|
+
i18n.use(createScopedLazyPlugin(loadPlugin, "server", environment), pluginOptions);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { createNextI18n };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_createNextI18n = require("./createNextI18n.cjs");
|
|
4
|
+
let _comvi_core = require("@comvi/core");
|
|
5
|
+
Object.defineProperty(exports, "I18n", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _comvi_core.I18n;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "createI18n", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return _comvi_core.createI18n;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
exports.createNextI18n = require_createNextI18n.createNextI18n;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createI18n, I18n } from '@comvi/core';
|
|
2
|
+
export type * from '@comvi/core';
|
|
3
|
+
export { createNextI18n } from './createNextI18n';
|
|
4
|
+
export type { CreateNextI18nOptions, CreateNextI18nResult } from './createNextI18n';
|
|
5
|
+
export type { RoutingConfig, LocalePrefixMode } from './routing/types';
|
|
6
|
+
export type { MiddlewareConfig } from './middleware/types';
|
|
7
|
+
export type { GetI18nOptions } from './server/types';
|
|
8
|
+
export type { I18nProviderProps } from './client/I18nProvider';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC/C,mBAAmB,aAAa,CAAC;AAGjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGpF,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED