Files
ncd-fe/packages/pl-fe/src/hooks/useLocale.ts
marcin mikołajczak e4615b70f7 pl-fe: WIP migrate settings store to zustand
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-07 01:32:55 +02:00

28 lines
580 B
TypeScript

import { getLocale } from 'pl-fe/actions/settings';
/** Locales which should be presented in right-to-left. */
const RTL_LOCALES = ['ar', 'ckb', 'fa', 'he'];
interface UseLocaleResult {
locale: string;
direction: 'ltr' | 'rtl';
}
/** Get valid locale from settings. */
const useLocale = (fallback = 'en'): UseLocaleResult => {
// TODO use useSettingsStore directly
const locale = getLocale(fallback);
const direction: 'ltr' | 'rtl' =
RTL_LOCALES.includes(locale)
? 'rtl'
: 'ltr';
return {
locale,
direction,
};
};
export { useLocale };