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 React from 'react'
|
||||||
import {formatDistance, Locale} from 'date-fns'
|
import {formatDistance, Locale} from 'date-fns'
|
||||||
import {
|
import {
|
||||||
@@ -18,8 +27,13 @@ import {
|
|||||||
zhTW,
|
zhTW,
|
||||||
} from 'date-fns/locale'
|
} from 'date-fns/locale'
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
import {AppLanguage} from '#/locale/languages'
|
||||||
import {useLanguagePrefs} from '#/state/preferences'
|
import {useLanguagePrefs} from '#/state/preferences'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AppLanguage}
|
||||||
|
*/
|
||||||
const locales: Record<string, Locale> = {
|
const locales: Record<string, Locale> = {
|
||||||
ca,
|
ca,
|
||||||
de,
|
de,
|
||||||
@@ -38,6 +52,10 @@ const locales: Record<string, Locale> = {
|
|||||||
zhTW,
|
zhTW,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a localized `formatDistance` function.
|
||||||
|
* {@link formatDistance}
|
||||||
|
*/
|
||||||
export function useFormatDistance() {
|
export function useFormatDistance() {
|
||||||
const {appLanguage} = useLanguagePrefs()
|
const {appLanguage} = useLanguagePrefs()
|
||||||
return React.useCallback<typeof formatDistance>(
|
return React.useCallback<typeof formatDistance>(
|
||||||
|
|||||||
Reference in New Issue
Block a user