feat: translation (#389)

This commit is contained in:
Cody Tseng 2025-06-23 23:52:21 +08:00 committed by GitHub
parent e2e115ebeb
commit df9066eae0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 1466 additions and 47 deletions

View file

@ -7,7 +7,8 @@ import {
TFeedInfo,
TNoteListMode,
TRelaySet,
TThemeSetting
TThemeSetting,
TTranslationServiceConfig
} from '@/types'
class LocalStorageService {
@ -27,6 +28,7 @@ class LocalStorageService {
private autoplay: boolean = true
private hideUntrustedInteractions: boolean = false
private hideUntrustedNotifications: boolean = false
private translationServiceConfigMap: Record<string, TTranslationServiceConfig> = {}
constructor() {
if (!LocalStorageService.instance) {
@ -109,6 +111,13 @@ class LocalStorageService {
? storedHideUntrustedNotifications === 'true'
: hideUntrustedEvents
const translationServiceConfigMapStr = window.localStorage.getItem(
StorageKey.TRANSLATION_SERVICE_CONFIG_MAP
)
if (translationServiceConfigMapStr) {
this.translationServiceConfigMap = JSON.parse(translationServiceConfigMapStr)
}
// Clean up deprecated data
window.localStorage.removeItem(StorageKey.ACCOUNT_PROFILE_EVENT_MAP)
window.localStorage.removeItem(StorageKey.ACCOUNT_FOLLOW_LIST_EVENT_MAP)
@ -290,6 +299,18 @@ class LocalStorageService {
hideUntrustedNotifications.toString()
)
}
getTranslationServiceConfig(pubkey?: string | null) {
return this.translationServiceConfigMap[pubkey ?? '_'] ?? { service: 'jumble' }
}
setTranslationServiceConfig(config: TTranslationServiceConfig, pubkey?: string | null) {
this.translationServiceConfigMap[pubkey ?? '_'] = config
window.localStorage.setItem(
StorageKey.TRANSLATION_SERVICE_CONFIG_MAP,
JSON.stringify(this.translationServiceConfigMap)
)
}
}
const instance = new LocalStorageService()