mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
feat: updates
This commit is contained in:
parent
a1b0bcf4d3
commit
884f3df41a
198 changed files with 4572 additions and 5336 deletions
43
packages/web/i18n/i18n.ts
Normal file
43
packages/web/i18n/i18n.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import i18next from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
import zhCN from './locales/zh-cn.json'
|
||||
import enUS from './locales/en-us.json'
|
||||
import { subscribe } from 'valtio'
|
||||
import settings from '../states/settings'
|
||||
|
||||
export const supportedLanguages = ['zh-CN', 'en-US'] as const
|
||||
|
||||
export const getLanguage = () => {
|
||||
// Get language from settings
|
||||
try {
|
||||
const settings = JSON.parse(localStorage.getItem('settings') || '{}')
|
||||
if (supportedLanguages.includes(settings.language)) {
|
||||
return settings.language
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Get language from browser
|
||||
if (navigator.language.startsWith('zh-')) {
|
||||
return 'zh-CN'
|
||||
}
|
||||
|
||||
// Fallback to English
|
||||
return 'en-US'
|
||||
}
|
||||
|
||||
i18next.use(initReactI18next).init({
|
||||
resources: {
|
||||
'en-US': { translation: enUS },
|
||||
'zh-CN': { translation: zhCN },
|
||||
},
|
||||
lng: getLanguage(),
|
||||
// lng: 'zh-CN',
|
||||
fallbackLng: 'en-US',
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
})
|
||||
|
||||
export default i18next
|
||||
Loading…
Add table
Add a link
Reference in a new issue