diff --git a/src/helpers/proxies.ts b/src/helpers/proxies.ts index 7b196d0..bed292b 100644 --- a/src/helpers/proxies.ts +++ b/src/helpers/proxies.ts @@ -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() diff --git a/src/i18n/index.tsx b/src/i18n/index.tsx index 2ad60ff..3b6e289 100644 --- a/src/i18n/index.tsx +++ b/src/i18n/index.tsx @@ -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( 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 } } diff --git a/src/pages/Connections.tsx b/src/pages/Connections.tsx index b78333e..ab15886 100644 --- a/src/pages/Connections.tsx +++ b/src/pages/Connections.tsx @@ -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, diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index e8862dd..7f9edda 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -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, diff --git a/src/pages/Rules.tsx b/src/pages/Rules.tsx index 2a9622b..f7543ab 100644 --- a/src/pages/Rules.tsx +++ b/src/pages/Rules.tsx @@ -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', diff --git a/src/signals/global.ts b/src/signals/global.ts new file mode 100644 index 0000000..65a566e --- /dev/null +++ b/src/signals/global.ts @@ -0,0 +1,5 @@ +import dayjs from 'dayjs' +import { curLocale } from '~/i18n' + +export const formatTimeFromNow = (time: number | string) => + dayjs(time).locale(curLocale()).fromNow() diff --git a/src/signals/index.ts b/src/signals/index.ts index 2e37a89..7680896 100644 --- a/src/signals/index.ts +++ b/src/signals/index.ts @@ -1,5 +1,6 @@ export * from './config' export * from './connections' +export * from './global' export * from './proxies' export * from './request' export * from './rules'