mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
fix: time from now date string not following locale changes
This commit is contained in:
parent
24fe2f13d8
commit
ba21999ed1
@ -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()
|
||||
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
5
src/signals/global.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import dayjs from 'dayjs'
|
||||
import { curLocale } from '~/i18n'
|
||||
|
||||
export const formatTimeFromNow = (time: number | string) =>
|
||||
dayjs(time).locale(curLocale()).fromNow()
|
@ -1,5 +1,6 @@
|
||||
export * from './config'
|
||||
export * from './connections'
|
||||
export * from './global'
|
||||
export * from './proxies'
|
||||
export * from './request'
|
||||
export * from './rules'
|
||||
|
Loading…
Reference in New Issue
Block a user