@djangocfg/layouts 2.1.304 → 2.1.308
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 +1 -1
- package/package.json +18 -18
- package/src/layouts/AppLayout/AppLayout.tsx +14 -11
- package/src/layouts/AppLayout/BaseApp.tsx +3 -1
- package/src/layouts/AppLayout/LayoutI18nProvider.tsx +59 -0
- package/src/layouts/AppLayout/index.ts +7 -0
- package/src/layouts/PrivateLayout/PrivateLayout.tsx +1 -5
- package/src/layouts/PrivateLayout/components/PrivateSidebar.tsx +2 -4
- package/src/layouts/PublicLayout/README.md +13 -13
- package/src/layouts/PublicLayout/footers/DefaultFooter/DefaultFooter.tsx +6 -11
- package/src/layouts/PublicLayout/footers/DefaultFooter/types.ts +15 -6
- package/src/layouts/PublicLayout/navbars/FloatingNavbar/FloatingNavbar.tsx +1 -5
- package/src/layouts/PublicLayout/navbars/FlushNavbar/FlushNavbar.tsx +1 -5
- package/src/layouts/PublicLayout/navbars/MinimalNavbar/MinimalNavbar.tsx +1 -6
- package/src/layouts/PublicLayout/primitives/NavControls.tsx +5 -9
- package/src/layouts/PublicLayout/shared/MobileDrawerShell.tsx +2 -6
- package/src/layouts/PublicLayout/shared/NavbarShell.tsx +1 -7
- package/src/layouts/_components/LocaleSwitcher.tsx +40 -178
- package/src/layouts/_components/PrivateSidebarAccount.tsx +6 -8
- package/src/layouts/_components/UserMenu.tsx +15 -19
- package/src/layouts/_components/index.ts +23 -2
- package/src/layouts/_components/locale-switcher/LocaleCard.tsx +91 -0
- package/src/layouts/_components/locale-switcher/LocaleGrid.tsx +128 -0
- package/src/layouts/_components/locale-switcher/LocaleSwitcher.tsx +100 -0
- package/src/layouts/_components/locale-switcher/LocaleSwitcherDialog.tsx +168 -0
- package/src/layouts/_components/locale-switcher/LocaleSwitcherDropdown.tsx +101 -0
- package/src/layouts/_components/locale-switcher/LocaleSwitcherTrigger.tsx +103 -0
- package/src/layouts/_components/locale-switcher/index.ts +27 -0
- package/src/layouts/_components/locale-switcher/localeMeta.ts +109 -0
- package/src/layouts/_components/locale-switcher/types.ts +48 -0
- package/src/layouts/types/layout.types.ts +37 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale metadata — native name + english name per locale code.
|
|
3
|
+
*
|
|
4
|
+
* Covers the codes shipped with `@djangocfg/i18n` (and their common regional
|
|
5
|
+
* variants). Unknown codes fall back to the uppercase code itself.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface LocaleMeta {
|
|
9
|
+
/** Native rendering — `'Русский'`, `'한국어'`. */
|
|
10
|
+
native: string;
|
|
11
|
+
/** English name — `'Russian'`, `'Korean'`. Used as the secondary line. */
|
|
12
|
+
english: string;
|
|
13
|
+
/** Marks the locale as RTL (`ar`, `he`, `fa`, `ur`). */
|
|
14
|
+
rtl?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const RTL_LANGS = new Set(['ar', 'he', 'fa', 'ur', 'ps', 'sd', 'yi', 'ku']);
|
|
18
|
+
|
|
19
|
+
const META: Record<string, { native: string; english: string }> = {
|
|
20
|
+
// Major
|
|
21
|
+
en: { native: 'English', english: 'English' },
|
|
22
|
+
ru: { native: 'Русский', english: 'Russian' },
|
|
23
|
+
ko: { native: '한국어', english: 'Korean' },
|
|
24
|
+
zh: { native: '中文', english: 'Chinese' },
|
|
25
|
+
ja: { native: '日本語', english: 'Japanese' },
|
|
26
|
+
es: { native: 'Español', english: 'Spanish' },
|
|
27
|
+
fr: { native: 'Français', english: 'French' },
|
|
28
|
+
de: { native: 'Deutsch', english: 'German' },
|
|
29
|
+
pt: { native: 'Português', english: 'Portuguese' },
|
|
30
|
+
it: { native: 'Italiano', english: 'Italian' },
|
|
31
|
+
ar: { native: 'العربية', english: 'Arabic' },
|
|
32
|
+
hi: { native: 'हिन्दी', english: 'Hindi' },
|
|
33
|
+
tr: { native: 'Türkçe', english: 'Turkish' },
|
|
34
|
+
pl: { native: 'Polski', english: 'Polish' },
|
|
35
|
+
nl: { native: 'Nederlands', english: 'Dutch' },
|
|
36
|
+
uk: { native: 'Українська', english: 'Ukrainian' },
|
|
37
|
+
|
|
38
|
+
// Regional variants
|
|
39
|
+
'pt-BR': { native: 'Português (Brasil)', english: 'Portuguese (Brazil)' },
|
|
40
|
+
'pt-PT': { native: 'Português (Portugal)', english: 'Portuguese (Portugal)' },
|
|
41
|
+
'zh-CN': { native: '简体中文', english: 'Chinese (Simplified)' },
|
|
42
|
+
'zh-TW': { native: '繁體中文', english: 'Chinese (Traditional)' },
|
|
43
|
+
'en-US': { native: 'English (US)', english: 'English (US)' },
|
|
44
|
+
'en-GB': { native: 'English (UK)', english: 'English (UK)' },
|
|
45
|
+
'es-MX': { native: 'Español (México)', english: 'Spanish (Mexico)' },
|
|
46
|
+
'es-ES': { native: 'Español (España)', english: 'Spanish (Spain)' },
|
|
47
|
+
'fr-CA': { native: 'Français (Canada)', english: 'French (Canada)' },
|
|
48
|
+
|
|
49
|
+
// Scandinavian
|
|
50
|
+
sv: { native: 'Svenska', english: 'Swedish' },
|
|
51
|
+
no: { native: 'Norsk', english: 'Norwegian' },
|
|
52
|
+
nb: { native: 'Norsk Bokmål', english: 'Norwegian Bokmål' },
|
|
53
|
+
nn: { native: 'Norsk Nynorsk', english: 'Norwegian Nynorsk' },
|
|
54
|
+
da: { native: 'Dansk', english: 'Danish' },
|
|
55
|
+
fi: { native: 'Suomi', english: 'Finnish' },
|
|
56
|
+
is: { native: 'Íslenska', english: 'Icelandic' },
|
|
57
|
+
|
|
58
|
+
// Other European
|
|
59
|
+
cs: { native: 'Čeština', english: 'Czech' },
|
|
60
|
+
sk: { native: 'Slovenčina', english: 'Slovak' },
|
|
61
|
+
hu: { native: 'Magyar', english: 'Hungarian' },
|
|
62
|
+
ro: { native: 'Română', english: 'Romanian' },
|
|
63
|
+
bg: { native: 'Български', english: 'Bulgarian' },
|
|
64
|
+
hr: { native: 'Hrvatski', english: 'Croatian' },
|
|
65
|
+
sr: { native: 'Српски', english: 'Serbian' },
|
|
66
|
+
sl: { native: 'Slovenščina', english: 'Slovenian' },
|
|
67
|
+
et: { native: 'Eesti', english: 'Estonian' },
|
|
68
|
+
lv: { native: 'Latviešu', english: 'Latvian' },
|
|
69
|
+
lt: { native: 'Lietuvių', english: 'Lithuanian' },
|
|
70
|
+
el: { native: 'Ελληνικά', english: 'Greek' },
|
|
71
|
+
|
|
72
|
+
// Other
|
|
73
|
+
th: { native: 'ไทย', english: 'Thai' },
|
|
74
|
+
vi: { native: 'Tiếng Việt', english: 'Vietnamese' },
|
|
75
|
+
id: { native: 'Indonesia', english: 'Indonesian' },
|
|
76
|
+
ms: { native: 'Bahasa Melayu', english: 'Malay' },
|
|
77
|
+
he: { native: 'עברית', english: 'Hebrew' },
|
|
78
|
+
fa: { native: 'فارسی', english: 'Persian' },
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
function normalize(code: string): { exact: string; base: string } {
|
|
82
|
+
const trimmed = code.trim();
|
|
83
|
+
const dash = trimmed.indexOf('-');
|
|
84
|
+
if (dash === -1) {
|
|
85
|
+
return { exact: trimmed.toLowerCase(), base: trimmed.toLowerCase() };
|
|
86
|
+
}
|
|
87
|
+
const lang = trimmed.slice(0, dash).toLowerCase();
|
|
88
|
+
const region = trimmed.slice(dash + 1).toUpperCase();
|
|
89
|
+
return { exact: `${lang}-${region}`, base: lang };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getLocaleMeta(
|
|
93
|
+
code: string,
|
|
94
|
+
overrides?: Record<string, string>,
|
|
95
|
+
): LocaleMeta {
|
|
96
|
+
const { exact, base } = normalize(code);
|
|
97
|
+
|
|
98
|
+
// Manual overrides win — match either the exact code or the base.
|
|
99
|
+
const overrideNative = overrides?.[code] ?? overrides?.[exact] ?? overrides?.[base];
|
|
100
|
+
|
|
101
|
+
// Try exact match first (`pt-BR`), fall back to base (`pt`).
|
|
102
|
+
const direct = META[exact] ?? META[base];
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
native: overrideNative ?? direct?.native ?? code.toUpperCase(),
|
|
106
|
+
english: direct?.english ?? code.toUpperCase(),
|
|
107
|
+
rtl: RTL_LANGS.has(base),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type LocaleSwitcherVariant = 'dropdown' | 'dialog';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Brand block shown in the dialog header. Pass either a logo node, a
|
|
7
|
+
* project name string, or both. Falls back to a Globe icon + "Select
|
|
8
|
+
* language" header when no brand is provided.
|
|
9
|
+
*/
|
|
10
|
+
export interface LocaleSwitcherBrand {
|
|
11
|
+
/** Logo node (img, svg, lucide icon, …). Sized at ~40×40 in the dialog header. */
|
|
12
|
+
logo?: ReactNode;
|
|
13
|
+
/** Project name displayed alongside the logo. */
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LocaleSwitcherLabels {
|
|
18
|
+
/**
|
|
19
|
+
* Title rendered in the dialog hero (`Choose your language`).
|
|
20
|
+
* The dialog also exposes this string as the accessible DialogTitle.
|
|
21
|
+
*/
|
|
22
|
+
dialogTitle?: string;
|
|
23
|
+
/** Subtitle below the title. */
|
|
24
|
+
dialogSubtitle?: string;
|
|
25
|
+
/** Search input placeholder. */
|
|
26
|
+
searchPlaceholder?: string;
|
|
27
|
+
/** Empty state when no locales match the search. */
|
|
28
|
+
emptyResults?: string;
|
|
29
|
+
/** Aria-label for the close button (also used as tooltip). */
|
|
30
|
+
closeLabel?: string;
|
|
31
|
+
/** Aria-label for the trigger button. */
|
|
32
|
+
triggerLabel?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LocaleSwitcherSharedProps {
|
|
36
|
+
/** Current locale (ISO 639-1, optionally with region — `'pt-BR'`). */
|
|
37
|
+
locale: string;
|
|
38
|
+
/** Available locales. */
|
|
39
|
+
locales: string[];
|
|
40
|
+
/** Selection callback. */
|
|
41
|
+
onChange: (locale: string) => void;
|
|
42
|
+
/** Override / add native names (`{ es: 'Español' }`). */
|
|
43
|
+
labels?: Record<string, string>;
|
|
44
|
+
/** UI strings (search placeholder, close, …). */
|
|
45
|
+
i18nLabels?: LocaleSwitcherLabels;
|
|
46
|
+
/** Extra trigger className. */
|
|
47
|
+
className?: string;
|
|
48
|
+
}
|
|
@@ -62,6 +62,13 @@ export interface BaseLayoutProps {
|
|
|
62
62
|
|
|
63
63
|
/** Debug panel configuration */
|
|
64
64
|
debug?: DebugConfig;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Locale-switching plumbing. Mounted into a `LayoutI18nProvider` inside
|
|
68
|
+
* `BaseApp` — every locale-aware component (footer, navbar, sidebar,
|
|
69
|
+
* UserMenu, LocaleSwitcher) reads from there via `useLayoutI18n()`.
|
|
70
|
+
*/
|
|
71
|
+
i18n?: I18nLayoutConfig;
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
/** Debug panel config — enabled in development by default, pass enabled: true/false to override */
|
|
@@ -70,9 +77,34 @@ export interface DebugConfig extends DebugButtonProps {
|
|
|
70
77
|
enabled?: boolean;
|
|
71
78
|
}
|
|
72
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Brand block surfaced inside the locale-switcher dialog. Shared via
|
|
82
|
+
* `I18nLayoutConfig.brand` so footer / navbar / sidebar all open the same
|
|
83
|
+
* dialog with the same identity.
|
|
84
|
+
*/
|
|
85
|
+
export interface I18nBrandConfig {
|
|
86
|
+
/** Logo node — img / svg / lucide icon. Sized ~36×36 in the dialog header. */
|
|
87
|
+
logo?: ReactNode;
|
|
88
|
+
/** Project name shown beside the logo. */
|
|
89
|
+
name?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** UI strings for the locale-switcher dialog (also passed via i18n). */
|
|
93
|
+
export interface I18nDialogLabels {
|
|
94
|
+
dialogTitle?: string;
|
|
95
|
+
dialogSubtitle?: string;
|
|
96
|
+
searchPlaceholder?: string;
|
|
97
|
+
emptyResults?: string;
|
|
98
|
+
closeLabel?: string;
|
|
99
|
+
triggerLabel?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
73
102
|
/**
|
|
74
103
|
* i18n configuration consumed by layouts, navbars, footer controls, and the
|
|
75
|
-
* UserMenu locale row. Same shape as `@djangocfg/nextjs`'s `useLocaleSwitcher
|
|
104
|
+
* UserMenu locale row. Same shape as `@djangocfg/nextjs`'s `useLocaleSwitcher`,
|
|
105
|
+
* with optional `brand` / `dialogLabels` so every locale-switcher mount
|
|
106
|
+
* (footer, navbar, sidebar) opens the same fullscreen dialog with a
|
|
107
|
+
* consistent identity.
|
|
76
108
|
*/
|
|
77
109
|
export interface I18nLayoutConfig {
|
|
78
110
|
/** Current locale (e.g. `"en"`, `"ru"`, `"pt-BR"`). */
|
|
@@ -81,6 +113,10 @@ export interface I18nLayoutConfig {
|
|
|
81
113
|
locales: string[];
|
|
82
114
|
/** Called when the user picks a new locale. */
|
|
83
115
|
onLocaleChange: (locale: string) => void;
|
|
116
|
+
/** Brand surfaced in the locale-switcher dialog header. */
|
|
117
|
+
brand?: I18nBrandConfig;
|
|
118
|
+
/** Custom UI strings for the locale-switcher dialog. */
|
|
119
|
+
dialogLabels?: I18nDialogLabels;
|
|
84
120
|
}
|
|
85
121
|
|
|
86
122
|
// ============================================================================
|