2025-10-27 20:30:10 -07:00
|
|
|
"use client";
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
2025-10-27 20:30:10 -07:00
|
|
|
import type React from "react";
|
2026-04-03 23:23:54 +05:30
|
|
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
2025-10-27 20:30:10 -07:00
|
|
|
import enMessages from "../messages/en.json";
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
2026-02-11 00:39:01 -08:00
|
|
|
type Locale = "en" | "es" | "pt" | "hi" | "zh";
|
|
|
|
|
|
2026-04-08 06:39:37 +05:30
|
|
|
/**
|
|
|
|
|
* Dynamically load locale messages on demand.
|
|
|
|
|
* English is the default and always available synchronously.
|
|
|
|
|
*/
|
|
|
|
|
const loadMessages = async (locale: Locale): Promise<typeof enMessages> => {
|
|
|
|
|
switch (locale) {
|
|
|
|
|
case "es":
|
|
|
|
|
return (await import("../messages/es.json")).default;
|
|
|
|
|
case "hi":
|
|
|
|
|
return (await import("../messages/hi.json")).default;
|
|
|
|
|
case "pt":
|
|
|
|
|
return (await import("../messages/pt.json")).default;
|
|
|
|
|
case "zh":
|
|
|
|
|
return (await import("../messages/zh.json")).default;
|
|
|
|
|
default:
|
|
|
|
|
return enMessages;
|
|
|
|
|
}
|
2026-02-11 00:39:01 -08:00
|
|
|
};
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
|
|
|
|
interface LocaleContextType {
|
2025-10-27 20:30:10 -07:00
|
|
|
locale: Locale;
|
|
|
|
|
messages: typeof enMessages;
|
|
|
|
|
setLocale: (locale: Locale) => void;
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const LocaleContext = createContext<LocaleContextType | undefined>(undefined);
|
|
|
|
|
|
2025-10-27 20:30:10 -07:00
|
|
|
const LOCALE_STORAGE_KEY = "surfsense-locale";
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
|
|
|
|
export function LocaleProvider({ children }: { children: React.ReactNode }) {
|
2025-10-27 20:30:10 -07:00
|
|
|
// Always start with 'en' to avoid hydration mismatch
|
|
|
|
|
// Then sync with localStorage after mount
|
|
|
|
|
const [locale, setLocaleState] = useState<Locale>("en");
|
2026-04-08 06:39:37 +05:30
|
|
|
const [messages, setMessages] = useState<typeof enMessages>(enMessages);
|
2025-10-27 20:30:10 -07:00
|
|
|
const [mounted, setMounted] = useState(false);
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
2025-10-27 20:30:10 -07:00
|
|
|
// Load locale from localStorage after component mounts (client-side only)
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setMounted(true);
|
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
|
const stored = localStorage.getItem(LOCALE_STORAGE_KEY);
|
2026-02-11 00:39:01 -08:00
|
|
|
if (stored && (["en", "es", "pt", "hi", "zh"] as const).includes(stored as Locale)) {
|
2026-04-08 06:39:37 +05:30
|
|
|
const storedLocale = stored as Locale;
|
|
|
|
|
setLocaleState(storedLocale);
|
|
|
|
|
// Load messages for non-English locale
|
|
|
|
|
if (storedLocale !== "en") {
|
|
|
|
|
loadMessages(storedLocale).then(setMessages);
|
|
|
|
|
}
|
2025-10-27 20:30:10 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
2025-10-27 20:30:10 -07:00
|
|
|
// Update locale and persist to localStorage
|
2026-04-08 06:39:37 +05:30
|
|
|
const setLocale = useCallback(async (newLocale: Locale) => {
|
|
|
|
|
// Load messages for the new locale
|
|
|
|
|
const newMessages = await loadMessages(newLocale);
|
|
|
|
|
setMessages(newMessages);
|
2025-10-27 20:30:10 -07:00
|
|
|
setLocaleState(newLocale);
|
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
|
localStorage.setItem(LOCALE_STORAGE_KEY, newLocale);
|
|
|
|
|
// Update HTML lang attribute
|
|
|
|
|
document.documentElement.lang = newLocale;
|
|
|
|
|
}
|
2026-04-03 23:23:54 +05:30
|
|
|
}, []);
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
2025-10-27 20:30:10 -07:00
|
|
|
// Set HTML lang attribute when locale changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (typeof window !== "undefined" && mounted) {
|
|
|
|
|
document.documentElement.lang = locale;
|
|
|
|
|
}
|
|
|
|
|
}, [locale, mounted]);
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
|
2026-04-07 05:55:39 +05:30
|
|
|
const contextValue = useMemo(
|
|
|
|
|
() => ({ locale, messages, setLocale }),
|
|
|
|
|
[locale, messages, setLocale]
|
2025-10-27 20:30:10 -07:00
|
|
|
);
|
2026-04-07 05:55:39 +05:30
|
|
|
|
|
|
|
|
return <LocaleContext.Provider value={contextValue}>{children}</LocaleContext.Provider>;
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function useLocaleContext() {
|
2025-10-27 20:30:10 -07:00
|
|
|
const context = useContext(LocaleContext);
|
|
|
|
|
if (context === undefined) {
|
|
|
|
|
throw new Error("useLocaleContext must be used within a LocaleProvider");
|
|
|
|
|
}
|
|
|
|
|
return context;
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
}
|