Files
dashboards/packages/dashboard-core/src/locale/dashboardLocale.ts
T
Alireza HassaniandCursor 66004a0fba Add FA/EN locale, home activity charts, and theme-aware polish.
Ship shared LocaleProvider, business/customer i18n, branding defaultLocale, curated home tiles with dual 30-day charts, and chart/page aura tokens; refresh PROJECT_CONTEXT.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-01 09:35:27 +03:30

38 lines
1.1 KiB
TypeScript

export type DashboardLocale = 'en' | 'fa'
export const DASHBOARD_LOCALE_STORAGE_KEY = 'meshkee.dashboard.locale'
export function isDashboardLocale(value: unknown): value is DashboardLocale {
return value === 'en' || value === 'fa'
}
export function getLocaleDirection(locale: DashboardLocale): 'ltr' | 'rtl' {
return locale === 'fa' ? 'rtl' : 'ltr'
}
export function applyDocumentLocale(locale: DashboardLocale): void {
if (typeof document === 'undefined') return
const root = document.documentElement
root.lang = locale
root.dir = getLocaleDirection(locale)
}
export function readStoredLocale(fallback: DashboardLocale = 'fa'): DashboardLocale {
if (typeof localStorage === 'undefined') return fallback
try {
const raw = localStorage.getItem(DASHBOARD_LOCALE_STORAGE_KEY)
return isDashboardLocale(raw) ? raw : fallback
} catch {
return fallback
}
}
export function writeStoredLocale(locale: DashboardLocale): void {
if (typeof localStorage === 'undefined') return
try {
localStorage.setItem(DASHBOARD_LOCALE_STORAGE_KEY, locale)
} catch {
// ignore quota / private mode
}
}