Patch bad migration, sanitize bad value (#2179)
parent
3592f6f50b
commit
bae63f9bf0
|
@ -84,3 +84,15 @@ export function getTranslatorLink(text: string, lang: string): string {
|
|||
text,
|
||||
)}`
|
||||
}
|
||||
|
||||
export function sanitizeAppLanguageSetting(appLanguage: string) {
|
||||
const langs = appLanguage.split(',').filter(Boolean)
|
||||
|
||||
for (const lang of langs) {
|
||||
if (['en', 'hi'].includes(lang)) {
|
||||
return lang
|
||||
}
|
||||
}
|
||||
|
||||
return 'en'
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import {i18n} from '@lingui/core'
|
|||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
import {messages as messagesEn} from '#/locale/locales/en/messages'
|
||||
import {messages as messagesHi} from '#/locale/locales/hi/messages'
|
||||
import {sanitizeAppLanguageSetting} from '#/locale/helpers'
|
||||
|
||||
export const locales = {
|
||||
en: 'English',
|
||||
|
@ -26,6 +27,6 @@ export async function dynamicActivate(locale: string) {
|
|||
export async function useLocaleLanguage() {
|
||||
const {appLanguage} = useLanguagePrefs()
|
||||
useEffect(() => {
|
||||
dynamicActivate(appLanguage)
|
||||
dynamicActivate(sanitizeAppLanguageSetting(appLanguage))
|
||||
}, [appLanguage])
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import {useEffect} from 'react'
|
|||
import {i18n} from '@lingui/core'
|
||||
|
||||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
import {sanitizeAppLanguageSetting} from '#/locale/helpers'
|
||||
|
||||
export const locales = {
|
||||
en: 'English',
|
||||
|
@ -29,6 +30,6 @@ export async function dynamicActivate(locale: string) {
|
|||
export async function useLocaleLanguage() {
|
||||
const {appLanguage} = useLanguagePrefs()
|
||||
useEffect(() => {
|
||||
dynamicActivate(appLanguage)
|
||||
dynamicActivate(sanitizeAppLanguageSetting(appLanguage))
|
||||
}, [appLanguage])
|
||||
}
|
||||
|
|
|
@ -94,7 +94,8 @@ export function transform(legacy: Partial<LegacySchema>): Schema {
|
|||
legacy.preferences?.postLanguageHistory ||
|
||||
defaults.languagePrefs.postLanguageHistory,
|
||||
appLanguage:
|
||||
legacy.preferences?.postLanguage || defaults.languagePrefs.appLanguage,
|
||||
legacy.preferences?.primaryLanguage ||
|
||||
defaults.languagePrefs.appLanguage,
|
||||
},
|
||||
requireAltTextEnabled:
|
||||
legacy.preferences?.requireAltTextEnabled ||
|
||||
|
|
Loading…
Reference in New Issue