mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 18:56:17 +01:00
login i18n & chart loading & fix forgot pass page (#236)
Co-authored-by: hank <hank@henrygd.me>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
|
||||
import en from '../locales/en/translation.json';
|
||||
import es from '../locales/es/translation.json';
|
||||
@@ -10,8 +9,32 @@ import ru from '../locales/ru/translation.json';
|
||||
import zhHans from '../locales/zh-CN/translation.json';
|
||||
import zhHant from '../locales/zh-HK/translation.json';
|
||||
|
||||
// Custom language detector to use localStorage
|
||||
const languageDetector: any = {
|
||||
type: 'languageDetector',
|
||||
async: true,
|
||||
detect: (callback: (lng: string) => void) => {
|
||||
const savedLanguage = localStorage.getItem('i18nextLng');
|
||||
const fallbackLanguage = (()=>{
|
||||
switch (navigator.language) {
|
||||
case 'zh-CN': case 'zh-SG': case 'zh-MY': case 'zh': case 'zh-Hans':
|
||||
return 'zh-CN';
|
||||
case 'zh-HK': case 'zh-TW': case 'zh-MO': case 'zh-Hant':
|
||||
return 'zh-HK';
|
||||
default:
|
||||
return navigator.language;
|
||||
}
|
||||
})();
|
||||
callback(savedLanguage || fallbackLanguage);
|
||||
},
|
||||
init: () => {},
|
||||
cacheUserLanguage: (lng: string) => {
|
||||
localStorage.setItem('i18nextLng', lng);
|
||||
}
|
||||
};
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
.use(languageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources: {
|
||||
|
||||
Reference in New Issue
Block a user