Skip to content

Commit

Permalink
feat: i18next fix webpack json
Browse files Browse the repository at this point in the history
  • Loading branch information
wkylin committed Nov 14, 2023
1 parent f05d09c commit 4d3d1de
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
16 changes: 6 additions & 10 deletions src/i18next.js → src/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import i18n from 'i18next'
// import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
import translationInZh from '../locales/zh/translation.json'
import translationInEn from '../locales/en/translation.json'
// import translationInZh from '../locales/zh/translation'
// import translationInEn from '../locales/en/translation'

i18n
// .use(Backend)
Expand All @@ -13,18 +17,10 @@ i18n
// },
resources: {
en: {
translation: {
demo: 'Demo',
lang: 'En',
home: 'Home',
},
translation: translationInEn,
},
zh: {
translation: {
demo: '演示',
lang: 'ZH',
home: '首页',
},
translation: translationInZh,
},
},
lng: 'zh',
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client'
import { I18nextProvider } from 'react-i18next'
import ThemeIndex from './theme'
import { ProThemeProvider } from './theme/hooks'
import i18n from './i18next'
import i18n from './i18n/i18n'

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLDivElement)

Expand Down
7 changes: 7 additions & 0 deletions src/locales/en/translation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const en = {
demo: 'Demo',
lang: 'En',
home: 'Home',
}

export default en
5 changes: 5 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"demo": "Demo",
"lang": "En",
"home": "Home"
}
7 changes: 7 additions & 0 deletions src/locales/zh/translation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const zh = {
demo: '演示',
lang: 'ZH',
home: '首页',
}

export default zh
5 changes: 5 additions & 0 deletions src/locales/zh/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"demo": "演示",
"lang": "ZH",
"home": "首页"
}
8 changes: 0 additions & 8 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,6 @@ const config = {
},
],
},
{
test: /\.json$/,
type: 'asset/resource', // 将json文件视为文件类型
generator: {
// 这里专门针对json文件的处理
filename: 'static/json/[name].[hash][ext][query]',
},
},
],
},
}
Expand Down

1 comment on commit 4d3d1de

@vercel
Copy link

@vercel vercel bot commented on 4d3d1de Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pro-react-admin – ./

pro-react-admin-wkylin.vercel.app
pro-react-admin.vercel.app
pro-react-admin-git-main-wkylin.vercel.app

Please sign in to comment.