Skip to content

Commit

Permalink
【Task 1】Refactor the existing multiple languages feature by adopting …
Browse files Browse the repository at this point in the history
…a third i18n library (#826)

* refactor i18n options

* refactor i18n in fork, star, pr, issue, perceptor

* refactor i18n in ossgpt, header_label, developer

* deleted some unnecessary files

* optimize and simplify code

* fix header labels issue
  • Loading branch information
taketaketakeru authored Jul 5, 2024
1 parent d1a99cd commit 902e28d
Show file tree
Hide file tree
Showing 23 changed files with 488 additions and 963 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
"echarts": "^5.3.0",
"element-ready": "^6.2.1",
"github-url-detection": "^8.1.0",
"i18next": "^23.11.5",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-http-backend": "^2.5.2",
"jquery": "^3.6.0",
"lodash-es": "^4.17.21",
"moment": "^2.30.1",
"react": "^17.0.2",
"react-chat-widget": "^3.1.4",
"react-dom": "^17.0.2",
"react-hot-loader": "^4.13.0",
"react-i18next": "^14.1.2",
"react-modal": "3.15.1",
"strip-indent": "^4.0.0"
},
Expand Down
12 changes: 0 additions & 12 deletions src/helpers/get-message-by-locale.ts

This file was deleted.

36 changes: 36 additions & 0 deletions src/helpers/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-http-backend';
import messages_en from '../locales/en/translation.json';
import messages_zh_CN from '../locales/zh_CN/translation.json';

const language_resources = {
zh_CN: {
translation: messages_zh_CN,
},
en: {
translation: messages_en,
},
};

i18n
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(Backend)
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
debug: false,
fallbackLng: 'en',
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
skipOnVariables: false,
},
resources: language_resources,
});

export default i18n;
Loading

0 comments on commit 902e28d

Please sign in to comment.