mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15: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 { PROXIES_ORDERING_TYPE } from '~/constants'
|
||||||
import { latencyQualityMap } from '~/signals'
|
import { latencyQualityMap } from '~/signals'
|
||||||
|
|
||||||
export const formatTimeFromNow = (time: number | string) => {
|
|
||||||
return dayjs(time).fromNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
export const formatProxyType = (type = '') => {
|
export const formatProxyType = (type = '') => {
|
||||||
const t = type.toLowerCase()
|
const t = type.toLowerCase()
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { createMemo, createSignal } from 'solid-js'
|
|||||||
import { LANG } from '~/constants'
|
import { LANG } from '~/constants'
|
||||||
import dict from './dict'
|
import dict from './dict'
|
||||||
|
|
||||||
const [curLocale, setCurLocale] = makePersisted(
|
export const [curLocale, setCurLocale] = makePersisted(
|
||||||
createSignal<LANG>(
|
createSignal<LANG>(
|
||||||
Reflect.has(dict, navigator.language)
|
Reflect.has(dict, navigator.language)
|
||||||
? (navigator.language as LANG)
|
? (navigator.language as LANG)
|
||||||
@ -16,17 +16,12 @@ const [curLocale, setCurLocale] = makePersisted(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const locale = (localeName?: LANG) => {
|
const locale = (localeName?: LANG) =>
|
||||||
if (localeName) {
|
localeName ? setCurLocale(localeName) : curLocale()
|
||||||
return setCurLocale(localeName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return curLocale()
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useI18n = () => {
|
export const useI18n = () => {
|
||||||
const curDict = createMemo(() => i18n.flatten(dict[curLocale()]))!
|
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,
|
ConnectionsTableDetailsModal,
|
||||||
} from '~/components'
|
} from '~/components'
|
||||||
import { CONNECTIONS_TABLE_ACCESSOR_KEY, MODAL } from '~/constants'
|
import { CONNECTIONS_TABLE_ACCESSOR_KEY, MODAL } from '~/constants'
|
||||||
import { formatTimeFromNow } from '~/helpers'
|
|
||||||
import { useI18n } from '~/i18n'
|
import { useI18n } from '~/i18n'
|
||||||
import {
|
import {
|
||||||
allConnections,
|
allConnections,
|
||||||
@ -52,6 +51,7 @@ import {
|
|||||||
connectionsTableColumnOrder,
|
connectionsTableColumnOrder,
|
||||||
connectionsTableColumnVisibility,
|
connectionsTableColumnVisibility,
|
||||||
connectionsTableSize,
|
connectionsTableSize,
|
||||||
|
formatTimeFromNow,
|
||||||
setConnectionsTableColumnOrder,
|
setConnectionsTableColumnOrder,
|
||||||
setConnectionsTableColumnVisibility,
|
setConnectionsTableColumnVisibility,
|
||||||
tableSizeClassName,
|
tableSizeClassName,
|
||||||
|
@ -17,12 +17,12 @@ import {
|
|||||||
import { MODAL } from '~/constants'
|
import { MODAL } from '~/constants'
|
||||||
import {
|
import {
|
||||||
filterProxiesByAvailability,
|
filterProxiesByAvailability,
|
||||||
formatTimeFromNow,
|
|
||||||
sortProxiesByOrderingType,
|
sortProxiesByOrderingType,
|
||||||
useStringBooleanMap,
|
useStringBooleanMap,
|
||||||
} from '~/helpers'
|
} from '~/helpers'
|
||||||
import { useI18n } from '~/i18n'
|
import { useI18n } from '~/i18n'
|
||||||
import {
|
import {
|
||||||
|
formatTimeFromNow,
|
||||||
hideUnAvailableProxies,
|
hideUnAvailableProxies,
|
||||||
proxiesOrderingType,
|
proxiesOrderingType,
|
||||||
useProxies,
|
useProxies,
|
||||||
|
@ -2,9 +2,9 @@ import { IconReload } from '@tabler/icons-solidjs'
|
|||||||
import { For, Show, createSignal, onMount } from 'solid-js'
|
import { For, Show, createSignal, onMount } from 'solid-js'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
import { Button } from '~/components'
|
import { Button } from '~/components'
|
||||||
import { formatTimeFromNow, useStringBooleanMap } from '~/helpers'
|
import { useStringBooleanMap } from '~/helpers'
|
||||||
import { useI18n } from '~/i18n'
|
import { useI18n } from '~/i18n'
|
||||||
import { useRules } from '~/signals'
|
import { formatTimeFromNow, useRules } from '~/signals'
|
||||||
|
|
||||||
enum ActiveTab {
|
enum ActiveTab {
|
||||||
ruleProviders = 'ruleProviders',
|
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 './config'
|
||||||
export * from './connections'
|
export * from './connections'
|
||||||
|
export * from './global'
|
||||||
export * from './proxies'
|
export * from './proxies'
|
||||||
export * from './request'
|
export * from './request'
|
||||||
export * from './rules'
|
export * from './rules'
|
||||||
|
Loading…
Reference in New Issue
Block a user