Comments
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/**
|
||||
* Hooks for date-fns localized formatters.
|
||||
*
|
||||
* Our app supports some languages that are not included in date-fns by
|
||||
* default, in which case it will fall back to English.
|
||||
*
|
||||
* {@link https://github.com/date-fns/date-fns/blob/main/docs/i18n.md}
|
||||
*/
|
||||
|
||||
import React from 'react'
|
||||
import {formatDistance, Locale} from 'date-fns'
|
||||
import {
|
||||
@@ -18,8 +27,13 @@ import {
|
||||
zhTW,
|
||||
} from 'date-fns/locale'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import {AppLanguage} from '#/locale/languages'
|
||||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
|
||||
/**
|
||||
* {@link AppLanguage}
|
||||
*/
|
||||
const locales: Record<string, Locale> = {
|
||||
ca,
|
||||
de,
|
||||
@@ -38,6 +52,10 @@ const locales: Record<string, Locale> = {
|
||||
zhTW,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a localized `formatDistance` function.
|
||||
* {@link formatDistance}
|
||||
*/
|
||||
export function useFormatDistance() {
|
||||
const {appLanguage} = useLanguagePrefs()
|
||||
return React.useCallback<typeof formatDistance>(
|
||||
|
||||
Reference in New Issue
Block a user