bigbuffet-rw/app/soapbox/hooks/useLocale.ts

31 lines
697 B
TypeScript
Raw Normal View History

import { getLocale } from 'soapbox/actions/settings';
import { useAppSelector } from './useAppSelector';
import type { CSSProperties } from 'react';
/** Locales which should be presented in right-to-left. */
const RTL_LOCALES = ['ar', 'ckb', 'fa', 'he'];
interface UseLocaleResult {
locale: string
direction: CSSProperties['direction']
}
/** Get valid locale from settings. */
const useLocale = (fallback = 'en'): UseLocaleResult => {
const locale = useAppSelector((state) => getLocale(state, fallback));
const direction: CSSProperties['direction'] =
RTL_LOCALES.includes(locale)
? 'rtl'
2022-12-23 15:34:14 -08:00
: 'ltr';
return {
locale,
direction,
};
};
export { useLocale };