fix(dayjs): fix relative time not follow language change (#3932)

* fix(dayjs): fix relative time not follow when language change

* fix: update world in grid item template

* fix: change dayjs locale to settings change

* fix: apply suggest review suggestion
This commit is contained in:
Cason Kervis
2025-06-18 15:51:27 +08:00
committed by GitHub
parent 1de43e1595
commit e3deb2ec10
5 changed files with 12 additions and 3 deletions
@@ -4,6 +4,7 @@ import { useEntry } from "@follow/store/entry/hooks"
import { useFeedById } from "@follow/store/feed/hooks"
import { cn } from "@follow/utils/utils"
import dayjs from "dayjs"
import { useTranslation } from "react-i18next"
import { useEntryIsRead } from "~/hooks/biz/useAsRead"
import { EntryTranslation } from "~/modules/entry-column/translation"
@@ -71,6 +72,8 @@ export const GridItemFooter = ({
const asRead = useEntryIsRead(entry)
const { t } = useTranslation("common")
if (!entry) return null
return (
<div className={cn("relative px-2 text-sm")}>
@@ -111,6 +114,8 @@ export const GridItemFooter = ({
<span className={cn("text-zinc-500", timeClassName)}>·</span>
<span className={cn("text-zinc-500", timeClassName)}>
{dayjs.duration(dayjs(entry?.publishedAt).diff(dayjs(), "minute"), "minute").humanize()}
{t("space")}
{t("words.ago")}
</span>
</div>
</div>
@@ -5,6 +5,7 @@ import { ACTION_LANGUAGE_MAP } from "@follow/shared"
import { IN_ELECTRON } from "@follow/shared/constants"
import { cn } from "@follow/utils/utils"
import { useQuery } from "@tanstack/react-query"
import dayjs from "dayjs"
import { useAtom } from "jotai"
import { useEffect } from "react"
import { useTranslation } from "react-i18next"
@@ -269,6 +270,7 @@ export const LanguageSelector = ({
disabled={loadingLanguageLockMap[finalRenderLanguage]}
onValueChange={(value) => {
setGeneralSetting("language", value as string)
dayjs.locale(value)
}}
renderItem={useTypeScriptHappyCallback((item) => {
const lang = item.value
+1 -1
View File
@@ -34,7 +34,7 @@
"ok": "OK",
"quantifier.piece": "個",
"retry": "再試行",
"space": " ",
"space": "",
"time.last_night": "昨夜",
"time.the_night_before_last": "一昨夜",
"time.today": "今日",
+1 -1
View File
@@ -37,7 +37,7 @@
"ok": "確定",
"quantifier.piece": "條",
"retry": "重試",
"space": " ",
"space": "",
"time.last_night": "昨晚",
"time.the_night_before_last": "前晚",
"time.today": "今天",
@@ -34,6 +34,8 @@ export const RelativeTime: FC<{
const timerRef = useRef<any>(null)
const { i18n } = useTranslation("common")
useEffect(() => {
const updateRelativeTime = () => {
setRelative(formatTime(props.date, displayAbsoluteTimeAfterDay, nextDateFormatTemplate))
@@ -49,7 +51,7 @@ export const RelativeTime: FC<{
return () => {
clearTimeout(timerRef.current)
}
}, [props.date, displayAbsoluteTimeAfterDay, nextDateFormatTemplate])
}, [props.date, displayAbsoluteTimeAfterDay, nextDateFormatTemplate, i18n.language])
const formated = dayjs(props.date).format(nextDateFormatTemplate)
const { t } = useTranslation("common")