Skip to content

Commit

Permalink
feat: 国际化
Browse files Browse the repository at this point in the history
  • Loading branch information
wkylin committed Nov 14, 2023
1 parent 7261660 commit f05d09c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ APP_BASE_URL=
DEPLOYED_ENV=Local
VITE_GREETINGS=Development
AUTH_USER=wkylin.w
AUTH_PASSWORD=wkylin.w
AUTH_PASSWORD=wkylin.w
PUBLIC_URL=''
5 changes: 4 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ APP_BASE_URL=
DEPLOYED_ENV=Prod
VITE_GREETINGS=Production
AUTH_USER=wkylin.w
AUTH_PASSWORD=wkylin.w
AUTH_PASSWORD=wkylin.w
# github pages
# PUBLIC_URL='/pro-react-admin'
PUBLIC_URL=''
28 changes: 22 additions & 6 deletions src/i18next.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import i18n from 'i18next'
import Backend from 'i18next-http-backend'
// import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'

i18n
.use(Backend)
// .use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
backend: {
loadPath: '/locales/{{lng}}/{{ns}}.json',
// backend: {
// loadPath: `${process.env.PUBLIC_URL}/locales/{{lng}}/{{ns}}.json`,
// },
resources: {
en: {
translation: {
demo: 'Demo',
lang: 'En',
home: 'Home',
},
},
zh: {
translation: {
demo: '演示',
lang: 'ZH',
home: '首页',
},
},
},
lng: 'zh',
fallbackLng: 'zh', // 默认语言
debug: process.env.NODE_ENV === 'production', // 开启调试模式
fallbackLng: 'en', // 默认语言
debug: process.env.NODE_ENV !== 'production', // 开启调试模式
interpolation: {
escapeValue: false, // 不转义特殊字符
},
Expand Down

1 comment on commit f05d09c

@vercel
Copy link

@vercel vercel bot commented on f05d09c 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-git-main-wkylin.vercel.app
pro-react-admin.vercel.app
pro-react-admin-wkylin.vercel.app

Please sign in to comment.