fix: time from now date string not following locale changes

This commit is contained in:
kunish 2023-09-23 00:33:48 +08:00
parent 24fe2f13d8
commit ba21999ed1
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430
7 changed files with 15 additions and 19 deletions

View File

@ -1,11 +1,6 @@
import dayjs from 'dayjs'
import { PROXIES_ORDERING_TYPE } from '~/constants'
import { latencyQualityMap } from '~/signals'
export const formatTimeFromNow = (time: number | string) => {
return dayjs(time).fromNow()
}
export const formatProxyType = (type = '') => {
const t = type.toLowerCase()

View File

@ -4,7 +4,7 @@ import { createMemo, createSignal } from 'solid-js'
import { LANG } from '~/constants'
import dict from './dict'
const [curLocale, setCurLocale] = makePersisted(
export const [curLocale, setCurLocale] = makePersisted(
createSignal<LANG>(
Reflect.has(dict, navigator.language)
? (navigator.language as LANG)
@ -16,17 +16,12 @@ const [curLocale, setCurLocale] = makePersisted(
},
)
const locale = (localeName?: LANG) => {
if (localeName) {
return setCurLocale(localeName)
}
return curLocale()
}
const locale = (localeName?: LANG) =>
localeName ? setCurLocale(localeName) : curLocale()
export const useI18n = () => {
const curDict = createMemo(() => i18n.flatten(dict[curLocale()]))!
const t = i18n.translator(() => curDict())
const t = createMemo(() => i18n.translator(() => curDict()))
return { t, locale }
return { t: t(), locale }
}

View File

@ -44,7 +44,6 @@ import {
ConnectionsTableDetailsModal,
} from '~/components'
import { CONNECTIONS_TABLE_ACCESSOR_KEY, MODAL } from '~/constants'
import { formatTimeFromNow } from '~/helpers'
import { useI18n } from '~/i18n'
import {
allConnections,
@ -52,6 +51,7 @@ import {
connectionsTableColumnOrder,
connectionsTableColumnVisibility,
connectionsTableSize,
formatTimeFromNow,
setConnectionsTableColumnOrder,
setConnectionsTableColumnVisibility,
tableSizeClassName,

View File

@ -17,12 +17,12 @@ import {
import { MODAL } from '~/constants'
import {
filterProxiesByAvailability,
formatTimeFromNow,
sortProxiesByOrderingType,
useStringBooleanMap,
} from '~/helpers'
import { useI18n } from '~/i18n'
import {
formatTimeFromNow,
hideUnAvailableProxies,
proxiesOrderingType,
useProxies,

View File

@ -2,9 +2,9 @@ import { IconReload } from '@tabler/icons-solidjs'
import { For, Show, createSignal, onMount } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Button } from '~/components'
import { formatTimeFromNow, useStringBooleanMap } from '~/helpers'
import { useStringBooleanMap } from '~/helpers'
import { useI18n } from '~/i18n'
import { useRules } from '~/signals'
import { formatTimeFromNow, useRules } from '~/signals'
enum ActiveTab {
ruleProviders = 'ruleProviders',

5
src/signals/global.ts Normal file
View File

@ -0,0 +1,5 @@
import dayjs from 'dayjs'
import { curLocale } from '~/i18n'
export const formatTimeFromNow = (time: number | string) =>
dayjs(time).locale(curLocale()).fromNow()

View File

@ -1,5 +1,6 @@
export * from './config'
export * from './connections'
export * from './global'
export * from './proxies'
export * from './request'
export * from './rules'