aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeJun <kejun1997@gmail.com>2021-07-17 23:03:14 +0800
committerGitHub <noreply@github.com>2021-07-17 08:03:14 -0700
commitb0ee18a9c0f16517aa87f8b58df55286af2f04f1 (patch)
tree647bf1665763a19a6683f9c4e1c5e2278b4ee6cd
parente5a1f300fff1ceb0f89de2b2a93fe2f4096803c8 (diff)
feat: add language detector (#67)
* feat: add language detector * style: fmt code
-rw-r--r--package.json1
-rw-r--r--src/App.js7
-rw-r--r--src/i18n.js6
3 files changed, 10 insertions, 4 deletions
diff --git a/package.json b/package.json
index e35ddc8..d043ec8 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
7 "@testing-library/react": "^9.3.2", 7 "@testing-library/react": "^9.3.2",
8 "@testing-library/user-event": "^7.1.2", 8 "@testing-library/user-event": "^7.1.2",
9 "i18next": "^20.3.3", 9 "i18next": "^20.3.3",
10 "i18next-browser-languagedetector": "^6.1.2",
10 "qrcode.react": "^1.0.0", 11 "qrcode.react": "^1.0.0",
11 "react": "^16.13.1", 12 "react": "^16.13.1",
12 "react-dom": "^16.13.1", 13 "react-dom": "^16.13.1",
diff --git a/src/App.js b/src/App.js
index f195431..0e975fb 100644
--- a/src/App.js
+++ b/src/App.js
@@ -16,9 +16,12 @@ function App() {
16 16
17 <div> 17 <div>
18 <label>{t('select')}</label> 18 <label>{t('select')}</label>
19 <select onChange={(e) => i18n.changeLanguage(e.target.value)}> 19 <select
20 value={i18n.language}
21 onChange={(e) => i18n.changeLanguage(e.target.value)}
22 >
20 <option value="en-US">en-US</option> 23 <option value="en-US">en-US</option>
21 <option value="简体中文">简体中文</option> 24 <option value="zh-CN">简体中文</option>
22 <option value="es">es</option> 25 <option value="es">es</option>
23 <option value="pt">Português</option> 26 <option value="pt">Português</option>
24 </select> 27 </select>
diff --git a/src/i18n.js b/src/i18n.js
index e0c267d..26b0cc0 100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -1,5 +1,6 @@
1import i18n from 'i18next'; 1import i18n from 'i18next';
2import { initReactI18next } from 'react-i18next'; 2import { initReactI18next } from 'react-i18next';
3import LanguageDetector from 'i18next-browser-languagedetector';
3 4
4const resources = { 5const resources = {
5 'en-US': { 6 'en-US': {
@@ -27,7 +28,7 @@ const resources = {
27 select: 'Select Language', 28 select: 'Select Language',
28 }, 29 },
29 }, 30 },
30 简体中文: { 31 'zh-CN': {
31 translation: { 32 translation: {
32 title: 'WiFi 连接卡', 33 title: 'WiFi 连接卡',
33 'desc.use': 34 'desc.use':
@@ -107,10 +108,11 @@ const resources = {
107 108
108i18n.use(initReactI18next).init({ 109i18n.use(initReactI18next).init({
109 resources, 110 resources,
110 lng: 'en-US',
111 interpolation: { 111 interpolation: {
112 escapeValue: false, 112 escapeValue: false,
113 }, 113 },
114}); 114});
115 115
116i18n.use(LanguageDetector).init();
117
116export default i18n; 118export default i18n;