style: restore blue accents for AI dialog components and standardize gold header
This commit is contained in:
@@ -24,37 +24,32 @@ function updateDocumentDirection(lang: SupportedLanguage) {
|
||||
document.documentElement.dir = RTL_LANGUAGES.includes(lang) ? 'rtl' : 'ltr'
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the actual language to use:
|
||||
* 1. If localStorage has a saved preference, use that (client only)
|
||||
* 2. Otherwise fall back to the server-detected initialLanguage
|
||||
*/
|
||||
function resolveLanguage(fallback: SupportedLanguage): SupportedLanguage {
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
const saved = localStorage.getItem('user-language') as SupportedLanguage
|
||||
if (saved && SUPPORTED_LANGS.includes(saved)) return saved
|
||||
} catch {}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
|
||||
export function LanguageProvider({ children, initialLanguage = 'en', initialTranslations }: {
|
||||
children: ReactNode
|
||||
initialLanguage?: SupportedLanguage
|
||||
initialTranslations?: Translations
|
||||
}) {
|
||||
// Resolve language synchronously from localStorage BEFORE any effect runs.
|
||||
// This prevents the flash where initialLanguage ('en') overrides RTL.
|
||||
const [language, setLanguageState] = useState<SupportedLanguage>(() => resolveLanguage(initialLanguage))
|
||||
// Use server-provided initialLanguage for the first render to prevent hydration mismatch.
|
||||
const [language, setLanguageState] = useState<SupportedLanguage>(initialLanguage)
|
||||
|
||||
// Start with server-provided translations or English fallback
|
||||
const [translations, setTranslations] = useState<Translations>(
|
||||
(initialTranslations || enTranslations) as unknown as Translations
|
||||
)
|
||||
|
||||
const cacheRef = useRef<Map<SupportedLanguage, Translations>>(new Map())
|
||||
const isFirstRender = useRef(true)
|
||||
|
||||
// Load saved preference from localStorage AFTER hydration
|
||||
useEffect(() => {
|
||||
const saved = localStorage.getItem('user-language') as SupportedLanguage
|
||||
if (saved && SUPPORTED_LANGS.includes(saved) && saved !== initialLanguage) {
|
||||
setLanguageState(saved)
|
||||
}
|
||||
}, [initialLanguage])
|
||||
|
||||
// Load translations when language changes (with caching)
|
||||
// On first render, skip updateDocumentDirection since the inline script already set it.
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user