@djangocfg/nextjs 2.1.109 → 2.1.111
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 +176 -7
- package/dist/config/index.d.mts +16 -1
- package/dist/config/index.mjs +83 -14
- package/dist/config/index.mjs.map +1 -1
- package/dist/i18n/client.d.mts +123 -0
- package/dist/i18n/client.mjs +104 -0
- package/dist/i18n/client.mjs.map +1 -0
- package/dist/i18n/components.d.mts +22 -0
- package/dist/i18n/components.mjs +133 -0
- package/dist/i18n/components.mjs.map +1 -0
- package/dist/i18n/index.d.mts +17 -0
- package/dist/i18n/index.mjs +269 -0
- package/dist/i18n/index.mjs.map +1 -0
- package/dist/i18n/navigation.d.mts +1095 -0
- package/dist/i18n/navigation.mjs +45 -0
- package/dist/i18n/navigation.mjs.map +1 -0
- package/dist/i18n/plugin.d.mts +41 -0
- package/dist/i18n/plugin.mjs +17 -0
- package/dist/i18n/plugin.mjs.map +1 -0
- package/dist/i18n/provider.d.mts +18 -0
- package/dist/i18n/provider.mjs +54 -0
- package/dist/i18n/provider.mjs.map +1 -0
- package/dist/i18n/proxy.d.mts +40 -0
- package/dist/i18n/proxy.mjs +42 -0
- package/dist/i18n/proxy.mjs.map +1 -0
- package/dist/i18n/request.d.mts +42 -0
- package/dist/i18n/request.mjs +63 -0
- package/dist/i18n/request.mjs.map +1 -0
- package/dist/i18n/routing.d.mts +79 -0
- package/dist/i18n/routing.mjs +33 -0
- package/dist/i18n/routing.mjs.map +1 -0
- package/dist/i18n/server.d.mts +90 -0
- package/dist/i18n/server.mjs +79 -0
- package/dist/i18n/server.mjs.map +1 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +176 -30
- package/dist/index.mjs.map +1 -1
- package/dist/sitemap/index.d.mts +22 -3
- package/dist/sitemap/index.mjs +92 -15
- package/dist/sitemap/index.mjs.map +1 -1
- package/dist/types-Cy349X20.d.mts +60 -0
- package/package.json +54 -4
- package/src/config/constants.ts +1 -0
- package/src/config/createNextConfig.ts +39 -17
- package/src/i18n/client.ts +221 -0
- package/src/i18n/components/LocaleSwitcher.tsx +124 -0
- package/src/i18n/components/index.ts +7 -0
- package/src/i18n/index.ts +149 -0
- package/src/i18n/navigation.ts +90 -0
- package/src/i18n/plugin.ts +66 -0
- package/src/i18n/provider.tsx +91 -0
- package/src/i18n/proxy.ts +81 -0
- package/src/i18n/request.ts +141 -0
- package/src/i18n/routing.ts +84 -0
- package/src/i18n/server.ts +175 -0
- package/src/i18n/types.ts +88 -0
- package/src/sitemap/generator.ts +84 -9
- package/src/sitemap/index.ts +1 -1
- package/src/sitemap/route.ts +71 -8
- package/src/sitemap/types.ts +9 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/i18n/navigation.ts
|
|
2
|
+
import { createNavigation as createNextIntlNavigation } from "next-intl/navigation";
|
|
3
|
+
|
|
4
|
+
// src/i18n/routing.ts
|
|
5
|
+
import { defineRouting } from "next-intl/routing";
|
|
6
|
+
var DEFAULT_LOCALES = ["en", "ru", "ko"];
|
|
7
|
+
var DEFAULT_LOCALE = "en";
|
|
8
|
+
function createRouting(config) {
|
|
9
|
+
const locales = config?.locales ?? DEFAULT_LOCALES;
|
|
10
|
+
const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;
|
|
11
|
+
const localePrefix = config?.localePrefix ?? "always";
|
|
12
|
+
return defineRouting({
|
|
13
|
+
locales,
|
|
14
|
+
defaultLocale,
|
|
15
|
+
localePrefix
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
var routing = createRouting();
|
|
19
|
+
|
|
20
|
+
// src/i18n/navigation.ts
|
|
21
|
+
function createNavigation(routingConfig) {
|
|
22
|
+
const config = routingConfig ?? routing;
|
|
23
|
+
return createNextIntlNavigation(config);
|
|
24
|
+
}
|
|
25
|
+
function createNavigationFromConfig(config) {
|
|
26
|
+
const routingConfig = createRouting(config);
|
|
27
|
+
return createNextIntlNavigation(routingConfig);
|
|
28
|
+
}
|
|
29
|
+
var {
|
|
30
|
+
Link,
|
|
31
|
+
redirect,
|
|
32
|
+
usePathname,
|
|
33
|
+
useRouter,
|
|
34
|
+
getPathname
|
|
35
|
+
} = createNavigation();
|
|
36
|
+
export {
|
|
37
|
+
Link,
|
|
38
|
+
createNavigation,
|
|
39
|
+
createNavigationFromConfig,
|
|
40
|
+
getPathname,
|
|
41
|
+
redirect,
|
|
42
|
+
usePathname,
|
|
43
|
+
useRouter
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=navigation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/navigation.ts","../../src/i18n/routing.ts"],"sourcesContent":["/**\n * i18n Navigation Utilities\n *\n * Provides locale-aware navigation components and functions\n *\n * @example\n * ```ts\n * // In your app's i18n/navigation.ts\n * import { createNavigation } from '@djangocfg/nextjs/i18n';\n * import { routing } from './routing';\n *\n * export const { Link, redirect, usePathname, useRouter } = createNavigation(routing);\n * ```\n *\n * @example\n * ```tsx\n * // Using in components\n * import { Link, usePathname } from '@/i18n/navigation';\n *\n * function Nav() {\n * const pathname = usePathname();\n * return <Link href=\"/about\">About</Link>;\n * }\n * ```\n */\n\nimport { createNavigation as createNextIntlNavigation } from 'next-intl/navigation';\nimport { routing, createRouting } from './routing';\nimport type { I18nConfig } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Navigation Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create navigation utilities with custom routing\n *\n * Returns locale-aware versions of:\n * - Link: Locale-prefixed links\n * - redirect: Server-side redirect with locale\n * - usePathname: Current pathname without locale prefix\n * - useRouter: Router with locale-aware navigation\n * - getPathname: Get pathname for a route\n */\nexport function createNavigation(routingConfig?: ReturnType<typeof createRouting>) {\n const config = routingConfig ?? routing;\n return createNextIntlNavigation(config);\n}\n\n/**\n * Create navigation from config options\n */\nexport function createNavigationFromConfig(config: Partial<I18nConfig>) {\n const routingConfig = createRouting(config);\n return createNextIntlNavigation(routingConfig);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Navigation (using default routing)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Default navigation utilities\n * Use these directly or create custom ones with createNavigation()\n */\nexport const {\n Link,\n redirect,\n usePathname,\n useRouter,\n getPathname,\n} = createNavigation();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Props for locale-aware Link component\n */\nexport interface LinkProps {\n /** Target href */\n href: string;\n /** Target locale (optional, defaults to current) */\n locale?: string;\n /** Children */\n children?: React.ReactNode;\n /** Additional props passed to Next.js Link */\n [key: string]: unknown;\n}\n","/**\n * i18n Routing Configuration\n *\n * Creates routing configuration for next-intl\n * Used by proxy and navigation components\n */\n\nimport { defineRouting } from 'next-intl/routing';\nimport type { I18nConfig, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Configuration\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst DEFAULT_LOCALES: LocaleCode[] = ['en', 'ru', 'ko'];\nconst DEFAULT_LOCALE: LocaleCode = 'en';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Routing Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create routing configuration for next-intl\n *\n * @example\n * ```ts\n * // i18n/routing.ts\n * import { createRouting } from '@djangocfg/nextjs/i18n';\n *\n * export const routing = createRouting({\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport function createRouting(config?: Partial<I18nConfig>) {\n const locales = config?.locales ?? DEFAULT_LOCALES;\n const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;\n const localePrefix = config?.localePrefix ?? 'always';\n\n return defineRouting({\n locales,\n defaultLocale,\n localePrefix,\n });\n}\n\n/**\n * Default routing configuration\n * Can be overridden by app-specific configuration\n */\nexport const routing = createRouting();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Utilities\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Check if a locale is supported\n */\nexport function isValidLocale(\n locale: string,\n supportedLocales: readonly string[] = DEFAULT_LOCALES\n): locale is LocaleCode {\n return supportedLocales.includes(locale as LocaleCode);\n}\n\n/**\n * Get locale from params (handles async params in Next.js 15+)\n */\nexport async function getLocaleFromParams(\n params: Promise<{ locale: string }> | { locale: string }\n): Promise<LocaleCode> {\n const resolved = await params;\n return resolved.locale as LocaleCode;\n}\n\n/**\n * Generate static params for all locales\n * Use in generateStaticParams for locale pages\n */\nexport function generateLocaleParams(locales: readonly string[] = DEFAULT_LOCALES) {\n return locales.map((locale) => ({ locale }));\n}\n"],"mappings":";AA0BA,SAAS,oBAAoB,gCAAgC;;;ACnB7D,SAAS,qBAAqB;AAO9B,IAAM,kBAAgC,CAAC,MAAM,MAAM,IAAI;AACvD,IAAM,iBAA6B;AAoB5B,SAAS,cAAc,QAA8B;AAC1D,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,SAAO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAMO,IAAM,UAAU,cAAc;;;ADP9B,SAAS,iBAAiB,eAAkD;AACjF,QAAM,SAAS,iBAAiB;AAChC,SAAO,yBAAyB,MAAM;AACxC;AAKO,SAAS,2BAA2B,QAA6B;AACtE,QAAM,gBAAgB,cAAc,MAAM;AAC1C,SAAO,yBAAyB,aAAa;AAC/C;AAUO,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI,iBAAiB;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export { default as createNextIntlPlugin } from 'next-intl/plugin';
|
|
2
|
+
import { NextConfig } from 'next';
|
|
3
|
+
import { a as I18nPluginOptions } from '../types-Cy349X20.mjs';
|
|
4
|
+
import '@djangocfg/i18n';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* i18n Plugin for Next.js Configuration
|
|
8
|
+
*
|
|
9
|
+
* Wraps next-intl plugin for use with createBaseNextConfig
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // next.config.ts
|
|
14
|
+
* import { createBaseNextConfig } from '@djangocfg/nextjs/config';
|
|
15
|
+
*
|
|
16
|
+
* export default createBaseNextConfig({
|
|
17
|
+
* i18n: {
|
|
18
|
+
* locales: ['en', 'ru', 'ko'],
|
|
19
|
+
* defaultLocale: 'en',
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create next-intl plugin wrapper
|
|
27
|
+
*
|
|
28
|
+
* @param options - i18n configuration options
|
|
29
|
+
* @returns Next.js config wrapper function
|
|
30
|
+
*/
|
|
31
|
+
declare function createI18nPlugin(options?: I18nPluginOptions): (nextConfig?: NextConfig) => NextConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Apply i18n plugin to Next.js config
|
|
34
|
+
*
|
|
35
|
+
* @param config - Base Next.js config
|
|
36
|
+
* @param options - i18n options
|
|
37
|
+
* @returns Modified Next.js config
|
|
38
|
+
*/
|
|
39
|
+
declare function withI18n(config: NextConfig, options?: I18nPluginOptions): NextConfig;
|
|
40
|
+
|
|
41
|
+
export { I18nPluginOptions, createI18nPlugin, withI18n };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/i18n/plugin.ts
|
|
2
|
+
import createNextIntlPlugin from "next-intl/plugin";
|
|
3
|
+
function createI18nPlugin(options) {
|
|
4
|
+
const requestConfigPath = options?.requestConfig ?? "./i18n/request.ts";
|
|
5
|
+
const withNextIntl = createNextIntlPlugin(requestConfigPath);
|
|
6
|
+
return withNextIntl;
|
|
7
|
+
}
|
|
8
|
+
function withI18n(config, options) {
|
|
9
|
+
const plugin = createI18nPlugin(options);
|
|
10
|
+
return plugin(config);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
createI18nPlugin,
|
|
14
|
+
createNextIntlPlugin,
|
|
15
|
+
withI18n
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=plugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/plugin.ts"],"sourcesContent":["/**\n * i18n Plugin for Next.js Configuration\n *\n * Wraps next-intl plugin for use with createBaseNextConfig\n *\n * @example\n * ```ts\n * // next.config.ts\n * import { createBaseNextConfig } from '@djangocfg/nextjs/config';\n *\n * export default createBaseNextConfig({\n * i18n: {\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * },\n * });\n * ```\n */\n\nimport createNextIntlPlugin from 'next-intl/plugin';\nimport type { NextConfig } from 'next';\nimport type { I18nPluginOptions } from './types';\n\nexport type { I18nPluginOptions } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Plugin Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create next-intl plugin wrapper\n *\n * @param options - i18n configuration options\n * @returns Next.js config wrapper function\n */\nexport function createI18nPlugin(options?: I18nPluginOptions) {\n // Determine request config path\n const requestConfigPath = options?.requestConfig\n ?? './i18n/request.ts';\n\n // Create next-intl plugin\n const withNextIntl = createNextIntlPlugin(requestConfigPath);\n\n return withNextIntl;\n}\n\n/**\n * Apply i18n plugin to Next.js config\n *\n * @param config - Base Next.js config\n * @param options - i18n options\n * @returns Modified Next.js config\n */\nexport function withI18n(\n config: NextConfig,\n options?: I18nPluginOptions\n): NextConfig {\n const plugin = createI18nPlugin(options);\n return plugin(config);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Export for direct use\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport { createNextIntlPlugin };\n"],"mappings":";AAmBA,OAAO,0BAA0B;AAgB1B,SAAS,iBAAiB,SAA6B;AAE5D,QAAM,oBAAoB,SAAS,iBAC9B;AAGL,QAAM,eAAe,qBAAqB,iBAAiB;AAE3D,SAAO;AACT;AASO,SAAS,SACd,QACA,SACY;AACZ,QAAM,SAAS,iBAAiB,OAAO;AACvC,SAAO,OAAO,MAAM;AACtB;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { b as I18nProviderProps } from '../types-Cy349X20.mjs';
|
|
3
|
+
import '@djangocfg/i18n';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Unified i18n Provider
|
|
7
|
+
*
|
|
8
|
+
* Wraps both NextIntlClientProvider and @djangocfg/i18n's I18nProvider
|
|
9
|
+
* This ensures both next-intl hooks and @djangocfg/i18n hooks work correctly
|
|
10
|
+
*/
|
|
11
|
+
declare function I18nProvider({ locale, messages, timeZone, now, children, }: I18nProviderProps): react.JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* Next-intl only provider (without @djangocfg/i18n context)
|
|
14
|
+
* Use if you only need next-intl hooks
|
|
15
|
+
*/
|
|
16
|
+
declare function NextIntlProvider({ locale, messages, timeZone, now, children, }: I18nProviderProps): react.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { I18nProvider, NextIntlProvider };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/i18n/provider.tsx
|
|
4
|
+
import { NextIntlClientProvider } from "next-intl";
|
|
5
|
+
import { I18nProvider as DjangoCfgI18nProvider } from "@djangocfg/i18n";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function I18nProvider({
|
|
8
|
+
locale,
|
|
9
|
+
messages,
|
|
10
|
+
timeZone = "UTC",
|
|
11
|
+
now,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
NextIntlClientProvider,
|
|
16
|
+
{
|
|
17
|
+
locale,
|
|
18
|
+
messages,
|
|
19
|
+
timeZone,
|
|
20
|
+
now,
|
|
21
|
+
children: /* @__PURE__ */ jsx(
|
|
22
|
+
DjangoCfgI18nProvider,
|
|
23
|
+
{
|
|
24
|
+
locale,
|
|
25
|
+
translations: messages,
|
|
26
|
+
children
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function NextIntlProvider({
|
|
33
|
+
locale,
|
|
34
|
+
messages,
|
|
35
|
+
timeZone = "UTC",
|
|
36
|
+
now,
|
|
37
|
+
children
|
|
38
|
+
}) {
|
|
39
|
+
return /* @__PURE__ */ jsx(
|
|
40
|
+
NextIntlClientProvider,
|
|
41
|
+
{
|
|
42
|
+
locale,
|
|
43
|
+
messages,
|
|
44
|
+
timeZone,
|
|
45
|
+
now,
|
|
46
|
+
children
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
I18nProvider,
|
|
52
|
+
NextIntlProvider
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=provider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/provider.tsx"],"sourcesContent":["/**\n * i18n Provider for Next.js App Router\n *\n * Bridges next-intl with @djangocfg/i18n\n * Provides translations to both Server and Client components\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * import { I18nProvider } from '@djangocfg/nextjs/i18n';\n * import { getMessages, getLocale } from '@djangocfg/nextjs/i18n/server';\n *\n * export default async function LocaleLayout({ children, params }) {\n * const locale = await getLocale(params);\n * const messages = await getMessages();\n *\n * return (\n * <I18nProvider locale={locale} messages={messages}>\n * {children}\n * </I18nProvider>\n * );\n * }\n * ```\n */\n\n'use client';\n\nimport { NextIntlClientProvider } from 'next-intl';\nimport { I18nProvider as DjangoCfgI18nProvider } from '@djangocfg/i18n';\nimport type { I18nProviderProps, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider Component\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Unified i18n Provider\n *\n * Wraps both NextIntlClientProvider and @djangocfg/i18n's I18nProvider\n * This ensures both next-intl hooks and @djangocfg/i18n hooks work correctly\n */\nexport function I18nProvider({\n locale,\n messages,\n timeZone = 'UTC',\n now,\n children,\n}: I18nProviderProps) {\n return (\n <NextIntlClientProvider\n locale={locale}\n messages={messages}\n timeZone={timeZone}\n now={now}\n >\n <DjangoCfgI18nProvider\n locale={locale as LocaleCode}\n translations={messages}\n >\n {children}\n </DjangoCfgI18nProvider>\n </NextIntlClientProvider>\n );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Lightweight Provider (next-intl only)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Next-intl only provider (without @djangocfg/i18n context)\n * Use if you only need next-intl hooks\n */\nexport function NextIntlProvider({\n locale,\n messages,\n timeZone = 'UTC',\n now,\n children,\n}: I18nProviderProps) {\n return (\n <NextIntlClientProvider\n locale={locale}\n messages={messages}\n timeZone={timeZone}\n now={now}\n >\n {children}\n </NextIntlClientProvider>\n );\n}\n"],"mappings":";;;AA2BA,SAAS,8BAA8B;AACvC,SAAS,gBAAgB,6BAA6B;AA2BhD;AAdC,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAAsB;AACpB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,cAAc;AAAA,UAEb;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAUO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAAsB;AACpB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
import { createRouting } from './routing.mjs';
|
|
4
|
+
import { I as I18nConfig } from '../types-Cy349X20.mjs';
|
|
5
|
+
import 'next-intl/routing';
|
|
6
|
+
import '@djangocfg/i18n';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create i18n proxy handler with custom routing configuration
|
|
10
|
+
*/
|
|
11
|
+
declare function createProxy(routingConfig?: ReturnType<typeof createRouting>): (request: NextRequest) => next_server.NextResponse<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Create i18n proxy from config options
|
|
14
|
+
*/
|
|
15
|
+
declare function createProxyFromConfig(config: Partial<I18nConfig>): (request: NextRequest) => next_server.NextResponse<unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Default proxy function using default routing
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // proxy.ts
|
|
22
|
+
* export { proxy as default, config } from '@djangocfg/nextjs/i18n';
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function proxy(request: NextRequest): next_server.NextResponse<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Default proxy config
|
|
28
|
+
* Matches all paths except static files, API routes, and Next.js internals
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // proxy.ts
|
|
33
|
+
* export { proxy as default, config } from '@djangocfg/nextjs/i18n';
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const config: {
|
|
37
|
+
matcher: string[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { config, createProxy, createProxyFromConfig, proxy };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/i18n/proxy.ts
|
|
2
|
+
import createIntlMiddleware from "next-intl/middleware";
|
|
3
|
+
|
|
4
|
+
// src/i18n/routing.ts
|
|
5
|
+
import { defineRouting } from "next-intl/routing";
|
|
6
|
+
var DEFAULT_LOCALES = ["en", "ru", "ko"];
|
|
7
|
+
var DEFAULT_LOCALE = "en";
|
|
8
|
+
function createRouting(config2) {
|
|
9
|
+
const locales = config2?.locales ?? DEFAULT_LOCALES;
|
|
10
|
+
const defaultLocale = config2?.defaultLocale ?? DEFAULT_LOCALE;
|
|
11
|
+
const localePrefix = config2?.localePrefix ?? "always";
|
|
12
|
+
return defineRouting({
|
|
13
|
+
locales,
|
|
14
|
+
defaultLocale,
|
|
15
|
+
localePrefix
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
var routing = createRouting();
|
|
19
|
+
|
|
20
|
+
// src/i18n/proxy.ts
|
|
21
|
+
function createProxy(routingConfig) {
|
|
22
|
+
const config2 = routingConfig ?? routing;
|
|
23
|
+
return createIntlMiddleware(config2);
|
|
24
|
+
}
|
|
25
|
+
function createProxyFromConfig(config2) {
|
|
26
|
+
const routingConfig = createRouting(config2);
|
|
27
|
+
return createIntlMiddleware(routingConfig);
|
|
28
|
+
}
|
|
29
|
+
var handleI18nRouting = createProxy();
|
|
30
|
+
function proxy(request) {
|
|
31
|
+
return handleI18nRouting(request);
|
|
32
|
+
}
|
|
33
|
+
var config = {
|
|
34
|
+
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"]
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
config,
|
|
38
|
+
createProxy,
|
|
39
|
+
createProxyFromConfig,
|
|
40
|
+
proxy
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=proxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/proxy.ts","../../src/i18n/routing.ts"],"sourcesContent":["/**\n * i18n Proxy for Next.js App Router (Next.js 16+)\n *\n * Handles locale detection and routing\n *\n * @example\n * ```ts\n * // proxy.ts\n * export { proxy as default, config } from '@djangocfg/nextjs/i18n';\n *\n * // Or with custom routing:\n * import { createProxy } from '@djangocfg/nextjs/i18n';\n * import { routing } from './i18n/routing';\n *\n * export default createProxy(routing);\n * export const config = { matcher: [...] };\n * ```\n */\n\nimport createIntlMiddleware from 'next-intl/middleware';\nimport type { NextRequest } from 'next/server';\n\nimport { routing, createRouting } from './routing';\nimport type { I18nConfig } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Proxy Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create i18n proxy handler with custom routing configuration\n */\nexport function createProxy(routingConfig?: ReturnType<typeof createRouting>) {\n const config = routingConfig ?? routing;\n return createIntlMiddleware(config);\n}\n\n/**\n * Create i18n proxy from config options\n */\nexport function createProxyFromConfig(config: Partial<I18nConfig>) {\n const routingConfig = createRouting(config);\n return createIntlMiddleware(routingConfig);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Proxy\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst handleI18nRouting = createProxy();\n\n/**\n * Default proxy function using default routing\n *\n * @example\n * ```ts\n * // proxy.ts\n * export { proxy as default, config } from '@djangocfg/nextjs/i18n';\n * ```\n */\nexport function proxy(request: NextRequest) {\n return handleI18nRouting(request);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Config\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Default proxy config\n * Matches all paths except static files, API routes, and Next.js internals\n *\n * @example\n * ```ts\n * // proxy.ts\n * export { proxy as default, config } from '@djangocfg/nextjs/i18n';\n * ```\n */\nexport const config = {\n matcher: ['/((?!api|_next|_vercel|.*\\\\..*).*)',],\n};\n","/**\n * i18n Routing Configuration\n *\n * Creates routing configuration for next-intl\n * Used by proxy and navigation components\n */\n\nimport { defineRouting } from 'next-intl/routing';\nimport type { I18nConfig, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Configuration\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst DEFAULT_LOCALES: LocaleCode[] = ['en', 'ru', 'ko'];\nconst DEFAULT_LOCALE: LocaleCode = 'en';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Routing Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create routing configuration for next-intl\n *\n * @example\n * ```ts\n * // i18n/routing.ts\n * import { createRouting } from '@djangocfg/nextjs/i18n';\n *\n * export const routing = createRouting({\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport function createRouting(config?: Partial<I18nConfig>) {\n const locales = config?.locales ?? DEFAULT_LOCALES;\n const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;\n const localePrefix = config?.localePrefix ?? 'always';\n\n return defineRouting({\n locales,\n defaultLocale,\n localePrefix,\n });\n}\n\n/**\n * Default routing configuration\n * Can be overridden by app-specific configuration\n */\nexport const routing = createRouting();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Utilities\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Check if a locale is supported\n */\nexport function isValidLocale(\n locale: string,\n supportedLocales: readonly string[] = DEFAULT_LOCALES\n): locale is LocaleCode {\n return supportedLocales.includes(locale as LocaleCode);\n}\n\n/**\n * Get locale from params (handles async params in Next.js 15+)\n */\nexport async function getLocaleFromParams(\n params: Promise<{ locale: string }> | { locale: string }\n): Promise<LocaleCode> {\n const resolved = await params;\n return resolved.locale as LocaleCode;\n}\n\n/**\n * Generate static params for all locales\n * Use in generateStaticParams for locale pages\n */\nexport function generateLocaleParams(locales: readonly string[] = DEFAULT_LOCALES) {\n return locales.map((locale) => ({ locale }));\n}\n"],"mappings":";AAmBA,OAAO,0BAA0B;;;ACZjC,SAAS,qBAAqB;AAO9B,IAAM,kBAAgC,CAAC,MAAM,MAAM,IAAI;AACvD,IAAM,iBAA6B;AAoB5B,SAAS,cAAcA,SAA8B;AAC1D,QAAM,UAAUA,SAAQ,WAAW;AACnC,QAAM,gBAAgBA,SAAQ,iBAAiB;AAC/C,QAAM,eAAeA,SAAQ,gBAAgB;AAE7C,SAAO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAMO,IAAM,UAAU,cAAc;;;ADnB9B,SAAS,YAAY,eAAkD;AAC5E,QAAMC,UAAS,iBAAiB;AAChC,SAAO,qBAAqBA,OAAM;AACpC;AAKO,SAAS,sBAAsBA,SAA6B;AACjE,QAAM,gBAAgB,cAAcA,OAAM;AAC1C,SAAO,qBAAqB,aAAa;AAC3C;AAMA,IAAM,oBAAoB,YAAY;AAW/B,SAAS,MAAM,SAAsB;AAC1C,SAAO,kBAAkB,OAAO;AAClC;AAgBO,IAAM,SAAS;AAAA,EACpB,SAAS,CAAC,oCAAqC;AACjD;","names":["config","config"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as next_intl_server from 'next-intl/server';
|
|
2
|
+
import { LocaleCode, I18nTranslations } from '@djangocfg/i18n';
|
|
3
|
+
import { M as Messages } from '../types-Cy349X20.mjs';
|
|
4
|
+
|
|
5
|
+
interface RequestConfigOptions {
|
|
6
|
+
/** Base locale translations from @djangocfg/i18n */
|
|
7
|
+
locales?: Record<LocaleCode, I18nTranslations>;
|
|
8
|
+
/** Extension i18n instances to merge */
|
|
9
|
+
extensions?: Array<{
|
|
10
|
+
namespace: string;
|
|
11
|
+
locales: Record<string, Record<string, unknown>>;
|
|
12
|
+
}>;
|
|
13
|
+
/** Custom message loader (overrides locales) */
|
|
14
|
+
loadMessages?: (locale: LocaleCode) => Promise<Messages> | Messages;
|
|
15
|
+
/** Time zone for date/time formatting */
|
|
16
|
+
timeZone?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create request configuration for next-intl
|
|
20
|
+
*
|
|
21
|
+
* This is used in your app's `i18n/request.ts` file
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // i18n/request.ts
|
|
26
|
+
* import { createRequestConfig } from '@djangocfg/nextjs/i18n';
|
|
27
|
+
* import { leadsI18n } from '@djangocfg/ext-leads';
|
|
28
|
+
* import { paymentsI18n } from '@djangocfg/ext-payments';
|
|
29
|
+
*
|
|
30
|
+
* export default createRequestConfig({
|
|
31
|
+
* extensions: [leadsI18n, paymentsI18n],
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function createRequestConfig(options?: RequestConfigOptions): (params: next_intl_server.GetRequestConfigParams) => next_intl_server.RequestConfig | Promise<next_intl_server.RequestConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* Default request config with base @djangocfg/i18n translations
|
|
38
|
+
* Can be used directly if no extensions are needed
|
|
39
|
+
*/
|
|
40
|
+
declare const _default: (params: next_intl_server.GetRequestConfigParams) => next_intl_server.RequestConfig | Promise<next_intl_server.RequestConfig>;
|
|
41
|
+
|
|
42
|
+
export { type RequestConfigOptions, createRequestConfig, _default as default };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/i18n/request.ts
|
|
2
|
+
import { getRequestConfig } from "next-intl/server";
|
|
3
|
+
import { mergeTranslations, en, ru, ko } from "@djangocfg/i18n";
|
|
4
|
+
|
|
5
|
+
// src/i18n/routing.ts
|
|
6
|
+
import { defineRouting } from "next-intl/routing";
|
|
7
|
+
var DEFAULT_LOCALES = ["en", "ru", "ko"];
|
|
8
|
+
var DEFAULT_LOCALE = "en";
|
|
9
|
+
function createRouting(config) {
|
|
10
|
+
const locales = config?.locales ?? DEFAULT_LOCALES;
|
|
11
|
+
const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;
|
|
12
|
+
const localePrefix = config?.localePrefix ?? "always";
|
|
13
|
+
return defineRouting({
|
|
14
|
+
locales,
|
|
15
|
+
defaultLocale,
|
|
16
|
+
localePrefix
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
var routing = createRouting();
|
|
20
|
+
|
|
21
|
+
// src/i18n/request.ts
|
|
22
|
+
var DEFAULT_LOCALES2 = {
|
|
23
|
+
en,
|
|
24
|
+
ru,
|
|
25
|
+
ko
|
|
26
|
+
};
|
|
27
|
+
function loadMessages(locale, options) {
|
|
28
|
+
const locales = options.locales ?? DEFAULT_LOCALES2;
|
|
29
|
+
const baseMessages = locales[locale] ?? locales.en ?? en;
|
|
30
|
+
if (!options.extensions?.length) {
|
|
31
|
+
return baseMessages;
|
|
32
|
+
}
|
|
33
|
+
let mergedMessages = { ...baseMessages };
|
|
34
|
+
for (const extension of options.extensions) {
|
|
35
|
+
const extMessages = extension.locales[locale] ?? extension.locales.en;
|
|
36
|
+
if (extMessages) {
|
|
37
|
+
mergedMessages = mergeTranslations(mergedMessages, {
|
|
38
|
+
[extension.namespace]: extMessages
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return mergedMessages;
|
|
43
|
+
}
|
|
44
|
+
function createRequestConfig(options = {}) {
|
|
45
|
+
return getRequestConfig(async ({ requestLocale }) => {
|
|
46
|
+
let locale = await requestLocale;
|
|
47
|
+
if (!locale || !routing.locales.includes(locale)) {
|
|
48
|
+
locale = routing.defaultLocale;
|
|
49
|
+
}
|
|
50
|
+
const messages = options.loadMessages ? await options.loadMessages(locale) : loadMessages(locale, options);
|
|
51
|
+
return {
|
|
52
|
+
locale,
|
|
53
|
+
messages,
|
|
54
|
+
timeZone: options.timeZone ?? "UTC"
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
var request_default = createRequestConfig();
|
|
59
|
+
export {
|
|
60
|
+
createRequestConfig,
|
|
61
|
+
request_default as default
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/request.ts","../../src/i18n/routing.ts"],"sourcesContent":["/**\n * i18n Request Configuration for Server Components\n *\n * Provides translations to server components via next-intl's request scope\n *\n * @example\n * ```ts\n * // i18n/request.ts in your app\n * import { createRequestConfig } from '@djangocfg/nextjs/i18n';\n * import { en, ru, ko } from '@djangocfg/i18n';\n * import { leadsI18n } from '@djangocfg/ext-leads';\n *\n * export default createRequestConfig({\n * locales: { en, ru, ko },\n * extensions: [leadsI18n],\n * });\n * ```\n */\n\nimport { getRequestConfig } from 'next-intl/server';\nimport { mergeTranslations, en, ru, ko } from '@djangocfg/i18n';\nimport type { I18nTranslations, LocaleCode } from '@djangocfg/i18n';\nimport type { Messages } from './types';\nimport { routing } from './routing';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface RequestConfigOptions {\n /** Base locale translations from @djangocfg/i18n */\n locales?: Record<LocaleCode, I18nTranslations>;\n /** Extension i18n instances to merge */\n extensions?: Array<{\n namespace: string;\n locales: Record<string, Record<string, unknown>>;\n }>;\n /** Custom message loader (overrides locales) */\n loadMessages?: (locale: LocaleCode) => Promise<Messages> | Messages;\n /** Time zone for date/time formatting */\n timeZone?: string;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Locales\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst DEFAULT_LOCALES: Record<LocaleCode, I18nTranslations> = {\n en,\n ru,\n ko,\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Message Loading\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Load and merge messages for a locale\n */\nfunction loadMessages(\n locale: LocaleCode,\n options: RequestConfigOptions\n): Messages {\n // Get base translations\n const locales = options.locales ?? DEFAULT_LOCALES;\n const baseMessages = locales[locale] ?? locales.en ?? en;\n\n // If no extensions, return base\n if (!options.extensions?.length) {\n return baseMessages as Messages;\n }\n\n // Merge extension translations\n let mergedMessages = { ...baseMessages } as Messages;\n\n for (const extension of options.extensions) {\n const extMessages = extension.locales[locale] ?? extension.locales.en;\n if (extMessages) {\n mergedMessages = mergeTranslations(mergedMessages, {\n [extension.namespace]: extMessages,\n }) as Messages;\n }\n }\n\n return mergedMessages;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Request Config Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create request configuration for next-intl\n *\n * This is used in your app's `i18n/request.ts` file\n *\n * @example\n * ```ts\n * // i18n/request.ts\n * import { createRequestConfig } from '@djangocfg/nextjs/i18n';\n * import { leadsI18n } from '@djangocfg/ext-leads';\n * import { paymentsI18n } from '@djangocfg/ext-payments';\n *\n * export default createRequestConfig({\n * extensions: [leadsI18n, paymentsI18n],\n * });\n * ```\n */\nexport function createRequestConfig(options: RequestConfigOptions = {}) {\n return getRequestConfig(async ({ requestLocale }) => {\n // Get locale from request or default\n let locale = await requestLocale;\n\n // Validate and fallback to default\n if (!locale || !routing.locales.includes(locale as LocaleCode)) {\n locale = routing.defaultLocale;\n }\n\n // Load messages\n const messages = options.loadMessages\n ? await options.loadMessages(locale as LocaleCode)\n : loadMessages(locale as LocaleCode, options);\n\n return {\n locale,\n messages,\n timeZone: options.timeZone ?? 'UTC',\n };\n });\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Export\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Default request config with base @djangocfg/i18n translations\n * Can be used directly if no extensions are needed\n */\nexport default createRequestConfig();\n","/**\n * i18n Routing Configuration\n *\n * Creates routing configuration for next-intl\n * Used by proxy and navigation components\n */\n\nimport { defineRouting } from 'next-intl/routing';\nimport type { I18nConfig, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Configuration\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst DEFAULT_LOCALES: LocaleCode[] = ['en', 'ru', 'ko'];\nconst DEFAULT_LOCALE: LocaleCode = 'en';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Routing Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create routing configuration for next-intl\n *\n * @example\n * ```ts\n * // i18n/routing.ts\n * import { createRouting } from '@djangocfg/nextjs/i18n';\n *\n * export const routing = createRouting({\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport function createRouting(config?: Partial<I18nConfig>) {\n const locales = config?.locales ?? DEFAULT_LOCALES;\n const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;\n const localePrefix = config?.localePrefix ?? 'always';\n\n return defineRouting({\n locales,\n defaultLocale,\n localePrefix,\n });\n}\n\n/**\n * Default routing configuration\n * Can be overridden by app-specific configuration\n */\nexport const routing = createRouting();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Utilities\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Check if a locale is supported\n */\nexport function isValidLocale(\n locale: string,\n supportedLocales: readonly string[] = DEFAULT_LOCALES\n): locale is LocaleCode {\n return supportedLocales.includes(locale as LocaleCode);\n}\n\n/**\n * Get locale from params (handles async params in Next.js 15+)\n */\nexport async function getLocaleFromParams(\n params: Promise<{ locale: string }> | { locale: string }\n): Promise<LocaleCode> {\n const resolved = await params;\n return resolved.locale as LocaleCode;\n}\n\n/**\n * Generate static params for all locales\n * Use in generateStaticParams for locale pages\n */\nexport function generateLocaleParams(locales: readonly string[] = DEFAULT_LOCALES) {\n return locales.map((locale) => ({ locale }));\n}\n"],"mappings":";AAmBA,SAAS,wBAAwB;AACjC,SAAS,mBAAmB,IAAI,IAAI,UAAU;;;ACb9C,SAAS,qBAAqB;AAO9B,IAAM,kBAAgC,CAAC,MAAM,MAAM,IAAI;AACvD,IAAM,iBAA6B;AAoB5B,SAAS,cAAc,QAA8B;AAC1D,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,SAAO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAMO,IAAM,UAAU,cAAc;;;ADJrC,IAAMA,mBAAwD;AAAA,EAC5D;AAAA,EACA;AAAA,EACA;AACF;AASA,SAAS,aACP,QACA,SACU;AAEV,QAAM,UAAU,QAAQ,WAAWA;AACnC,QAAM,eAAe,QAAQ,MAAM,KAAK,QAAQ,MAAM;AAGtD,MAAI,CAAC,QAAQ,YAAY,QAAQ;AAC/B,WAAO;AAAA,EACT;AAGA,MAAI,iBAAiB,EAAE,GAAG,aAAa;AAEvC,aAAW,aAAa,QAAQ,YAAY;AAC1C,UAAM,cAAc,UAAU,QAAQ,MAAM,KAAK,UAAU,QAAQ;AACnE,QAAI,aAAa;AACf,uBAAiB,kBAAkB,gBAAgB;AAAA,QACjD,CAAC,UAAU,SAAS,GAAG;AAAA,MACzB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAuBO,SAAS,oBAAoB,UAAgC,CAAC,GAAG;AACtE,SAAO,iBAAiB,OAAO,EAAE,cAAc,MAAM;AAEnD,QAAI,SAAS,MAAM;AAGnB,QAAI,CAAC,UAAU,CAAC,QAAQ,QAAQ,SAAS,MAAoB,GAAG;AAC9D,eAAS,QAAQ;AAAA,IACnB;AAGA,UAAM,WAAW,QAAQ,eACrB,MAAM,QAAQ,aAAa,MAAoB,IAC/C,aAAa,QAAsB,OAAO;AAE9C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,UAAU,QAAQ,YAAY;AAAA,IAChC;AAAA,EACF,CAAC;AACH;AAUA,IAAO,kBAAQ,oBAAoB;","names":["DEFAULT_LOCALES"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as next_intl_routing from 'next-intl/routing';
|
|
2
|
+
import { I as I18nConfig } from '../types-Cy349X20.mjs';
|
|
3
|
+
import { LocaleCode } from '@djangocfg/i18n';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create routing configuration for next-intl
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // i18n/routing.ts
|
|
11
|
+
* import { createRouting } from '@djangocfg/nextjs/i18n';
|
|
12
|
+
*
|
|
13
|
+
* export const routing = createRouting({
|
|
14
|
+
* locales: ['en', 'ru', 'ko'],
|
|
15
|
+
* defaultLocale: 'en',
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function createRouting(config?: Partial<I18nConfig>): {
|
|
20
|
+
locales: string[];
|
|
21
|
+
defaultLocale: string;
|
|
22
|
+
localePrefix?: next_intl_routing.LocalePrefix<string[], "always" | "as-needed" | "never">;
|
|
23
|
+
domains?: never;
|
|
24
|
+
localeCookie?: boolean | {
|
|
25
|
+
name?: string;
|
|
26
|
+
maxAge?: number | undefined;
|
|
27
|
+
priority?: "low" | "medium" | "high" | undefined;
|
|
28
|
+
domain?: string | undefined;
|
|
29
|
+
path?: string | undefined;
|
|
30
|
+
secure?: boolean | undefined;
|
|
31
|
+
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
32
|
+
partitioned?: boolean | undefined;
|
|
33
|
+
};
|
|
34
|
+
alternateLinks?: boolean;
|
|
35
|
+
localeDetection?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Default routing configuration
|
|
39
|
+
* Can be overridden by app-specific configuration
|
|
40
|
+
*/
|
|
41
|
+
declare const routing: {
|
|
42
|
+
locales: string[];
|
|
43
|
+
defaultLocale: string;
|
|
44
|
+
localePrefix?: next_intl_routing.LocalePrefix<string[], "always" | "as-needed" | "never">;
|
|
45
|
+
domains?: never;
|
|
46
|
+
localeCookie?: boolean | {
|
|
47
|
+
name?: string;
|
|
48
|
+
maxAge?: number | undefined;
|
|
49
|
+
priority?: "low" | "medium" | "high" | undefined;
|
|
50
|
+
domain?: string | undefined;
|
|
51
|
+
path?: string | undefined;
|
|
52
|
+
secure?: boolean | undefined;
|
|
53
|
+
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
54
|
+
partitioned?: boolean | undefined;
|
|
55
|
+
};
|
|
56
|
+
alternateLinks?: boolean;
|
|
57
|
+
localeDetection?: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Check if a locale is supported
|
|
61
|
+
*/
|
|
62
|
+
declare function isValidLocale(locale: string, supportedLocales?: readonly string[]): locale is LocaleCode;
|
|
63
|
+
/**
|
|
64
|
+
* Get locale from params (handles async params in Next.js 15+)
|
|
65
|
+
*/
|
|
66
|
+
declare function getLocaleFromParams(params: Promise<{
|
|
67
|
+
locale: string;
|
|
68
|
+
}> | {
|
|
69
|
+
locale: string;
|
|
70
|
+
}): Promise<LocaleCode>;
|
|
71
|
+
/**
|
|
72
|
+
* Generate static params for all locales
|
|
73
|
+
* Use in generateStaticParams for locale pages
|
|
74
|
+
*/
|
|
75
|
+
declare function generateLocaleParams(locales?: readonly string[]): {
|
|
76
|
+
locale: string;
|
|
77
|
+
}[];
|
|
78
|
+
|
|
79
|
+
export { createRouting, generateLocaleParams, getLocaleFromParams, isValidLocale, routing };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/i18n/routing.ts
|
|
2
|
+
import { defineRouting } from "next-intl/routing";
|
|
3
|
+
var DEFAULT_LOCALES = ["en", "ru", "ko"];
|
|
4
|
+
var DEFAULT_LOCALE = "en";
|
|
5
|
+
function createRouting(config) {
|
|
6
|
+
const locales = config?.locales ?? DEFAULT_LOCALES;
|
|
7
|
+
const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;
|
|
8
|
+
const localePrefix = config?.localePrefix ?? "always";
|
|
9
|
+
return defineRouting({
|
|
10
|
+
locales,
|
|
11
|
+
defaultLocale,
|
|
12
|
+
localePrefix
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
var routing = createRouting();
|
|
16
|
+
function isValidLocale(locale, supportedLocales = DEFAULT_LOCALES) {
|
|
17
|
+
return supportedLocales.includes(locale);
|
|
18
|
+
}
|
|
19
|
+
async function getLocaleFromParams(params) {
|
|
20
|
+
const resolved = await params;
|
|
21
|
+
return resolved.locale;
|
|
22
|
+
}
|
|
23
|
+
function generateLocaleParams(locales = DEFAULT_LOCALES) {
|
|
24
|
+
return locales.map((locale) => ({ locale }));
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
createRouting,
|
|
28
|
+
generateLocaleParams,
|
|
29
|
+
getLocaleFromParams,
|
|
30
|
+
isValidLocale,
|
|
31
|
+
routing
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=routing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/routing.ts"],"sourcesContent":["/**\n * i18n Routing Configuration\n *\n * Creates routing configuration for next-intl\n * Used by proxy and navigation components\n */\n\nimport { defineRouting } from 'next-intl/routing';\nimport type { I18nConfig, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Configuration\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst DEFAULT_LOCALES: LocaleCode[] = ['en', 'ru', 'ko'];\nconst DEFAULT_LOCALE: LocaleCode = 'en';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Routing Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create routing configuration for next-intl\n *\n * @example\n * ```ts\n * // i18n/routing.ts\n * import { createRouting } from '@djangocfg/nextjs/i18n';\n *\n * export const routing = createRouting({\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport function createRouting(config?: Partial<I18nConfig>) {\n const locales = config?.locales ?? DEFAULT_LOCALES;\n const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;\n const localePrefix = config?.localePrefix ?? 'always';\n\n return defineRouting({\n locales,\n defaultLocale,\n localePrefix,\n });\n}\n\n/**\n * Default routing configuration\n * Can be overridden by app-specific configuration\n */\nexport const routing = createRouting();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Utilities\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Check if a locale is supported\n */\nexport function isValidLocale(\n locale: string,\n supportedLocales: readonly string[] = DEFAULT_LOCALES\n): locale is LocaleCode {\n return supportedLocales.includes(locale as LocaleCode);\n}\n\n/**\n * Get locale from params (handles async params in Next.js 15+)\n */\nexport async function getLocaleFromParams(\n params: Promise<{ locale: string }> | { locale: string }\n): Promise<LocaleCode> {\n const resolved = await params;\n return resolved.locale as LocaleCode;\n}\n\n/**\n * Generate static params for all locales\n * Use in generateStaticParams for locale pages\n */\nexport function generateLocaleParams(locales: readonly string[] = DEFAULT_LOCALES) {\n return locales.map((locale) => ({ locale }));\n}\n"],"mappings":";AAOA,SAAS,qBAAqB;AAO9B,IAAM,kBAAgC,CAAC,MAAM,MAAM,IAAI;AACvD,IAAM,iBAA6B;AAoB5B,SAAS,cAAc,QAA8B;AAC1D,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,SAAO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAMO,IAAM,UAAU,cAAc;AAS9B,SAAS,cACd,QACA,mBAAsC,iBAChB;AACtB,SAAO,iBAAiB,SAAS,MAAoB;AACvD;AAKA,eAAsB,oBACpB,QACqB;AACrB,QAAM,WAAW,MAAM;AACvB,SAAO,SAAS;AAClB;AAMO,SAAS,qBAAqB,UAA6B,iBAAiB;AACjF,SAAO,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;AAC7C;","names":[]}
|