fix(i18n): replace useTranslation with useLazyTranslation in Base64Converter
Fix missing translations by ensuring base64Converter namespace is dynamically loaded.
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
import { Download } from 'lucide-react';
|
import { Download } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { formatFileSize } from '@/utils/base64Converter';
|
import { formatFileSize } from '@/utils/base64Converter';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useLazyTranslation } from '@/utils/useLazyTranslation';
|
||||||
|
|
||||||
interface DecodeResultPaperProps {
|
interface DecodeResultPaperProps {
|
||||||
/** 标题文案,由调用方传入 i18n key 对应的值(如 decodedFileOutput / decodedImageOutput) */
|
/** 标题文案,由调用方传入 i18n key 对应的值(如 decodedFileOutput / decodedImageOutput) */
|
||||||
@@ -38,7 +38,7 @@ export default function DecodeResultPaper({
|
|||||||
onDownload,
|
onDownload,
|
||||||
children,
|
children,
|
||||||
}: DecodeResultPaperProps) {
|
}: DecodeResultPaperProps) {
|
||||||
const { t } = useTranslation('base64Converter');
|
const { t } = useLazyTranslation('base64Converter');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4 rounded-xl bg-primary/10 border border-primary/30">
|
<div className="p-4 rounded-xl bg-primary/10 border border-primary/30">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Image as ImageIcon, Trash2, Upload } from 'lucide-react';
|
import { Image as ImageIcon, Trash2, Upload } from 'lucide-react';
|
||||||
import TextInputArea from '@/components/TextInputArea';
|
import TextInputArea from '@/components/TextInputArea';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useLazyTranslation } from '@/utils/useLazyTranslation';
|
||||||
import CopyButton from '@/components/CopyButton';
|
import CopyButton from '@/components/CopyButton';
|
||||||
import DecodeResultPaper from '@/components/DecodeResultPaper';
|
import DecodeResultPaper from '@/components/DecodeResultPaper';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -19,7 +19,7 @@ interface Base64ConverterSectionProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Base64ConverterSection({ mode }: Base64ConverterSectionProps) {
|
export default function Base64ConverterSection({ mode }: Base64ConverterSectionProps) {
|
||||||
const { t } = useTranslation('base64Converter');
|
const { t } = useLazyTranslation('base64Converter');
|
||||||
|
|
||||||
const [direction, setDirection] = useStorageState(
|
const [direction, setDirection] = useStorageState(
|
||||||
`base64Converter/${mode}Mode/direction`,
|
`base64Converter/${mode}Mode/direction`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Trash2, Upload } from 'lucide-react';
|
import { Trash2, Upload } from 'lucide-react';
|
||||||
import TextInputArea from '@/components/TextInputArea';
|
import TextInputArea from '@/components/TextInputArea';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useLazyTranslation } from '@/utils/useLazyTranslation';
|
||||||
import CopyButton from '@/components/CopyButton';
|
import CopyButton from '@/components/CopyButton';
|
||||||
import DecodeResultPaper from '@/components/DecodeResultPaper';
|
import DecodeResultPaper from '@/components/DecodeResultPaper';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -15,7 +15,7 @@ const isValidDirection = (val: unknown): val is Base64ConvertDirection =>
|
|||||||
val === 'encode' || val === 'decode';
|
val === 'encode' || val === 'decode';
|
||||||
|
|
||||||
export default function FileMode() {
|
export default function FileMode() {
|
||||||
const { t } = useTranslation('base64Converter');
|
const { t } = useLazyTranslation('base64Converter');
|
||||||
const [direction, setDirection] = useStorageState(
|
const [direction, setDirection] = useStorageState(
|
||||||
'base64Converter/fileMode/direction',
|
'base64Converter/fileMode/direction',
|
||||||
'encode',
|
'encode',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Image as ImageIcon, Trash2 } from 'lucide-react';
|
import { Image as ImageIcon, Trash2 } from 'lucide-react';
|
||||||
import TextInputArea from '@/components/TextInputArea';
|
import TextInputArea from '@/components/TextInputArea';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useLazyTranslation } from '@/utils/useLazyTranslation';
|
||||||
import CopyButton from '@/components/CopyButton';
|
import CopyButton from '@/components/CopyButton';
|
||||||
import DecodeResultPaper from '@/components/DecodeResultPaper';
|
import DecodeResultPaper from '@/components/DecodeResultPaper';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -15,7 +15,7 @@ const isValidDirection = (val: unknown): val is Base64ConvertDirection =>
|
|||||||
val === 'encode' || val === 'decode';
|
val === 'encode' || val === 'decode';
|
||||||
|
|
||||||
export default function ImageMode() {
|
export default function ImageMode() {
|
||||||
const { t } = useTranslation('base64Converter');
|
const { t } = useLazyTranslation('base64Converter');
|
||||||
const [direction, setDirection] = useStorageState(
|
const [direction, setDirection] = useStorageState(
|
||||||
'base64Converter/imageMode/direction',
|
'base64Converter/imageMode/direction',
|
||||||
'encode',
|
'encode',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import TextInputArea from '@/components/TextInputArea';
|
import TextInputArea from '@/components/TextInputArea';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useLazyTranslation } from '@/utils/useLazyTranslation';
|
||||||
import CopyButton from '@/components/CopyButton';
|
import CopyButton from '@/components/CopyButton';
|
||||||
import { base64ToText, textToBase64 } from '@/utils/base64Converter';
|
import { base64ToText, textToBase64 } from '@/utils/base64Converter';
|
||||||
import SwitchButtonGroup from '@/components/SwitchButtonGroup';
|
import SwitchButtonGroup from '@/components/SwitchButtonGroup';
|
||||||
@@ -20,7 +20,7 @@ interface TextModeProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function TextMode({ onSwitchToImageMode }: TextModeProps = {}) {
|
export default function TextMode({ onSwitchToImageMode }: TextModeProps = {}) {
|
||||||
const { t } = useTranslation('base64Converter');
|
const { t } = useLazyTranslation('base64Converter');
|
||||||
|
|
||||||
// 1. 纯净的核心源状态机:只保留输入源和转换方向
|
// 1. 纯净的核心源状态机:只保留输入源和转换方向
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useLazyTranslation } from '@/utils/useLazyTranslation';
|
||||||
import type { FileToBase64Result } from '@/utils/base64Converter';
|
import type { FileToBase64Result } from '@/utils/base64Converter';
|
||||||
import {
|
import {
|
||||||
base64ToBlob,
|
base64ToBlob,
|
||||||
@@ -21,7 +21,7 @@ interface UseBase64ConverterProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useBase64Converter({ mode }: UseBase64ConverterProps) {
|
export function useBase64Converter({ mode }: UseBase64ConverterProps) {
|
||||||
const { t } = useTranslation('base64Converter');
|
const { t } = useLazyTranslation('base64Converter');
|
||||||
|
|
||||||
const [result, setResult] = useState<FileToBase64Result | null>(null);
|
const [result, setResult] = useState<FileToBase64Result | null>(null);
|
||||||
const [info, setInfo] = useState<FileInfo | null>(null);
|
const [info, setInfo] = useState<FileInfo | null>(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user