fix(i18n): 统一使用 useLazyTranslation 避免翻译 key 闪烁

This commit is contained in:
雨霖铃
2026-05-21 00:50:01 +08:00
parent 604fbb4d1f
commit 8e2ac5200d
19 changed files with 70 additions and 34 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ import CopyButton from '@/components/CopyButton';
import { useSnackbar } from '@/components/GlobalSnackbar';
import type { UnitType } from '@/config/pageTheme';
import { timestampPageStyles } from '@/config/pageTheme';
import { useTranslation } from 'react-i18next';
import { useLazyTranslation } from '@/utils/useLazyTranslation';
interface LiveClockProps {
unit: UnitType;
@@ -14,7 +14,7 @@ interface LiveClockProps {
const LiveClock = React.memo(({ unit, onUseNow }: LiveClockProps) => {
const [now, setNow] = useState(() => Date.now());
const { t } = useTranslation(['timestamp']);
const { t } = useLazyTranslation('timestamp');
const { showMessage } = useSnackbar();
const onUseNowRef = useRef(onUseNow);
+2 -2
View File
@@ -4,7 +4,7 @@ import dayjs from '@/utils/dayjs';
import CopyButton from '@/components/CopyButton';
import type { UnitType } from '@/config/pageTheme';
import { DATE_FORMAT, timestampPageStyles } from '@/config/pageTheme';
import { useTranslation } from 'react-i18next';
import { useLazyTranslation } from '@/utils/useLazyTranslation';
interface ResultViewProps {
result: string;
@@ -17,7 +17,7 @@ interface ResultViewProps {
const ResultView = React.memo(
({ result, mode, unit, zone, showEmptyPlaceholder = false }: ResultViewProps) => {
const { t } = useTranslation(['timestamp']);
const { t } = useLazyTranslation('timestamp');
const extraInfo = useMemo(() => {
if (!result) return null;
+2 -2
View File
@@ -2,7 +2,7 @@ import { useCallback, useState } from 'react';
import dayjs from '@/utils/dayjs';
import type { UnitType, ZoneType } from '@/config/pageTheme';
import { DATE_FORMAT } from '@/config/pageTheme';
import { useTranslation } from 'react-i18next';
import { useLazyTranslation } from '@/utils/useLazyTranslation';
import { useContextMenuData } from '@/utils/useContextMenuData';
export interface UseTimestampConverterReturn {
@@ -34,7 +34,7 @@ function isTimestampLike(input: string): boolean {
}
export function useTimestampConverter(): UseTimestampConverterReturn {
const { t } = useTranslation(['timestamp']);
const { t } = useLazyTranslation('timestamp');
const [mode, setMode] = useState<'ts2dt' | 'dt2ts'>('ts2dt');
const [tsInput, setTsInput] = useState(() => String(Date.now()));
const [dtInput, setDtInput] = useState(() => dayjs().format(DATE_FORMAT));