@djangocfg/nextjs 2.1.110 → 2.1.112
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 +208 -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 +11 -0
- package/dist/i18n/components.mjs +90 -0
- package/dist/i18n/components.mjs.map +1 -0
- package/dist/i18n/index.d.mts +18 -0
- package/dist/i18n/index.mjs +226 -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 +60 -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,123 @@
|
|
|
1
|
+
import * as next_intl from 'next-intl';
|
|
2
|
+
export { useFormatter, useMessages, useNow, useTimeZone } from 'next-intl';
|
|
3
|
+
import { LocaleCode } from '@djangocfg/i18n';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get translations in Client Components
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const t = useTranslations('HomePage');
|
|
11
|
+
* return <h1>{t('title')}</h1>;
|
|
12
|
+
*
|
|
13
|
+
* // With interpolation
|
|
14
|
+
* return <p>{t('greeting', { name: 'John' })}</p>;
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function useTranslations<Namespace extends string = never>(namespace?: Namespace): next_intl._Translator<Record<string, any>, Namespace>;
|
|
18
|
+
/**
|
|
19
|
+
* Get current locale in Client Components
|
|
20
|
+
*/
|
|
21
|
+
declare function useLocale(): LocaleCode;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shorthand for useTranslations
|
|
25
|
+
* Alias for compatibility with @djangocfg/i18n
|
|
26
|
+
*/
|
|
27
|
+
declare const useT: typeof useTranslations;
|
|
28
|
+
/**
|
|
29
|
+
* Get namespaced translations
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const pt = useNamespacedTranslations('payments');
|
|
34
|
+
* return <span>{pt('balance.available')}</span>;
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function useNamespacedTranslations(namespace: string): next_intl._Translator<Record<string, any>, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Format a date according to locale
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const formatDate = useDateFormatter();
|
|
44
|
+
* return <span>{formatDate(new Date())}</span>;
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function useDateFormatter(): (date: Date | number, options?: Parameters<{
|
|
48
|
+
(value: Date | number, options?: next_intl.DateTimeFormatOptions): string;
|
|
49
|
+
(value: Date | number, format?: string, options?: next_intl.DateTimeFormatOptions): string;
|
|
50
|
+
}>[1]) => string;
|
|
51
|
+
/**
|
|
52
|
+
* Format a number according to locale
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* const formatNumber = useNumberFormatter();
|
|
57
|
+
* return <span>{formatNumber(1234.56)}</span>;
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function useNumberFormatter(): (number: number, options?: Parameters<{
|
|
61
|
+
(value: number | bigint, options?: next_intl.NumberFormatOptions): string;
|
|
62
|
+
(value: number | bigint, format?: string, options?: next_intl.NumberFormatOptions): string;
|
|
63
|
+
}>[1]) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Format relative time
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const formatRelative = useRelativeTimeFormatter();
|
|
70
|
+
* return <span>{formatRelative(new Date())}</span>;
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function useRelativeTimeFormatter(): (date: Date | number, options?: Parameters<{
|
|
74
|
+
(date: number | Date, now?: next_intl.RelativeTimeFormatOptions["now"]): string;
|
|
75
|
+
(date: number | Date, options?: next_intl.RelativeTimeFormatOptions): string;
|
|
76
|
+
}>[1]) => string;
|
|
77
|
+
/**
|
|
78
|
+
* Get list of available locales from routing config
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* const locales = useLocales();
|
|
83
|
+
* // ['en', 'ru', 'ko']
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function useLocales(): LocaleCode[];
|
|
87
|
+
/**
|
|
88
|
+
* Get default locale from routing config
|
|
89
|
+
*/
|
|
90
|
+
declare function useDefaultLocale(): LocaleCode;
|
|
91
|
+
/**
|
|
92
|
+
* Hook to change current locale
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* const changeLocale = useChangeLocale();
|
|
97
|
+
*
|
|
98
|
+
* <button onClick={() => changeLocale('ru')}>
|
|
99
|
+
* Switch to Russian
|
|
100
|
+
* </button>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare function useChangeLocale(): (locale: LocaleCode) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Combined hook for locale switching
|
|
106
|
+
* Returns current locale, available locales, and change function
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* const { locale, locales, changeLocale } = useLocaleSwitcher();
|
|
111
|
+
*
|
|
112
|
+
* <select value={locale} onChange={(e) => changeLocale(e.target.value)}>
|
|
113
|
+
* {locales.map(l => <option key={l} value={l}>{l}</option>)}
|
|
114
|
+
* </select>
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function useLocaleSwitcher(): {
|
|
118
|
+
locale: string;
|
|
119
|
+
locales: string[];
|
|
120
|
+
changeLocale: (locale: LocaleCode) => void;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { useChangeLocale, useDateFormatter, useDefaultLocale, useLocale, useLocaleSwitcher, useLocales, useNamespacedTranslations, useNumberFormatter, useRelativeTimeFormatter, useT, useTranslations };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/i18n/client.ts
|
|
4
|
+
import {
|
|
5
|
+
useTranslations as useNextIntlTranslations,
|
|
6
|
+
useLocale as useNextIntlLocale,
|
|
7
|
+
useMessages,
|
|
8
|
+
useNow,
|
|
9
|
+
useTimeZone,
|
|
10
|
+
useFormatter
|
|
11
|
+
} from "next-intl";
|
|
12
|
+
|
|
13
|
+
// src/i18n/navigation.ts
|
|
14
|
+
import { createNavigation as createNextIntlNavigation } from "next-intl/navigation";
|
|
15
|
+
|
|
16
|
+
// src/i18n/routing.ts
|
|
17
|
+
import { defineRouting } from "next-intl/routing";
|
|
18
|
+
var DEFAULT_LOCALES = ["en", "ru", "ko"];
|
|
19
|
+
var DEFAULT_LOCALE = "en";
|
|
20
|
+
function createRouting(config) {
|
|
21
|
+
const locales = config?.locales ?? DEFAULT_LOCALES;
|
|
22
|
+
const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;
|
|
23
|
+
const localePrefix = config?.localePrefix ?? "as-needed";
|
|
24
|
+
return defineRouting({
|
|
25
|
+
locales,
|
|
26
|
+
defaultLocale,
|
|
27
|
+
localePrefix
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
var routing = createRouting();
|
|
31
|
+
|
|
32
|
+
// src/i18n/navigation.ts
|
|
33
|
+
function createNavigation(routingConfig) {
|
|
34
|
+
const config = routingConfig ?? routing;
|
|
35
|
+
return createNextIntlNavigation(config);
|
|
36
|
+
}
|
|
37
|
+
var {
|
|
38
|
+
Link,
|
|
39
|
+
redirect,
|
|
40
|
+
usePathname,
|
|
41
|
+
useRouter,
|
|
42
|
+
getPathname
|
|
43
|
+
} = createNavigation();
|
|
44
|
+
|
|
45
|
+
// src/i18n/client.ts
|
|
46
|
+
function useTranslations(namespace) {
|
|
47
|
+
return useNextIntlTranslations(namespace);
|
|
48
|
+
}
|
|
49
|
+
function useLocale() {
|
|
50
|
+
return useNextIntlLocale();
|
|
51
|
+
}
|
|
52
|
+
var useT = useTranslations;
|
|
53
|
+
function useNamespacedTranslations(namespace) {
|
|
54
|
+
return useNextIntlTranslations(namespace);
|
|
55
|
+
}
|
|
56
|
+
function useDateFormatter() {
|
|
57
|
+
const formatter = useFormatter();
|
|
58
|
+
return (date, options) => formatter.dateTime(date, options);
|
|
59
|
+
}
|
|
60
|
+
function useNumberFormatter() {
|
|
61
|
+
const formatter = useFormatter();
|
|
62
|
+
return (number, options) => formatter.number(number, options);
|
|
63
|
+
}
|
|
64
|
+
function useRelativeTimeFormatter() {
|
|
65
|
+
const formatter = useFormatter();
|
|
66
|
+
return (date, options) => formatter.relativeTime(date, options);
|
|
67
|
+
}
|
|
68
|
+
function useLocales() {
|
|
69
|
+
return routing.locales;
|
|
70
|
+
}
|
|
71
|
+
function useDefaultLocale() {
|
|
72
|
+
return routing.defaultLocale;
|
|
73
|
+
}
|
|
74
|
+
function useChangeLocale() {
|
|
75
|
+
const router = useRouter();
|
|
76
|
+
const pathname = usePathname();
|
|
77
|
+
return (locale) => {
|
|
78
|
+
router.replace(pathname, { locale });
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function useLocaleSwitcher() {
|
|
82
|
+
const locale = useLocale();
|
|
83
|
+
const locales = useLocales();
|
|
84
|
+
const changeLocale = useChangeLocale();
|
|
85
|
+
return { locale, locales, changeLocale };
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
useChangeLocale,
|
|
89
|
+
useDateFormatter,
|
|
90
|
+
useDefaultLocale,
|
|
91
|
+
useFormatter,
|
|
92
|
+
useLocale,
|
|
93
|
+
useLocaleSwitcher,
|
|
94
|
+
useLocales,
|
|
95
|
+
useMessages,
|
|
96
|
+
useNamespacedTranslations,
|
|
97
|
+
useNow,
|
|
98
|
+
useNumberFormatter,
|
|
99
|
+
useRelativeTimeFormatter,
|
|
100
|
+
useT,
|
|
101
|
+
useTimeZone,
|
|
102
|
+
useTranslations
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/client.ts","../../src/i18n/navigation.ts","../../src/i18n/routing.ts"],"sourcesContent":["/**\n * Client-side i18n Hooks\n *\n * For use in Client Components ('use client')\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useTranslations, useLocale } from '@djangocfg/nextjs/i18n/client';\n *\n * export function MyComponent() {\n * const t = useTranslations('HomePage');\n * const locale = useLocale();\n *\n * return <h1>{t('title')}</h1>;\n * }\n * ```\n */\n\n'use client';\n\nimport {\n useTranslations as useNextIntlTranslations,\n useLocale as useNextIntlLocale,\n useMessages,\n useNow,\n useTimeZone,\n useFormatter,\n} from 'next-intl';\nimport { useRouter, usePathname } from './navigation';\nimport { routing } from './routing';\nimport type { LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Core Client Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Get translations in Client Components\n *\n * @example\n * ```tsx\n * const t = useTranslations('HomePage');\n * return <h1>{t('title')}</h1>;\n *\n * // With interpolation\n * return <p>{t('greeting', { name: 'John' })}</p>;\n * ```\n */\nexport function useTranslations<Namespace extends string = never>(\n namespace?: Namespace\n) {\n return useNextIntlTranslations(namespace);\n}\n\n/**\n * Get current locale in Client Components\n */\nexport function useLocale(): LocaleCode {\n return useNextIntlLocale() as LocaleCode;\n}\n\n/**\n * Get all messages\n * Useful for passing to child providers\n */\nexport { useMessages };\n\n/**\n * Get current time\n */\nexport { useNow };\n\n/**\n * Get timezone\n */\nexport { useTimeZone };\n\n/**\n * Get formatter for dates, numbers, etc.\n */\nexport { useFormatter };\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Convenience Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Shorthand for useTranslations\n * Alias for compatibility with @djangocfg/i18n\n */\nexport const useT = useTranslations;\n\n/**\n * Get namespaced translations\n *\n * @example\n * ```tsx\n * const pt = useNamespacedTranslations('payments');\n * return <span>{pt('balance.available')}</span>;\n * ```\n */\nexport function useNamespacedTranslations(namespace: string) {\n return useNextIntlTranslations(namespace);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Formatting Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Format a date according to locale\n *\n * @example\n * ```tsx\n * const formatDate = useDateFormatter();\n * return <span>{formatDate(new Date())}</span>;\n * ```\n */\nexport function useDateFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.dateTime>[1]) =>\n formatter.dateTime(date, options);\n}\n\n/**\n * Format a number according to locale\n *\n * @example\n * ```tsx\n * const formatNumber = useNumberFormatter();\n * return <span>{formatNumber(1234.56)}</span>;\n * ```\n */\nexport function useNumberFormatter() {\n const formatter = useFormatter();\n return (number: number, options?: Parameters<typeof formatter.number>[1]) =>\n formatter.number(number, options);\n}\n\n/**\n * Format relative time\n *\n * @example\n * ```tsx\n * const formatRelative = useRelativeTimeFormatter();\n * return <span>{formatRelative(new Date())}</span>;\n * ```\n */\nexport function useRelativeTimeFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.relativeTime>[1]) =>\n formatter.relativeTime(date, options);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Switching Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Get list of available locales from routing config\n *\n * @example\n * ```tsx\n * const locales = useLocales();\n * // ['en', 'ru', 'ko']\n * ```\n */\nexport function useLocales(): LocaleCode[] {\n return routing.locales as LocaleCode[];\n}\n\n/**\n * Get default locale from routing config\n */\nexport function useDefaultLocale(): LocaleCode {\n return routing.defaultLocale as LocaleCode;\n}\n\n/**\n * Hook to change current locale\n *\n * @example\n * ```tsx\n * const changeLocale = useChangeLocale();\n *\n * <button onClick={() => changeLocale('ru')}>\n * Switch to Russian\n * </button>\n * ```\n */\nexport function useChangeLocale() {\n const router = useRouter();\n const pathname = usePathname();\n\n return (locale: LocaleCode) => {\n router.replace(pathname, { locale });\n };\n}\n\n/**\n * Combined hook for locale switching\n * Returns current locale, available locales, and change function\n *\n * @example\n * ```tsx\n * const { locale, locales, changeLocale } = useLocaleSwitcher();\n *\n * <select value={locale} onChange={(e) => changeLocale(e.target.value)}>\n * {locales.map(l => <option key={l} value={l}>{l}</option>)}\n * </select>\n * ```\n */\nexport function useLocaleSwitcher() {\n const locale = useLocale();\n const locales = useLocales();\n const changeLocale = useChangeLocale();\n\n return { locale, locales, changeLocale };\n}\n","/**\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 ?? 'as-needed';\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":";;;AAsBA;AAAA,EACE,mBAAmB;AAAA,EACnB,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACHP,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;AAkBO,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI,iBAAiB;;;ADrBd,SAAS,gBACd,WACA;AACA,SAAO,wBAAwB,SAAS;AAC1C;AAKO,SAAS,YAAwB;AACtC,SAAO,kBAAkB;AAC3B;AA+BO,IAAM,OAAO;AAWb,SAAS,0BAA0B,WAAmB;AAC3D,SAAO,wBAAwB,SAAS;AAC1C;AAeO,SAAS,mBAAmB;AACjC,QAAM,YAAY,aAAa;AAC/B,SAAO,CAAC,MAAqB,YAC3B,UAAU,SAAS,MAAM,OAAO;AACpC;AAWO,SAAS,qBAAqB;AACnC,QAAM,YAAY,aAAa;AAC/B,SAAO,CAAC,QAAgB,YACtB,UAAU,OAAO,QAAQ,OAAO;AACpC;AAWO,SAAS,2BAA2B;AACzC,QAAM,YAAY,aAAa;AAC/B,SAAO,CAAC,MAAqB,YAC3B,UAAU,aAAa,MAAM,OAAO;AACxC;AAeO,SAAS,aAA2B;AACzC,SAAO,QAAQ;AACjB;AAKO,SAAS,mBAA+B;AAC7C,SAAO,QAAQ;AACjB;AAcO,SAAS,kBAAkB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAE7B,SAAO,CAAC,WAAuB;AAC7B,WAAO,QAAQ,UAAU,EAAE,OAAO,CAAC;AAAA,EACrC;AACF;AAeO,SAAS,oBAAoB;AAClC,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,WAAW;AAC3B,QAAM,eAAe,gBAAgB;AAErC,SAAO,EAAE,QAAQ,SAAS,aAAa;AACzC;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { LocaleSwitcherProps as LocaleSwitcherProps$1 } from '@djangocfg/layouts';
|
|
3
|
+
import { LocaleCode } from '@djangocfg/i18n';
|
|
4
|
+
|
|
5
|
+
interface LocaleSwitcherProps extends Omit<LocaleSwitcherProps$1, 'locale' | 'locales' | 'onChange'> {
|
|
6
|
+
/** Available locales (defaults to all from routing config) */
|
|
7
|
+
locales?: LocaleCode[];
|
|
8
|
+
}
|
|
9
|
+
declare function LocaleSwitcher({ locales: customLocales, ...props }: LocaleSwitcherProps): react.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { LocaleSwitcher, type LocaleSwitcherProps };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/i18n/components/LocaleSwitcher.tsx
|
|
2
|
+
import {
|
|
3
|
+
LocaleSwitcher as BaseLocaleSwitcher
|
|
4
|
+
} from "@djangocfg/layouts";
|
|
5
|
+
|
|
6
|
+
// src/i18n/client.ts
|
|
7
|
+
import {
|
|
8
|
+
useTranslations as useNextIntlTranslations,
|
|
9
|
+
useLocale as useNextIntlLocale,
|
|
10
|
+
useMessages,
|
|
11
|
+
useNow,
|
|
12
|
+
useTimeZone,
|
|
13
|
+
useFormatter
|
|
14
|
+
} from "next-intl";
|
|
15
|
+
|
|
16
|
+
// src/i18n/navigation.ts
|
|
17
|
+
import { createNavigation as createNextIntlNavigation } from "next-intl/navigation";
|
|
18
|
+
|
|
19
|
+
// src/i18n/routing.ts
|
|
20
|
+
import { defineRouting } from "next-intl/routing";
|
|
21
|
+
var DEFAULT_LOCALES = ["en", "ru", "ko"];
|
|
22
|
+
var DEFAULT_LOCALE = "en";
|
|
23
|
+
function createRouting(config) {
|
|
24
|
+
const locales = config?.locales ?? DEFAULT_LOCALES;
|
|
25
|
+
const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;
|
|
26
|
+
const localePrefix = config?.localePrefix ?? "as-needed";
|
|
27
|
+
return defineRouting({
|
|
28
|
+
locales,
|
|
29
|
+
defaultLocale,
|
|
30
|
+
localePrefix
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
var routing = createRouting();
|
|
34
|
+
|
|
35
|
+
// src/i18n/navigation.ts
|
|
36
|
+
function createNavigation(routingConfig) {
|
|
37
|
+
const config = routingConfig ?? routing;
|
|
38
|
+
return createNextIntlNavigation(config);
|
|
39
|
+
}
|
|
40
|
+
var {
|
|
41
|
+
Link,
|
|
42
|
+
redirect,
|
|
43
|
+
usePathname,
|
|
44
|
+
useRouter,
|
|
45
|
+
getPathname
|
|
46
|
+
} = createNavigation();
|
|
47
|
+
|
|
48
|
+
// src/i18n/client.ts
|
|
49
|
+
function useLocale() {
|
|
50
|
+
return useNextIntlLocale();
|
|
51
|
+
}
|
|
52
|
+
function useLocales() {
|
|
53
|
+
return routing.locales;
|
|
54
|
+
}
|
|
55
|
+
function useChangeLocale() {
|
|
56
|
+
const router = useRouter();
|
|
57
|
+
const pathname = usePathname();
|
|
58
|
+
return (locale) => {
|
|
59
|
+
router.replace(pathname, { locale });
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function useLocaleSwitcher() {
|
|
63
|
+
const locale = useLocale();
|
|
64
|
+
const locales = useLocales();
|
|
65
|
+
const changeLocale = useChangeLocale();
|
|
66
|
+
return { locale, locales, changeLocale };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/i18n/components/LocaleSwitcher.tsx
|
|
70
|
+
import { jsx } from "react/jsx-runtime";
|
|
71
|
+
function LocaleSwitcher({
|
|
72
|
+
locales: customLocales,
|
|
73
|
+
...props
|
|
74
|
+
}) {
|
|
75
|
+
const { locale, locales: routingLocales, changeLocale } = useLocaleSwitcher();
|
|
76
|
+
const availableLocales = customLocales || routingLocales;
|
|
77
|
+
return /* @__PURE__ */ jsx(
|
|
78
|
+
BaseLocaleSwitcher,
|
|
79
|
+
{
|
|
80
|
+
locale,
|
|
81
|
+
locales: availableLocales,
|
|
82
|
+
onChange: changeLocale,
|
|
83
|
+
...props
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
LocaleSwitcher
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=components.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/components/LocaleSwitcher.tsx","../../src/i18n/client.ts","../../src/i18n/navigation.ts","../../src/i18n/routing.ts"],"sourcesContent":["/**\n * LocaleSwitcher Component (Smart)\n *\n * Wrapper around @djangocfg/layouts LocaleSwitcher with next-intl hooks.\n * Automatically gets locale data from routing config.\n *\n * @example\n * ```tsx\n * import { LocaleSwitcher } from '@djangocfg/nextjs/i18n/components';\n *\n * // Basic usage (uses all locales from routing config)\n * <LocaleSwitcher />\n *\n * // With custom locales\n * <LocaleSwitcher locales={['en', 'ru']} />\n *\n * // With custom labels\n * <LocaleSwitcher\n * labels={{\n * en: 'English',\n * ru: 'Русский',\n * ko: '한국어',\n * }}\n * />\n * ```\n */\n\n'use client';\n\nimport {\n LocaleSwitcher as BaseLocaleSwitcher,\n type LocaleSwitcherProps as BaseLocaleSwitcherProps,\n} from '@djangocfg/layouts';\n\nimport { useLocaleSwitcher } from '../client';\nimport type { LocaleCode } from '../types';\n\nexport interface LocaleSwitcherProps\n extends Omit<BaseLocaleSwitcherProps, 'locale' | 'locales' | 'onChange'> {\n /** Available locales (defaults to all from routing config) */\n locales?: LocaleCode[];\n}\n\nexport function LocaleSwitcher({\n locales: customLocales,\n ...props\n}: LocaleSwitcherProps) {\n const { locale, locales: routingLocales, changeLocale } = useLocaleSwitcher();\n\n const availableLocales = customLocales || routingLocales;\n\n return (\n <BaseLocaleSwitcher\n locale={locale}\n locales={availableLocales}\n onChange={changeLocale}\n {...props}\n />\n );\n}\n","/**\n * Client-side i18n Hooks\n *\n * For use in Client Components ('use client')\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useTranslations, useLocale } from '@djangocfg/nextjs/i18n/client';\n *\n * export function MyComponent() {\n * const t = useTranslations('HomePage');\n * const locale = useLocale();\n *\n * return <h1>{t('title')}</h1>;\n * }\n * ```\n */\n\n'use client';\n\nimport {\n useTranslations as useNextIntlTranslations,\n useLocale as useNextIntlLocale,\n useMessages,\n useNow,\n useTimeZone,\n useFormatter,\n} from 'next-intl';\nimport { useRouter, usePathname } from './navigation';\nimport { routing } from './routing';\nimport type { LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Core Client Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Get translations in Client Components\n *\n * @example\n * ```tsx\n * const t = useTranslations('HomePage');\n * return <h1>{t('title')}</h1>;\n *\n * // With interpolation\n * return <p>{t('greeting', { name: 'John' })}</p>;\n * ```\n */\nexport function useTranslations<Namespace extends string = never>(\n namespace?: Namespace\n) {\n return useNextIntlTranslations(namespace);\n}\n\n/**\n * Get current locale in Client Components\n */\nexport function useLocale(): LocaleCode {\n return useNextIntlLocale() as LocaleCode;\n}\n\n/**\n * Get all messages\n * Useful for passing to child providers\n */\nexport { useMessages };\n\n/**\n * Get current time\n */\nexport { useNow };\n\n/**\n * Get timezone\n */\nexport { useTimeZone };\n\n/**\n * Get formatter for dates, numbers, etc.\n */\nexport { useFormatter };\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Convenience Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Shorthand for useTranslations\n * Alias for compatibility with @djangocfg/i18n\n */\nexport const useT = useTranslations;\n\n/**\n * Get namespaced translations\n *\n * @example\n * ```tsx\n * const pt = useNamespacedTranslations('payments');\n * return <span>{pt('balance.available')}</span>;\n * ```\n */\nexport function useNamespacedTranslations(namespace: string) {\n return useNextIntlTranslations(namespace);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Formatting Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Format a date according to locale\n *\n * @example\n * ```tsx\n * const formatDate = useDateFormatter();\n * return <span>{formatDate(new Date())}</span>;\n * ```\n */\nexport function useDateFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.dateTime>[1]) =>\n formatter.dateTime(date, options);\n}\n\n/**\n * Format a number according to locale\n *\n * @example\n * ```tsx\n * const formatNumber = useNumberFormatter();\n * return <span>{formatNumber(1234.56)}</span>;\n * ```\n */\nexport function useNumberFormatter() {\n const formatter = useFormatter();\n return (number: number, options?: Parameters<typeof formatter.number>[1]) =>\n formatter.number(number, options);\n}\n\n/**\n * Format relative time\n *\n * @example\n * ```tsx\n * const formatRelative = useRelativeTimeFormatter();\n * return <span>{formatRelative(new Date())}</span>;\n * ```\n */\nexport function useRelativeTimeFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.relativeTime>[1]) =>\n formatter.relativeTime(date, options);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Switching Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Get list of available locales from routing config\n *\n * @example\n * ```tsx\n * const locales = useLocales();\n * // ['en', 'ru', 'ko']\n * ```\n */\nexport function useLocales(): LocaleCode[] {\n return routing.locales as LocaleCode[];\n}\n\n/**\n * Get default locale from routing config\n */\nexport function useDefaultLocale(): LocaleCode {\n return routing.defaultLocale as LocaleCode;\n}\n\n/**\n * Hook to change current locale\n *\n * @example\n * ```tsx\n * const changeLocale = useChangeLocale();\n *\n * <button onClick={() => changeLocale('ru')}>\n * Switch to Russian\n * </button>\n * ```\n */\nexport function useChangeLocale() {\n const router = useRouter();\n const pathname = usePathname();\n\n return (locale: LocaleCode) => {\n router.replace(pathname, { locale });\n };\n}\n\n/**\n * Combined hook for locale switching\n * Returns current locale, available locales, and change function\n *\n * @example\n * ```tsx\n * const { locale, locales, changeLocale } = useLocaleSwitcher();\n *\n * <select value={locale} onChange={(e) => changeLocale(e.target.value)}>\n * {locales.map(l => <option key={l} value={l}>{l}</option>)}\n * </select>\n * ```\n */\nexport function useLocaleSwitcher() {\n const locale = useLocale();\n const locales = useLocales();\n const changeLocale = useChangeLocale();\n\n return { locale, locales, changeLocale };\n}\n","/**\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 ?? 'as-needed';\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":";AA6BA;AAAA,EACE,kBAAkB;AAAA,OAEb;;;ACVP;AAAA,EACE,mBAAmB;AAAA,EACnB,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACHP,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;AAkBO,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI,iBAAiB;;;ADZd,SAAS,YAAwB;AACtC,SAAO,kBAAkB;AAC3B;AA4GO,SAAS,aAA2B;AACzC,SAAO,QAAQ;AACjB;AAqBO,SAAS,kBAAkB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAE7B,SAAO,CAAC,WAAuB;AAC7B,WAAO,QAAQ,UAAU,EAAE,OAAO,CAAC;AAAA,EACrC;AACF;AAeO,SAAS,oBAAoB;AAClC,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,WAAW;AAC3B,QAAM,eAAe,gBAAgB;AAErC,SAAO,EAAE,QAAQ,SAAS,aAAa;AACzC;;;ADxKI;AATG,SAAS,eAAe;AAAA,EAC7B,SAAS;AAAA,EACT,GAAG;AACL,GAAwB;AACtB,QAAM,EAAE,QAAQ,SAAS,gBAAgB,aAAa,IAAI,kBAAkB;AAE5E,QAAM,mBAAmB,iBAAiB;AAE1C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,SAAS;AAAA,MACT,UAAU;AAAA,MACT,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { E as ExtensionMessages, I as I18nConfig, a as I18nPluginOptions, b as I18nProviderProps, d as LocaleLayoutProps, e as LocalePageProps, L as LocaleParams, M as Messages, c as MessagesLoader } from '../types-Cy349X20.mjs';
|
|
2
|
+
export { createRouting, generateLocaleParams, getLocaleFromParams, isValidLocale, routing } from './routing.mjs';
|
|
3
|
+
export { Link, LinkProps, createNavigation, createNavigationFromConfig, getPathname, redirect, usePathname, useRouter } from './navigation.mjs';
|
|
4
|
+
export { I18nProvider, NextIntlProvider } from './provider.mjs';
|
|
5
|
+
export { RequestConfigOptions, createRequestConfig } from './request.mjs';
|
|
6
|
+
export { createProxy, createProxyFromConfig, proxy, config as proxyConfig } from './proxy.mjs';
|
|
7
|
+
export { LocaleSwitcher, LocaleSwitcherProps } from './components.mjs';
|
|
8
|
+
export { I18nTranslations, LocaleCode } from '@djangocfg/i18n';
|
|
9
|
+
import 'next-intl/routing';
|
|
10
|
+
import 'next/navigation';
|
|
11
|
+
import 'next/dist/shared/lib/app-router-context.shared-runtime';
|
|
12
|
+
import 'next-intl/navigation';
|
|
13
|
+
import 'url';
|
|
14
|
+
import 'next-intl';
|
|
15
|
+
import 'react';
|
|
16
|
+
import 'next-intl/server';
|
|
17
|
+
import 'next/server';
|
|
18
|
+
import '@djangocfg/layouts';
|
|
@@ -0,0 +1,226 @@
|
|
|
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(config2) {
|
|
6
|
+
const locales = config2?.locales ?? DEFAULT_LOCALES;
|
|
7
|
+
const defaultLocale = config2?.defaultLocale ?? DEFAULT_LOCALE;
|
|
8
|
+
const localePrefix = config2?.localePrefix ?? "as-needed";
|
|
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
|
+
|
|
27
|
+
// src/i18n/navigation.ts
|
|
28
|
+
import { createNavigation as createNextIntlNavigation } from "next-intl/navigation";
|
|
29
|
+
function createNavigation(routingConfig) {
|
|
30
|
+
const config2 = routingConfig ?? routing;
|
|
31
|
+
return createNextIntlNavigation(config2);
|
|
32
|
+
}
|
|
33
|
+
function createNavigationFromConfig(config2) {
|
|
34
|
+
const routingConfig = createRouting(config2);
|
|
35
|
+
return createNextIntlNavigation(routingConfig);
|
|
36
|
+
}
|
|
37
|
+
var {
|
|
38
|
+
Link,
|
|
39
|
+
redirect,
|
|
40
|
+
usePathname,
|
|
41
|
+
useRouter,
|
|
42
|
+
getPathname
|
|
43
|
+
} = createNavigation();
|
|
44
|
+
|
|
45
|
+
// src/i18n/provider.tsx
|
|
46
|
+
import { NextIntlClientProvider } from "next-intl";
|
|
47
|
+
import { I18nProvider as DjangoCfgI18nProvider } from "@djangocfg/i18n";
|
|
48
|
+
import { jsx } from "react/jsx-runtime";
|
|
49
|
+
function I18nProvider({
|
|
50
|
+
locale,
|
|
51
|
+
messages,
|
|
52
|
+
timeZone = "UTC",
|
|
53
|
+
now,
|
|
54
|
+
children
|
|
55
|
+
}) {
|
|
56
|
+
return /* @__PURE__ */ jsx(
|
|
57
|
+
NextIntlClientProvider,
|
|
58
|
+
{
|
|
59
|
+
locale,
|
|
60
|
+
messages,
|
|
61
|
+
timeZone,
|
|
62
|
+
now,
|
|
63
|
+
children: /* @__PURE__ */ jsx(
|
|
64
|
+
DjangoCfgI18nProvider,
|
|
65
|
+
{
|
|
66
|
+
locale,
|
|
67
|
+
translations: messages,
|
|
68
|
+
children
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function NextIntlProvider({
|
|
75
|
+
locale,
|
|
76
|
+
messages,
|
|
77
|
+
timeZone = "UTC",
|
|
78
|
+
now,
|
|
79
|
+
children
|
|
80
|
+
}) {
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
NextIntlClientProvider,
|
|
83
|
+
{
|
|
84
|
+
locale,
|
|
85
|
+
messages,
|
|
86
|
+
timeZone,
|
|
87
|
+
now,
|
|
88
|
+
children
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/i18n/request.ts
|
|
94
|
+
import { getRequestConfig } from "next-intl/server";
|
|
95
|
+
import { mergeTranslations, en, ru, ko } from "@djangocfg/i18n";
|
|
96
|
+
var DEFAULT_LOCALES2 = {
|
|
97
|
+
en,
|
|
98
|
+
ru,
|
|
99
|
+
ko
|
|
100
|
+
};
|
|
101
|
+
function loadMessages(locale, options) {
|
|
102
|
+
const locales = options.locales ?? DEFAULT_LOCALES2;
|
|
103
|
+
const baseMessages = locales[locale] ?? locales.en ?? en;
|
|
104
|
+
if (!options.extensions?.length) {
|
|
105
|
+
return baseMessages;
|
|
106
|
+
}
|
|
107
|
+
let mergedMessages = { ...baseMessages };
|
|
108
|
+
for (const extension of options.extensions) {
|
|
109
|
+
const extMessages = extension.locales[locale] ?? extension.locales.en;
|
|
110
|
+
if (extMessages) {
|
|
111
|
+
mergedMessages = mergeTranslations(mergedMessages, {
|
|
112
|
+
[extension.namespace]: extMessages
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return mergedMessages;
|
|
117
|
+
}
|
|
118
|
+
function createRequestConfig(options = {}) {
|
|
119
|
+
return getRequestConfig(async ({ requestLocale }) => {
|
|
120
|
+
let locale = await requestLocale;
|
|
121
|
+
if (!locale || !routing.locales.includes(locale)) {
|
|
122
|
+
locale = routing.defaultLocale;
|
|
123
|
+
}
|
|
124
|
+
const messages = options.loadMessages ? await options.loadMessages(locale) : loadMessages(locale, options);
|
|
125
|
+
return {
|
|
126
|
+
locale,
|
|
127
|
+
messages,
|
|
128
|
+
timeZone: options.timeZone ?? "UTC"
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
var request_default = createRequestConfig();
|
|
133
|
+
|
|
134
|
+
// src/i18n/proxy.ts
|
|
135
|
+
import createIntlMiddleware from "next-intl/middleware";
|
|
136
|
+
function createProxy(routingConfig) {
|
|
137
|
+
const config2 = routingConfig ?? routing;
|
|
138
|
+
return createIntlMiddleware(config2);
|
|
139
|
+
}
|
|
140
|
+
function createProxyFromConfig(config2) {
|
|
141
|
+
const routingConfig = createRouting(config2);
|
|
142
|
+
return createIntlMiddleware(routingConfig);
|
|
143
|
+
}
|
|
144
|
+
var handleI18nRouting = createProxy();
|
|
145
|
+
function proxy(request) {
|
|
146
|
+
return handleI18nRouting(request);
|
|
147
|
+
}
|
|
148
|
+
var config = {
|
|
149
|
+
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"]
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/i18n/components/LocaleSwitcher.tsx
|
|
153
|
+
import {
|
|
154
|
+
LocaleSwitcher as BaseLocaleSwitcher
|
|
155
|
+
} from "@djangocfg/layouts";
|
|
156
|
+
|
|
157
|
+
// src/i18n/client.ts
|
|
158
|
+
import {
|
|
159
|
+
useTranslations as useNextIntlTranslations,
|
|
160
|
+
useLocale as useNextIntlLocale,
|
|
161
|
+
useMessages,
|
|
162
|
+
useNow,
|
|
163
|
+
useTimeZone,
|
|
164
|
+
useFormatter
|
|
165
|
+
} from "next-intl";
|
|
166
|
+
function useLocale() {
|
|
167
|
+
return useNextIntlLocale();
|
|
168
|
+
}
|
|
169
|
+
function useLocales() {
|
|
170
|
+
return routing.locales;
|
|
171
|
+
}
|
|
172
|
+
function useChangeLocale() {
|
|
173
|
+
const router = useRouter();
|
|
174
|
+
const pathname = usePathname();
|
|
175
|
+
return (locale) => {
|
|
176
|
+
router.replace(pathname, { locale });
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function useLocaleSwitcher() {
|
|
180
|
+
const locale = useLocale();
|
|
181
|
+
const locales = useLocales();
|
|
182
|
+
const changeLocale = useChangeLocale();
|
|
183
|
+
return { locale, locales, changeLocale };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/i18n/components/LocaleSwitcher.tsx
|
|
187
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
188
|
+
function LocaleSwitcher({
|
|
189
|
+
locales: customLocales,
|
|
190
|
+
...props
|
|
191
|
+
}) {
|
|
192
|
+
const { locale, locales: routingLocales, changeLocale } = useLocaleSwitcher();
|
|
193
|
+
const availableLocales = customLocales || routingLocales;
|
|
194
|
+
return /* @__PURE__ */ jsx2(
|
|
195
|
+
BaseLocaleSwitcher,
|
|
196
|
+
{
|
|
197
|
+
locale,
|
|
198
|
+
locales: availableLocales,
|
|
199
|
+
onChange: changeLocale,
|
|
200
|
+
...props
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
export {
|
|
205
|
+
I18nProvider,
|
|
206
|
+
Link,
|
|
207
|
+
LocaleSwitcher,
|
|
208
|
+
NextIntlProvider,
|
|
209
|
+
createNavigation,
|
|
210
|
+
createNavigationFromConfig,
|
|
211
|
+
createProxy,
|
|
212
|
+
createProxyFromConfig,
|
|
213
|
+
createRequestConfig,
|
|
214
|
+
createRouting,
|
|
215
|
+
generateLocaleParams,
|
|
216
|
+
getLocaleFromParams,
|
|
217
|
+
getPathname,
|
|
218
|
+
isValidLocale,
|
|
219
|
+
proxy,
|
|
220
|
+
config as proxyConfig,
|
|
221
|
+
redirect,
|
|
222
|
+
routing,
|
|
223
|
+
usePathname,
|
|
224
|
+
useRouter
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=index.mjs.map
|