28 lines
714 B
TypeScript
28 lines
714 B
TypeScript
'use client'
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
/**
|
|
* Sets document direction (RTL/LTR) on mount based on saved language.
|
|
* Runs before paint to prevent visual flash.
|
|
*/
|
|
export function DirectionInitializer() {
|
|
useEffect(() => {
|
|
try {
|
|
let lang = localStorage.getItem('user-language')
|
|
if (!lang) {
|
|
const c = document.cookie.split(';').map(s => s.trim()).find(s => s.startsWith('user-language='))
|
|
if (c) lang = c.split('=')[1]
|
|
}
|
|
if (lang === 'fa' || lang === 'ar') {
|
|
document.documentElement.dir = 'rtl'
|
|
document.documentElement.lang = lang
|
|
} else {
|
|
document.documentElement.dir = 'ltr'
|
|
}
|
|
} catch {}
|
|
}, [])
|
|
|
|
return null
|
|
}
|