fix: default assistant name empty

This commit is contained in:
kangfenmao 2024-07-15 17:22:51 +08:00
parent b487c68822
commit ec49cf61d6
6 changed files with 39 additions and 8 deletions

View File

@ -94,7 +94,9 @@ app.whenReady().then(() => {
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err))
if (app.isPackaged) {
setTimeout(() => new AppUpdater(), 3000)
}
})
// Quit when all windows are closed, except on macOS. There, it's common

View File

@ -225,7 +225,7 @@ const resources = {
i18n.use(initReactI18next).init({
resources,
lng: localStorage.getItem('language') || 'en-US',
lng: localStorage.getItem('language') || navigator.language || 'en-US',
fallbackLng: 'en-US',
interpolation: {
escapeValue: false

View File

@ -1,13 +1,13 @@
import changelogEn from '@renderer/assets/changelog/CHANGELOG.en.md?raw'
import changelogZh from '@renderer/assets/changelog/CHANGELOG.zh.md?raw'
import i18next from 'i18next'
import { FC } from 'react'
import Markdown from 'react-markdown'
import styled from 'styled-components'
import styles from '@renderer/assets/styles/changelog.module.scss'
import i18n from '@renderer/i18n'
const Changelog: FC = () => {
const language = i18next.language
const language = i18n.language
const changelog = language === 'zh-CN' ? changelogZh : changelogEn
return (

View File

@ -1,12 +1,12 @@
import { Assistant, Model, Provider, Topic } from '@renderer/types'
import store from '@renderer/store'
import { uuid } from '@renderer/utils'
import i18next from 'i18next'
import i18n from '@renderer/i18n'
export function getDefaultAssistant(): Assistant {
return {
id: 'default',
name: i18next.t('assistant.default.name'),
name: i18n.t('assistant.default.name'),
prompt: '',
topics: [getDefaultTopic()]
}
@ -15,7 +15,7 @@ export function getDefaultAssistant(): Assistant {
export function getDefaultTopic(): Topic {
return {
id: uuid(),
name: i18next.t('assistant.default.topic.name'),
name: i18n.t('assistant.default.topic.name'),
messages: []
}
}

View File

@ -19,7 +19,7 @@ const persistedReducer = persistReducer(
{
key: 'cherry-studio',
storage,
version: 7,
version: 8,
blacklist: ['runtime'],
migrate
},

View File

@ -1,6 +1,9 @@
import { createMigrate } from 'redux-persist'
import { RootState } from '.'
import { SYSTEM_MODELS } from '@renderer/config/models'
import { isEmpty } from 'lodash'
import i18n from '@renderer/i18n'
import { Assistant } from '@renderer/types'
const migrate = createMigrate({
// @ts-ignore store type is unknown
@ -112,6 +115,32 @@ const migrate = createMigrate({
language: navigator.language
}
}
},
// @ts-ignore store type is unknown
'8': (state: RootState) => {
const fixAssistantName = (assistant: Assistant) => {
if (isEmpty(assistant.name)) {
assistant.name = i18n.t(`assistant.${assistant.id}.name`)
}
assistant.topics = assistant.topics.map((topic) => {
if (isEmpty(topic.name)) {
topic.name = i18n.t(`assistant.${assistant.id}.topic.name`)
}
return topic
})
return assistant
}
return {
...state,
assistants: {
...state.assistants,
defaultAssistant: fixAssistantName(state.assistants.defaultAssistant),
assistants: state.assistants.assistants.map((assistant) => fixAssistantName(assistant))
}
}
}
})