balibabu commited on
Commit
0711582
·
1 Parent(s): 036238f

Default language will be given according to the browse setting and also can be configured #801 (#823)

Browse files

### What problem does this PR solve?

Default language will be given according to the browse setting and also
can be configured #801
### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/package-lock.json CHANGED
@@ -17,6 +17,7 @@
17
  "dayjs": "^1.11.10",
18
  "eventsource-parser": "^1.1.2",
19
  "i18next": "^23.7.16",
 
20
  "js-base64": "^3.7.5",
21
  "jsencrypt": "^3.3.2",
22
  "lodash": "^4.17.21",
@@ -11732,6 +11733,14 @@
11732
  "@babel/runtime": "^7.23.2"
11733
  }
11734
  },
 
 
 
 
 
 
 
 
11735
  "node_modules/iconv-lite": {
11736
  "version": "0.6.3",
11737
  "resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.6.3.tgz",
 
17
  "dayjs": "^1.11.10",
18
  "eventsource-parser": "^1.1.2",
19
  "i18next": "^23.7.16",
20
+ "i18next-browser-languagedetector": "^8.0.0",
21
  "js-base64": "^3.7.5",
22
  "jsencrypt": "^3.3.2",
23
  "lodash": "^4.17.21",
 
11733
  "@babel/runtime": "^7.23.2"
11734
  }
11735
  },
11736
+ "node_modules/i18next-browser-languagedetector": {
11737
+ "version": "8.0.0",
11738
+ "resolved": "https://registry.npmmirror.com/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.0.0.tgz",
11739
+ "integrity": "sha512-zhXdJXTTCoG39QsrOCiOabnWj2jecouOqbchu3EfhtSHxIB5Uugnm9JaizenOy39h7ne3+fLikIjeW88+rgszw==",
11740
+ "dependencies": {
11741
+ "@babel/runtime": "^7.23.2"
11742
+ }
11743
+ },
11744
  "node_modules/iconv-lite": {
11745
  "version": "0.6.3",
11746
  "resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.6.3.tgz",
web/package.json CHANGED
@@ -21,6 +21,7 @@
21
  "dayjs": "^1.11.10",
22
  "eventsource-parser": "^1.1.2",
23
  "i18next": "^23.7.16",
 
24
  "js-base64": "^3.7.5",
25
  "jsencrypt": "^3.3.2",
26
  "lodash": "^4.17.21",
 
21
  "dayjs": "^1.11.10",
22
  "eventsource-parser": "^1.1.2",
23
  "i18next": "^23.7.16",
24
+ "i18next-browser-languagedetector": "^8.0.0",
25
  "js-base64": "^3.7.5",
26
  "jsencrypt": "^3.3.2",
27
  "lodash": "^4.17.21",
web/src/locales/config.ts CHANGED
@@ -1,4 +1,5 @@
1
  import i18n from 'i18next';
 
2
  import { initReactI18next } from 'react-i18next';
3
 
4
  import translation_en from './en';
@@ -11,13 +12,19 @@ const resources = {
11
  'zh-TRADITIONAL': translation_zh_traditional,
12
  };
13
 
14
- i18n.use(initReactI18next).init({
15
- resources,
16
- lng: 'en',
17
- fallbackLng: 'en',
18
- interpolation: {
19
- escapeValue: false,
20
- },
21
- });
 
 
 
 
 
 
22
 
23
  export default i18n;
 
1
  import i18n from 'i18next';
2
+ import LanguageDetector from 'i18next-browser-languagedetector';
3
  import { initReactI18next } from 'react-i18next';
4
 
5
  import translation_en from './en';
 
12
  'zh-TRADITIONAL': translation_zh_traditional,
13
  };
14
 
15
+ i18n
16
+ .use(initReactI18next)
17
+ .use(LanguageDetector)
18
+ .init({
19
+ detection: {
20
+ lookupLocalStorage: 'lng',
21
+ },
22
+ supportedLngs: ['en', 'zh', 'zh-TRADITIONAL'],
23
+ resources,
24
+ fallbackLng: 'en',
25
+ interpolation: {
26
+ escapeValue: false,
27
+ },
28
+ });
29
 
30
  export default i18n;