Skip to content

Commit eb82a69

Browse files
authored
Merge pull request #5 from wanniwa/3.0.0
3.0.0
2 parents cb864aa + 27af974 commit eb82a69

101 files changed

Lines changed: 21521 additions & 1611 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
.idea
2+
.vscode
23
.venv
34
/dist
45
/build
56
AppData
67
/log
8+
__pycache__
9+
.DS_Store
10+
dist.zip

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ If my tool has been helpful for your translation work, I would appreciate it if
5858
4. click Generate button
5959
5. After completing the generation, a mod translation package will be generated
6060

61+
## Changelog
62+
63+
- **3.0.0**
64+
- **Translation model**: Fully revamped translation model support, bringing better quality, stability and compatibility.
65+
- **Core**: Optimized the translation workflow to better cooperate with the new models.
66+
- **Other**: Minor experience improvements and bug fixes.
67+
6168
## Support framework
6269
1. [CP] Content Patcher
6370
2. [i18n] i18n/default.json

Transtar.spec

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
from PyInstaller.utils.hooks import collect_all
3+
4+
datas = []
5+
binaries = []
6+
hiddenimports = ['sklearn', 'PySide6-Fluent-Widgets~=1.10.4', 'pyside6~=6.10.1', 'hjson~=3.1.0', 'translatepy~=2.3', 'rich~=14.2.0', 'deepl~=1.27.0', 'packaging>=25.0', 'appdirs', '', 'google-genai', 'openai', 'boto3', 'cohere', 'anthropic', 'tiktoken']
7+
tmp_ret = collect_all('sklearn')
8+
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
9+
10+
11+
a = Analysis(
12+
['main.py'],
13+
pathex=[],
14+
binaries=binaries,
15+
datas=datas,
16+
hiddenimports=hiddenimports,
17+
hookspath=[],
18+
hooksconfig={},
19+
runtime_hooks=[],
20+
excludes=['jaxlib'],
21+
noarchive=False,
22+
optimize=0,
23+
)
24+
pyz = PYZ(a.pure)
25+
26+
exe = EXE(
27+
pyz,
28+
a.scripts,
29+
[],
30+
exclude_binaries=True,
31+
name='Transtar',
32+
debug=False,
33+
bootloader_ignore_signals=False,
34+
strip=False,
35+
upx=True,
36+
console=False,
37+
disable_windowed_traceback=False,
38+
argv_emulation=False,
39+
target_arch=None,
40+
codesign_identity=None,
41+
entitlements_file=None,
42+
icon=['app/resource/images/icon.icns'],
43+
)
44+
coll = COLLECT(
45+
exe,
46+
a.binaries,
47+
a.datas,
48+
strip=False,
49+
upx=True,
50+
upx_exclude=[],
51+
name='Transtar',
52+
)
53+
app = BUNDLE(
54+
coll,
55+
name='Transtar.app',
56+
icon='./app/resource/images/icon.icns',
57+
bundle_identifier=None,
58+
)

app/api/paratranz/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List, Dict
2-
from ...common.config import cfg
2+
from ...common.config import appConfig
33
from ..base import BaseAPI
44
from .exceptions import ParatranzAPIError
55
import wjson
@@ -12,17 +12,17 @@ class ParatranzAPI(BaseAPI):
1212

1313
def get_headers(self) -> Dict[str, str]:
1414
"""获取请求头"""
15-
if not cfg.paratranz_token.value:
15+
if not appConfig.paratranz_token.value:
1616
raise ParatranzAPIError("Paratranz token not configured")
1717
return {
18-
'Authorization': cfg.paratranz_token.value,
18+
'Authorization': appConfig.paratranz_token.value,
1919
}
2020

2121
def _get_project_id(self) -> str:
2222
"""获取项目ID"""
23-
if not cfg.paratranz_project_id.value:
23+
if not appConfig.paratranz_project_id.value:
2424
raise ParatranzAPIError("Paratranz project ID not configured")
25-
return cfg.paratranz_project_id.value
25+
return appConfig.paratranz_project_id.value
2626

2727
def get_project_files(self) -> List[dict]:
2828
"""获取项目文件列表"""

app/common/config.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# coding:utf-8
2+
import json
3+
import os
24
import sys
35
from enum import Enum
46

57
from PySide6.QtCore import QLocale
68
from qfluentwidgets import (qconfig, QConfig, ConfigItem, OptionsConfigItem, BoolValidator,
79
OptionsValidator, Theme, ConfigSerializer, RangeConfigItem, RangeValidator)
810

9-
from .setting import CONFIG_FILE
11+
from .setting import CONFIG_FILE, TRANS_CONFIG_FILE
1012
from .constant import LANGUAGES
1113

12-
models = ['google', 'deepl', 'gpt-3.5-turbo', 'gpt-4', 'gpt-4-turbo-2024-04-09', 'gpt-4o', 'gpt-4o-mini', 'custom model']
13-
1414

1515
class Language(Enum):
1616
""" Language enumeration """
@@ -46,16 +46,6 @@ class Config(QConfig):
4646
""" Config of application """
4747
i18n_extract_cp = ConfigItem("Translation", "i18n_extract_cp", False, BoolValidator())
4848
i18n_source_flag = ConfigItem("Translation", "i18n_source_flag", False, BoolValidator())
49-
trans_model = OptionsConfigItem("Translation", "trans_model", "google", OptionsValidator(models))
50-
ai_base_url = OptionsConfigItem("Translation", "ai_base_url", "")
51-
trans_custom_model = OptionsConfigItem("Translation", "trans_custom_model", "")
52-
53-
ai_batch_size = RangeConfigItem("Translation", "ai_batch_size", 5, RangeValidator(1, 50))
54-
thread_count = RangeConfigItem("Translation", "thread_count", 5, RangeValidator(1, 20))
55-
ai_prompt = ConfigItem("Translation", "ai_prompt",
56-
"You are currently a professional Stardew Valley mod translator. ", None)
57-
api_key = ConfigItem("Translation", "api_key", "", None)
58-
5949
source_language = OptionsConfigItem(
6050
"Translation", "source_language", LANGUAGES['English'], OptionsValidator(LANGUAGES.values()), restart=False)
6151
to_language = OptionsConfigItem(
@@ -71,7 +61,29 @@ class Config(QConfig):
7161
# 本地字典界面每页显示条数
7262
localDictPageSize = ConfigItem("LocalDict", "pageSize", 100)
7363

64+
# 任务设置
65+
trans_platform = ConfigItem("TaskSettings", "trans_platform", "google", None)
66+
task_prompt = ConfigItem("TaskSettings", "prompt", "You are currently a professional Stardew Valley mod translator.", None)
67+
task_split_mode = OptionsConfigItem("TaskSettings", "split_mode", "token", OptionsValidator(["token", "count"]))
68+
task_split_token_limit = RangeConfigItem("TaskSettings", "split_token_limit", 3000, RangeValidator(100, 200000))
69+
task_token_reserve = RangeConfigItem("TaskSettings", "token_reserve", 512, RangeValidator(0, 20000))
70+
task_split_count_limit = RangeConfigItem("TaskSettings", "split_count_limit", 20, RangeValidator(1, 500))
71+
task_concurrency = RangeConfigItem("TaskSettings", "concurrency", 0, RangeValidator(0, 100))
72+
task_request_timeout = RangeConfigItem("TaskSettings", "request_timeout", 120, RangeValidator(10, 3600))
73+
task_max_rounds = RangeConfigItem("TaskSettings", "max_rounds", 1, RangeValidator(1, 50))
74+
75+
76+
# 载入配置文件
77+
def load_config(path) -> dict:
78+
config = {}
79+
if os.path.exists(path):
80+
with open(path, "r", encoding="utf-8") as reader:
81+
config = json.load(reader)
82+
return config
83+
84+
85+
appConfig = Config()
86+
appConfig.themeMode.value = Theme.AUTO
87+
qconfig.load(str(CONFIG_FILE.absolute()), appConfig)
7488

75-
cfg = Config()
76-
cfg.themeMode.value = Theme.AUTO
77-
qconfig.load(str(CONFIG_FILE.absolute()), cfg)
89+
# transConfig = load_config(str(TRANS_CONFIG_FILE.absolute()))

app/common/constant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"Portuguese": "pt",
1515
"Russian": "ru",
1616
"Spanish": "es",
17+
"Thai": "th",
1718
"Turkish": "tr",
1819
"Vietnamese": "vi",
1920
"Bahasa Indonesia": "id"

0 commit comments

Comments
 (0)