fix: i18n and lint
This commit is contained in:
parent
13747a585a
commit
16ac419b9b
@ -1,40 +1,39 @@
|
||||
|
||||
/**
|
||||
* OCOOL_API_KEY=sk-abcxxxxxxxxxxxxxxxxxxxxxxx123 ts-node scripts/update-i18n.ts
|
||||
*/
|
||||
|
||||
|
||||
// OCOOL API KEY
|
||||
const OCOOL_API_KEY = process.env.OCOOL_API_KEY;
|
||||
const OCOOL_API_KEY = process.env.OCOOL_API_KEY
|
||||
|
||||
const INDEX = [
|
||||
// 语言的名称 代码 用来翻译的模型
|
||||
{name: "France", code: "fr-fr", model: "qwen2.5-32b-instruct"},
|
||||
{name: "Spanish", code: "es-es", model: "qwen2.5-32b-instruct"},
|
||||
{name: "Portuguese", code: "pt-pt", model: "qwen2.5-72b-instruct"},
|
||||
{name: "Greek", code: "el-gr", model: "qwen-turbo" },
|
||||
{ name: 'France', code: 'fr-fr', model: 'qwen2.5-32b-instruct' },
|
||||
{ name: 'Spanish', code: 'es-es', model: 'qwen2.5-32b-instruct' },
|
||||
{ name: 'Portuguese', code: 'pt-pt', model: 'qwen2.5-72b-instruct' },
|
||||
{ name: 'Greek', code: 'el-gr', model: 'qwen-turbo' }
|
||||
]
|
||||
|
||||
const fs = require("fs");
|
||||
import OpenAI from "openai";
|
||||
const fs = require('fs')
|
||||
import OpenAI from 'openai'
|
||||
|
||||
const zh = JSON.parse(fs.readFileSync("src/renderer/src/i18n/locales/zh-cn.json", 'utf8')) as object
|
||||
const zh = JSON.parse(fs.readFileSync('src/renderer/src/i18n/locales/zh-cn.json', 'utf8')) as object
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: OCOOL_API_KEY,
|
||||
baseURL: "https://one.ocoolai.com/v1"
|
||||
});
|
||||
baseURL: 'https://one.ocoolai.com/v1'
|
||||
})
|
||||
|
||||
// 递归遍历翻译
|
||||
async function translate(zh: object, obj: object, target: string, model: string, updateFile) {
|
||||
const texts: { [key: string]: string } = {}
|
||||
for(let e in zh){
|
||||
if(typeof zh[e]=="object"){ // 遍历下一层
|
||||
if(!obj[e] || typeof obj[e]!="object") obj[e] = {}
|
||||
for (const e in zh) {
|
||||
if (typeof zh[e] == 'object') {
|
||||
// 遍历下一层
|
||||
if (!obj[e] || typeof obj[e] != 'object') obj[e] = {}
|
||||
await translate(zh[e], obj[e], target, model, updateFile)
|
||||
} else {
|
||||
// 加入到本层待翻译列表
|
||||
if(!obj[e] || typeof obj[e]!="string"){
|
||||
if (!obj[e] || typeof obj[e] != 'string') {
|
||||
texts[e] = zh[e]
|
||||
}
|
||||
}
|
||||
@ -42,9 +41,11 @@ async function translate(zh:object, obj:object, target: string, model:string, up
|
||||
if (Object.keys(texts).length > 0) {
|
||||
const completion = await openai.chat.completions.create({
|
||||
model: model,
|
||||
response_format: {type:"json_object"},
|
||||
response_format: { type: 'json_object' },
|
||||
messages: [
|
||||
{role:"user", content:`
|
||||
{
|
||||
role: 'user',
|
||||
content: `
|
||||
You are a robot specifically designed for translation tasks. As a model that has been extensively fine-tuned on Russian language corpora, you are proficient in using the Russian language.
|
||||
Now, please output the translation based on the input content. The input will include both Chinese and English key values, and you should output the corresponding key values in the Russian language.
|
||||
When translating, ensure that no key value is omitted, and maintain the accuracy and fluency of the translation. Pay attention to the capitalization rules in the output to match the source text, and especially pay attention to whether to capitalize the first letter of each word except for prepositions. For strings containing \`{{value}}\`, ensure that the format is not disrupted.
|
||||
@ -53,22 +54,28 @@ Output in JSON.
|
||||
INPUT
|
||||
######################################################
|
||||
${JSON.stringify({
|
||||
"confirm": "确定要备份数据吗?",
|
||||
"select_model": "选择模型",
|
||||
"title": "文件",
|
||||
"deeply_thought": "已深度思考(用时 {{secounds}} 秒)",
|
||||
confirm: '确定要备份数据吗?',
|
||||
select_model: '选择模型',
|
||||
title: '文件',
|
||||
deeply_thought: '已深度思考(用时 {{secounds}} 秒)'
|
||||
})}
|
||||
######################################################
|
||||
MAKE SURE TO OUTPUT IN Russian. DO NOT OUTPUT IN UNSPECIFIED LANGUAGE.
|
||||
######################################################
|
||||
`},
|
||||
{role:"assistant", content:JSON.stringify({
|
||||
"confirm": "Подтвердите резервное копирование данных?",
|
||||
"select_model": "Выберите Модель",
|
||||
"title": "Файл",
|
||||
"deeply_thought": "Глубоко продумано (заняло {{seconds}} секунд)"
|
||||
})},
|
||||
{role:"user", content:`
|
||||
`
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: JSON.stringify({
|
||||
confirm: 'Подтвердите резервное копирование данных?',
|
||||
select_model: 'Выберите Модель',
|
||||
title: 'Файл',
|
||||
deeply_thought: 'Глубоко продумано (заняло {{seconds}} секунд)'
|
||||
})
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: `
|
||||
You are a robot specifically designed for translation tasks. As a model that has been extensively fine-tuned on ${target} language corpora, you are proficient in using the ${target} language.
|
||||
Now, please output the translation based on the input content. The input will include both Chinese and English key values, and you should output the corresponding key values in the ${target} language.
|
||||
When translating, ensure that no key value is omitted, and maintain the accuracy and fluency of the translation. Pay attention to the capitalization rules in the output to match the source text, and especially pay attention to whether to capitalize the first letter of each word except for prepositions. For strings containing \`{{value}}\`, ensure that the format is not disrupted.
|
||||
@ -80,28 +87,29 @@ ${JSON.stringify(texts)}
|
||||
######################################################
|
||||
MAKE SURE TO OUTPUT IN ${target}. DO NOT OUTPUT IN UNSPECIFIED LANGUAGE.
|
||||
######################################################
|
||||
`}
|
||||
`
|
||||
}
|
||||
]
|
||||
})
|
||||
// 添加翻译后的键值,并打印错译漏译内容
|
||||
try {
|
||||
const result = JSON.parse(completion.choices[0].message.content!)
|
||||
for(let e in texts){
|
||||
for (const e in texts) {
|
||||
if (result[e] && typeof result[e] === 'string') {
|
||||
obj[e] = result[e]
|
||||
} else {
|
||||
console.log("[warning]", `missing value "${e}" in ${target} translation`)
|
||||
console.log('[warning]', `missing value "${e}" in ${target} translation`)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("[error]", e)
|
||||
for(let e in texts){
|
||||
console.log("[warning]", `missing value "${e}" in ${target} translation`)
|
||||
console.log('[error]', e)
|
||||
for (const e in texts) {
|
||||
console.log('[warning]', `missing value "${e}" in ${target} translation`)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除多余的键值
|
||||
for(let e in obj){
|
||||
for (const e in obj) {
|
||||
if (!zh[e]) {
|
||||
delete obj[e]
|
||||
}
|
||||
@ -110,8 +118,8 @@ MAKE SURE TO OUTPUT IN ${target}. DO NOT OUTPUT IN UNSPECIFIED LANGUAGE.
|
||||
updateFile()
|
||||
}
|
||||
|
||||
(async ()=>{
|
||||
for(let {name, code, model} of INDEX){
|
||||
;(async () => {
|
||||
for (const { name, code, model } of INDEX) {
|
||||
const obj = fs.existsSync(`src/renderer/src/i18n/locales/${code}.json`)
|
||||
? JSON.parse(fs.readFileSync(`src/renderer/src/i18n/locales/${code}.json`, 'utf8'))
|
||||
: {}
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { LanguageVarious } from '@renderer/types'
|
||||
import { ConfigProvider, theme } from 'antd'
|
||||
import elGR from 'antd/locale/el_GR'
|
||||
import enUS from 'antd/locale/en_US'
|
||||
import esES from 'antd/locale/es_ES'
|
||||
import frFR from 'antd/locale/fr_FR'
|
||||
import jaJP from 'antd/locale/ja_JP'
|
||||
import ptPT from 'antd/locale/pt_PT'
|
||||
import ruRU from 'antd/locale/ru_RU'
|
||||
import zhCN from 'antd/locale/zh_CN'
|
||||
import zhTW from 'antd/locale/zh_TW'
|
||||
@ -53,7 +57,14 @@ function getAntdLocale(language: LanguageVarious) {
|
||||
return ruRU
|
||||
case 'ja-JP':
|
||||
return jaJP
|
||||
|
||||
case 'el-GR':
|
||||
return elGR
|
||||
case 'es-ES':
|
||||
return esES
|
||||
case 'fr-FR':
|
||||
return frFR
|
||||
case 'pt-PT':
|
||||
return ptPT
|
||||
default:
|
||||
return zhCN
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import i18n from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
|
||||
import elGR from './locales/el-gr.json'
|
||||
import enUS from './locales/en-us.json'
|
||||
import esES from './locales/es-es.json'
|
||||
@ -19,7 +20,7 @@ const resources = {
|
||||
'pt-PT': ptPT,
|
||||
'ru-RU': ruRU,
|
||||
'zh-CN': zhCN,
|
||||
'zh-TW': zhTW,
|
||||
'zh-TW': zhTW
|
||||
}
|
||||
|
||||
export const getLanguage = () => {
|
||||
|
||||
@ -556,7 +556,7 @@
|
||||
"string": "文本"
|
||||
},
|
||||
"pinned": "已固定",
|
||||
"rerank_model": "重排序模型",
|
||||
"rerank_model": "重排模型",
|
||||
"rerank_model_support_provider": "目前重排序模型仅支持部分服务商 ({{provider}})",
|
||||
"rerank_model_tooltip": "在设置->模型服务中点击管理按钮添加",
|
||||
"search": "搜索模型...",
|
||||
|
||||
@ -565,7 +565,7 @@
|
||||
"string": "文字"
|
||||
},
|
||||
"pinned": "已固定",
|
||||
"rerank_model": "重排序模型",
|
||||
"rerank_model": "重排模型",
|
||||
"rerank_model_support_provider": "目前重排序模型僅支持部分服務商 ({{provider}})",
|
||||
"rerank_model_tooltip": "在設定->模型服務中點擊管理按鈕添加",
|
||||
"search": "搜尋模型...",
|
||||
|
||||
@ -15,8 +15,8 @@ import { UploadOutlined } from '@ant-design/icons'
|
||||
import ObsidianExportPopup from '@renderer/components/Popups/ObsidianExportPopup'
|
||||
import SelectModelPopup from '@renderer/components/Popups/SelectModelPopup'
|
||||
import TextEditPopup from '@renderer/components/Popups/TextEditPopup'
|
||||
import { TranslateLanguageOptions } from '@renderer/config/translate'
|
||||
import { isReasoningModel } from '@renderer/config/models'
|
||||
import { TranslateLanguageOptions } from '@renderer/config/translate'
|
||||
import { useMessageOperations } from '@renderer/hooks/useMessageOperations'
|
||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||
import { getMessageTitle, resetAssistantMessage } from '@renderer/services/MessagesService'
|
||||
@ -24,7 +24,6 @@ import { translateText } from '@renderer/services/TranslateService'
|
||||
import { Message, Model } from '@renderer/types'
|
||||
import { Assistant, Topic } from '@renderer/types'
|
||||
import { captureScrollableDivAsBlob, captureScrollableDivAsDataURL, removeTrailingDoubleSpaces } from '@renderer/utils'
|
||||
import { withMessageThought } from '@renderer/utils/formats'
|
||||
import {
|
||||
exportMarkdownToJoplin,
|
||||
exportMarkdownToNotion,
|
||||
@ -32,12 +31,13 @@ import {
|
||||
exportMessageAsMarkdown,
|
||||
messageToMarkdown
|
||||
} from '@renderer/utils/export'
|
||||
import { withMessageThought } from '@renderer/utils/formats'
|
||||
import { Button, Dropdown, Popconfirm, Tooltip } from 'antd'
|
||||
import dayjs from 'dayjs'
|
||||
import { clone } from 'lodash'
|
||||
import { FC, memo, useCallback, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
import { clone } from 'lodash'
|
||||
|
||||
interface Props {
|
||||
message: Message
|
||||
@ -258,7 +258,7 @@ const MessageMenubar: FC<Props> = (props) => {
|
||||
]
|
||||
}
|
||||
],
|
||||
[message, messageContainerRef, onEdit, onNewBranch, t]
|
||||
[message, messageContainerRef, onEdit, onNewBranch, t, topic.name]
|
||||
)
|
||||
|
||||
const onRegenerate = async (e: React.MouseEvent | undefined) => {
|
||||
|
||||
@ -26,8 +26,8 @@ import BeatLoader from 'react-spinners/BeatLoader'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import ChatNavigation from './ChatNavigation'
|
||||
import MessageGroup from './MessageGroup'
|
||||
import MessageAnchorLine from './MessageAnchorLine'
|
||||
import MessageGroup from './MessageGroup'
|
||||
import NarrowLayout from './NarrowLayout'
|
||||
import NewTopicButton from './NewTopicButton'
|
||||
import Prompt from './Prompt'
|
||||
|
||||
@ -24,6 +24,7 @@ import {
|
||||
setFontSize,
|
||||
setMathEngine,
|
||||
setMessageFont,
|
||||
setMessageNavigation,
|
||||
setMessageStyle,
|
||||
setMultiModelMessageStyle,
|
||||
setPasteLongTextAsFile,
|
||||
@ -31,7 +32,6 @@ import {
|
||||
setRenderInputMessageAsMarkdown,
|
||||
setShowInputEstimatedTokens,
|
||||
setShowMessageDivider,
|
||||
setMessageNavigation,
|
||||
setThoughtAutoCollapse
|
||||
} from '@renderer/store/settings'
|
||||
import { Assistant, AssistantSettings, CodeStyleVarious, ThemeMode, TranslateLanguageVarious } from '@renderer/types'
|
||||
|
||||
@ -584,10 +584,10 @@ const ModelInfo = styled.div`
|
||||
.model-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.label-column {
|
||||
width: 80px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
|
||||
@ -12,13 +12,13 @@ import {
|
||||
setWebdavSyncInterval as _setWebdavSyncInterval,
|
||||
setWebdavUser as _setWebdavUser
|
||||
} from '@renderer/store/settings'
|
||||
import { formatFileSize } from '@renderer/utils'
|
||||
import { Button, Input, Modal, Select, Spin, Tooltip } from 'antd'
|
||||
import dayjs from 'dayjs'
|
||||
import { FC, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { SettingDivider, SettingGroup, SettingRow, SettingRowTitle, SettingTitle } from '..'
|
||||
import { formatFileSize } from '@renderer/utils'
|
||||
|
||||
interface BackupFile {
|
||||
fileName: string
|
||||
|
||||
@ -96,13 +96,13 @@ const GeneralSettings: FC = () => {
|
||||
const languagesOptions: { value: LanguageVarious; label: string; flag: string }[] = [
|
||||
{ value: 'zh-CN', label: '中文', flag: '🇨🇳' },
|
||||
{ value: 'zh-TW', label: '中文(繁体)', flag: '🇭🇰' },
|
||||
{ value: 'el-GR', label: 'Ελληνικά', flag: '🇬🇷' },
|
||||
{ value: 'en-US', label: 'English', flag: '🇺🇸' },
|
||||
{ value: 'ja-JP', label: '日本語', flag: '🇯🇵' },
|
||||
{ value: 'ru-RU', label: 'Русский', flag: '🇷🇺' },
|
||||
{ value: 'el-GR', label: 'Ελληνικά', flag: '🇬🇷' },
|
||||
{ value: 'es-ES', label: 'Español', flag: '🇪🇸' },
|
||||
{ value: 'fr-FR', label: 'Français', flag: '🇫🇷' },
|
||||
{ value: 'ja-JP', label: '日本語', flag: '🇯🇵' },
|
||||
{ value: 'pt-PT', label: 'Português', flag: '🇵🇹' },
|
||||
{ value: 'ru-RU', label: 'Русский', flag: '🇷🇺' }
|
||||
{ value: 'pt-PT', label: 'Português', flag: '🇵🇹' }
|
||||
]
|
||||
|
||||
return (
|
||||
|
||||
@ -168,7 +168,6 @@ const initialState: SettingsState = {
|
||||
obsidianTages: '',
|
||||
joplinToken: '',
|
||||
joplinUrl: ''
|
||||
|
||||
}
|
||||
|
||||
const settingsSlice = createSlice({
|
||||
|
||||
@ -201,7 +201,16 @@ export enum ThemeMode {
|
||||
|
||||
export type LanguageVarious = 'zh-CN' | 'zh-TW' | 'el-GR' | 'en-US' | 'es-ES' | 'fr-FR' | 'ja-JP' | 'pt-PT' | 'ru-RU'
|
||||
|
||||
export type TranslateLanguageVarious = 'chinese' | 'chinese-traditional' | 'greek' | 'english' | 'spanish' | 'french' | 'japanese' | 'portuguese' | 'russian'
|
||||
export type TranslateLanguageVarious =
|
||||
| 'chinese'
|
||||
| 'chinese-traditional'
|
||||
| 'greek'
|
||||
| 'english'
|
||||
| 'spanish'
|
||||
| 'french'
|
||||
| 'japanese'
|
||||
| 'portuguese'
|
||||
| 'russian'
|
||||
|
||||
export type CodeStyleVarious = BuiltinTheme | 'auto'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user