File tree Expand file tree Collapse file tree 5 files changed +14
-6
lines changed
Expand file tree Collapse file tree 5 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,15 @@ import { useEffect, useState } from 'react';
22import { CodeBlockData } from 'markdown-react-code-preview-loader' ;
33import { useTranslation } from 'react-i18next' ;
44
5- const useMdData = ( path : ( lang : string ) => Promise < { default : CodeBlockData } > ) => {
5+ const useMdData = ( path : ( lang : string ) => Promise < { default : CodeBlockData } > , name : string = 'language' ) => {
66 const init = useTranslation ( ) ;
77 const [ mdData , setMdData ] = useState < CodeBlockData > ( {
88 source : '' ,
99 components : { } ,
1010 codeBlock : { } ,
1111 languages : { } ,
1212 } ) ;
13- const lang = init . t ( 'language' ) ;
13+ const lang = init . t ( name ) ;
1414 useEffect ( ( ) => {
1515 const getMd = async ( ) => {
1616 try {
Original file line number Diff line number Diff line change @@ -6,9 +6,11 @@ import LanguageData from './language.json';
66// or even better, manage them separated from your code: https://react.i18next.com/guides/multiple-translation-files)
77const resources : Record < string , { translation : { language : string } } > = { } ;
88Object . entries ( LanguageData ) . forEach ( ( [ key , item ] ) => {
9+ const { value, label, ...rest } = item ;
910 resources [ key ] = {
1011 translation : {
1112 language : item . value ,
13+ ...rest ,
1214 } ,
1315 } ;
1416} ) ;
Original file line number Diff line number Diff line change 11{
22 "zh" : {
33 "label" : " 中文" ,
4- "value" : " -zh"
4+ "value" : " -zh" ,
5+ "markdown-react-code-preview-loader" : " README-zh" ,
6+ "App" : " App-zh"
57 },
68 "en" : {
79 "label" : " 英文" ,
8- "value" : " "
10+ "value" : " " ,
11+ "markdown-react-code-preview-loader" : " README" ,
12+ "App" : " App"
913 }
1014}
Original file line number Diff line number Diff line change 11import MarkdownPreview from '@uiw/react-markdown-preview' ;
22import useMdData from './../../components/useMdData' ;
33export function HomePage ( ) {
4- const mdData = useMdData ( ( lang ) => import ( `markdown-react-code-preview-loader/README${ lang } .md` ) ) ;
4+ const mdData = useMdData ( ( path ) => {
5+ return import ( `markdown-react-code-preview-loader/${ path } .md` ) ;
6+ } , 'markdown-react-code-preview-loader' ) ;
57 return < MarkdownPreview source = { mdData . source } /> ;
68}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ const getMetaData = (meta: string) => {
1414} ;
1515
1616export function ExamplePage ( ) {
17- const mdData = useMdData ( ( lang ) => import ( `./App ${ lang } .md` ) ) ;
17+ const mdData = useMdData ( ( path ) => import ( `./${ path } .md` ) , 'App' ) ;
1818 return (
1919 < div >
2020 < MarkdownPreview
You can’t perform that action at this time.
0 commit comments