spacedrive/interface/hooks/useLocale.ts
Artsiom Voitas dee3ca0524
Added date formatting according to chosen language in the settings (#2414)
* added date formatting according to chosen language

* deleted spaces

* deleted spaces

* fixed typos

* set date formats after

* error handling

---------

Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
2024-04-30 16:52:20 +00:00

23 lines
704 B
TypeScript

import dayjs from 'dayjs';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { loadDayjsLocale } from '~/app/$libraryId/Explorer/util';
dayjs.extend(localizedFormat);
export const useLocale = (namespace: Parameters<typeof useTranslation>[0] = 'translation') => {
const { i18n, t } = useTranslation(namespace);
const isLocaleReady = Object.keys(i18n).length > 0;
loadDayjsLocale(i18n.resolvedLanguage || i18n.language || 'en');
const [dateFormat, setDateFormat] = useState(localStorage.getItem('sd-date-format') || 'LL');
return {
i18n,
t,
isLocaleReady,
dateFormat,
setDateFormat
};
};