Skip to content

Commit

Permalink
Fix | i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
LxHTT committed Mar 23, 2024
1 parent d9d87df commit 8431721
Show file tree
Hide file tree
Showing 19 changed files with 3,777 additions and 207 deletions.
18 changes: 9 additions & 9 deletions Adapters/Plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def initSinglePluginsWidget(self, pluginsVerticalLayout: QVBoxLayout):
def deletePlugin(self, pluginName, parent):
if not self.isDelMsgShowed:
w = MessageBox(
f'你真的要删除插件"{pluginName}"?吗?',
"删除后,这个插件将会消失不见!\n此操作是不可逆的!你确定这么做吗?",
self.tr(f'你真的要删除插件"{pluginName}"?吗?'),
self.tr("删除后,这个插件将会消失不见!\n此操作是不可逆的!你确定这么做吗?"),
parent,
)
w.yesButton.setText("取消")
Expand All @@ -294,11 +294,11 @@ def deletePlugin(self, pluginName, parent):

def deletePluginConfirm(self, pluginName, parent):
self.isDelMsgShowed = 0
title = f'你真的要删除插件"{pluginName}"?'
content = f'此操作是不可逆的!它会失去很久,很久!\n如果真的要删除,请在下方输入框内输入"{pluginName}",然后点击“删除”按钮:' # noqa: E501
title = self.tr(f'你真的要删除插件"{pluginName}"?')
content = self.tr(f'此操作是不可逆的!它会失去很久,很久!\n如果真的要删除,请在下方输入框内输入"{pluginName}",然后点击“删除”按钮:') # noqa: E501
w2 = MessageBox(title, content, parent)
w2.yesButton.setText("取消")
w2.cancelButton.setText("删除")
w2.yesButton.setText(self.tr("取消"))
w2.cancelButton.setText(self.tr("删除"))
w2.cancelButton.setStyleSheet(
GlobalMCSL2Variables.darkWarnBtnStyleSheet
if isDarkTheme()
Expand All @@ -311,7 +311,7 @@ def deletePluginConfirm(self, pluginName, parent):
name=pluginName, LineEditText=confirmLineEdit.text(), parent=parent
)
)
confirmLineEdit.setPlaceholderText(f'在此输入"{pluginName}"')
confirmLineEdit.setPlaceholderText(self.tr(f'在此输入"{pluginName}"'))
parent.deleteBtnEnabled.connect(w2.cancelButton.setEnabled)
w2.cancelSignal.connect(lambda: self.deletePluginFile(pluginName, parent))
w2.textLayout.addWidget(confirmLineEdit)
Expand All @@ -325,8 +325,8 @@ def deletePluginFile(self, pluginName, parent):
rmtree(f"Plugins//{pluginName}")
else:
InfoBar.error(
title="提示",
content=f"删除插件{pluginName}失败!",
title=self.tr("提示"),
content=self.tr(f"删除插件{pluginName}失败!"),
duration=2000,
position=InfoBarPosition.BOTTOM_LEFT,
parent=parent,
Expand Down
8 changes: 4 additions & 4 deletions MCSL2Lib/Pages/configEditorPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def createConfigEditor(self, selected, deselected):
text = readFile(filePath)
except Exception as e:
InfoBar.info(
title="抱歉",
content=f"MCSL2无法打开此文件,原因:\n{e.with_traceback(None)}",
title=self.tr("抱歉"),
content=self.tr("MCSL2无法打开此文件,原因:\n") + e.with_traceback(None),
orient=Qt.Horizontal,
parent=self,
duration=1500,
Expand Down Expand Up @@ -233,8 +233,8 @@ def saveConfig(self, filePath: str, auto: bool = True):
if (newText := self.editorDict[filePath].toPlainText()) != tmpText:
writeFile(filePath, newText)
InfoBar.info(
title="提示",
content=f"已{'自动' if auto else ''}保存 {osp.basename(filePath)}",
title=self.tr("提示"),
content=self.tr("已保存 ") + osp.basename(filePath),
orient=Qt.Horizontal,
parent=self,
duration=1500,
Expand Down
2 changes: 1 addition & 1 deletion MCSL2Lib/Pages/configurePage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def __init__(self, parent=None):
self.extendedAutoDetectJavaPrimaryPushBtn.setText(self.tr("自动查找Java"))
self.extendedJavaListPushBtn.setText(self.tr("Java列表"))
self.extendedMemSubtitleLabel.setText(self.tr("内存:"))
self.extendedToSymbol.setText(self.tr("~"))
self.extendedToSymbol.setText("~")
self.extendedDownloadCorePrimaryPushBtn.setText(self.tr("下载核心"))
self.extendedManuallyAddCorePrimaryPushBtn.setText(self.tr("手动导入"))
self.extendedAddCoreFromDownloadedPrimaryPushBtn.setText(self.tr("从下载的核心中导入"))
Expand Down
4 changes: 2 additions & 2 deletions MCSL2Lib/Pages/consoleCenterPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, parent=None):
self.titleLimitWidget = QWidget(self)
self.titleLayout = QGridLayout(self.titleLimitWidget)
self.subTitleLabel = StrongBodyLabel(
text="查看所有正在运行中的服务器。", parent=self.titleLimitWidget
text=self.tr("查看所有正在运行中的服务器。"), parent=self.titleLimitWidget
)
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
Expand All @@ -37,7 +37,7 @@ def __init__(self, parent=None):
self.subTitleLabel.setSizePolicy(sizePolicy)
self.subTitleLabel.setTextFormat(Qt.MarkdownText)
self.titleLayout.addWidget(self.subTitleLabel, 1, 0, 1, 1)
self.titleLabel = TitleLabel(text="监控", parent=self.titleLimitWidget)
self.titleLabel = TitleLabel(text=self.tr("监控"), parent=self.titleLimitWidget)
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand Down
12 changes: 8 additions & 4 deletions MCSL2Lib/Pages/downloadPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,10 @@ def __init__(self, parent=None):
def onPageChangedRefresh(self, currentChanged):
if currentChanged == 3:
self.subTitleLabel.setText(
self.tr(
f"Aria2引擎高速驱动! - 当前下载源:{settingsVariables.downloadSourceTextList[settingsVariables.downloadSourceList.index(cfg.get(cfg.downloadSource))]}" # noqa: E501
self.tr("Aria2引擎高速驱动! - 当前下载源:{downloadSource}").format(
downloadSource=settingsVariables.downloadSourceTextList[
settingsVariables.downloadSourceList.index(cfg.get(cfg.downloadSource))
]
)
)
self.downloadStackedWidget.setCurrentWidget(
Expand Down Expand Up @@ -1330,8 +1332,10 @@ def downloadCustomURLFile(self):
urlLineEdit = LineEdit()
urlLineEdit.setPlaceholderText(self.tr("URL"))
w = MessageBox(
"创建下载任务",
"使用MCSL2自带的高速Aria2下载引擎下载文件。\n请注意,部分网站可能会禁止(403),无法正常下载。",
self.tr("创建下载任务"),
self.tr(
"使用MCSL2自带的高速Aria2下载引擎下载文件。\n请注意,部分网站可能会禁止(403),无法正常下载。"
),
self,
)
w.textLayout.addWidget(urlLineEdit)
Expand Down
10 changes: 5 additions & 5 deletions MCSL2Lib/Pages/serverManagerPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def deleteServer_Step4(self, exit1Msg):
self.deletingServerStateToolTip.setState(True)
self.deletingServerStateToolTip = None
else:
self.deletingServerStateToolTip.setContent(self.tr("怪,删除失败!\n") + exit1Msg)
self.deletingServerStateToolTip.setContent(self.tr("删除失败!\n") + exit1Msg)
self.deletingServerStateToolTip.setState(True)
self.deletingServerStateToolTip = None
self.refreshServers()
Expand Down Expand Up @@ -1357,7 +1357,7 @@ def afterInstallingForge(self, installFinished, args=...):
self.installingForgeStateToolTip = None
else:
self.installingForgeStateToolTip.setContent(
self.tr("怪,安装失败!") + args if args is not ... else ""
self.tr("安装失败!") + args if args is not ... else ""
)
self.installingForgeStateToolTip.setState(True)
self.installingForgeStateToolTip = None
Expand Down Expand Up @@ -1403,9 +1403,9 @@ def startServer(self, index):
self.runningServerCardGenerated.emit(w.monitorWidget)

def backup(self, index):
w = MessageBox("备份服务器", "请选择你需要备份的文件:", self)
w.yesButton.setText("服务器")
w.cancelButton.setText("仅存档")
w = MessageBox(self.tr("备份服务器"), self.tr("请选择你需要备份的文件:"), self)
w.yesButton.setText(self.tr("服务器"))
w.cancelButton.setText(self.tr("仅存档"))
w.yesSignal.connect(
lambda: backupServer(
ServerConfigConstructor.loadServerConfig(index=index).serverName, parent=self
Expand Down
36 changes: 14 additions & 22 deletions MCSL2Lib/Pages/settingsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,20 @@ def __init__(self, parent=None):
self.settingsLayout.addWidget(self.consoleSettingsGroup)

# Software
self.programSettingsGroup = SettingCardGroup("程序设置", self.settingsWidget)
self.programSettingsGroup = SettingCardGroup(self.tr("程序设置"), self.settingsWidget)
self.themeMode = OptionsSettingCard(
cfg.themeMode,
FIF.BRUSH,
title="主题",
content="本程序也要花里胡哨捏~",
title=self.tr("主题"),
content=self.tr("本程序也要花里胡哨捏~"),
texts=["浅色", "深色", "跟随系统"],
parent=self.programSettingsGroup,
)
self.themeColor = CustomColorSettingCard(
configItem=cfg.themeColor,
icon=FIF.PALETTE,
title="主题色",
content="本程序也要花里胡哨捏~",
title=self.tr("强调色"),
content=self.tr("本程序也要花里胡哨捏~"),
parent=self.programSettingsGroup,
)
self.alwaysRunAsAdministrator = SwitchSettingCard(
Expand Down Expand Up @@ -347,7 +347,7 @@ def __init__(self, parent=None):
self.settingsLayout.addWidget(self.programSettingsGroup)

# Update
self.updateSettingsGroup = SettingCardGroup("更新设置", self.settingsWidget)
self.updateSettingsGroup = SettingCardGroup(self.tr("更新设置"), self.settingsWidget)
self.checkUpdateSetting = PrimaryPushSettingCard(
icon=FIF.SYNC,
text=self.tr("检查更新"),
Expand Down Expand Up @@ -395,7 +395,7 @@ def __init__(self, parent=None):
self.gridLayout.setObjectName("gridLayout")

self.openOfficialWeb = HyperlinkButton(
"https://mcsl.com.cn", "打开官网", self.aboutContentWidget, FIF.HOME
"https://mcsl.com.cn", self.tr("打开官网"), self.aboutContentWidget, FIF.HOME
)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
Expand All @@ -407,7 +407,7 @@ def __init__(self, parent=None):
self.gridLayout.addWidget(self.openOfficialWeb, 1, 1, 1, 1)
self.openSourceCodeRepo = HyperlinkButton(
"https://www.github.com/MCSLTeam/MCSL2",
"打开源码仓库",
self.tr("打开源码仓库"),
self.aboutContentWidget,
FIF.GITHUB,
)
Expand All @@ -425,7 +425,7 @@ def __init__(self, parent=None):
self.gridLayout.addWidget(self.aboutContent, 0, 0, 1, 7)
self.joinQQGroup = HyperlinkButton(
"https://jq.qq.com/?_wv=1027&k=x2ISlviQ",
"加入官方群聊",
self.tr("加入官方QQ群"),
self.aboutContentWidget,
FIF.HELP,
)
Expand All @@ -438,7 +438,7 @@ def __init__(self, parent=None):

self.gridLayout.addWidget(self.joinQQGroup, 1, 0, 1, 1)
self.generateSysReport = PrimaryPushButton(
icon=FIF.DICTIONARY, text="系统报告", parent=self.aboutContentWidget
icon=FIF.DICTIONARY, text=self.tr("系统报告"), parent=self.aboutContentWidget
)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
Expand All @@ -448,7 +448,7 @@ def __init__(self, parent=None):
self.generateSysReport.setObjectName("generateSysReport")

self.gridLayout.addWidget(self.generateSysReport, 1, 5, 1, 1)
self.uniqueCodeBtn = PrimaryPushButton(icon=FIF.PASTE, text="复制识别码", parent=self)
self.uniqueCodeBtn = PrimaryPushButton(icon=FIF.PASTE, text=self.tr("复制识别码"), parent=self)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand All @@ -461,7 +461,7 @@ def __init__(self, parent=None):
self.gridLayout.addItem(spacerItem30, 1, 6, 1, 2)
self.sponsorsBtn = HyperlinkButton(
"https://github.com/MCSLTeam/MCSL2/blob/master/Sponsors.md",
"赞助者列表",
self.tr("赞助者列表"),
self.aboutContentWidget,
FIF.PEOPLE,
)
Expand All @@ -474,7 +474,7 @@ def __init__(self, parent=None):

self.donateBtn = HyperlinkButton(
"https://afdian.net/a/MCSLTeam",
"赞助此项目",
self.tr("赞助此项目"),
self.aboutContentWidget,
FIF.CAFE,
)
Expand Down Expand Up @@ -508,15 +508,7 @@ def __init__(self, parent=None):
self.titleLabel.setText(self.tr("设置"))
self.subTitleLabel.setText(self.tr("自定义你的MCSL2。"))
self.aboutContent.setText(
self.tr("MCSL2是一个开源非营利性项目,遵循GNU General Public License 3.0开源协议。\n")
+ self.tr("任何人皆可使用MCSL2的源码进行再编译、修改以及发行,\n")
+ self.tr(
"但必须在相关源代码中以及软件中给出声明,并且二次分发版本的项目名称应与“MCSL2”有\n"
)
+ self.tr("明显辨识度。\n")
+ self.tr("\n")
+ self.tr("Copyright © MCSLTeam. All right reserved.\n")
+ self.tr("")
self.tr("MCSL2是一个开源非营利性项目,遵循GNU General Public License 3.0开源协议。\n任何人皆可使用MCSL2的源码进行再编译、修改以及发行,\n但必须在相关源代码中以及软件中给出声明,并且二次分发版本的项目名称应与“MCSL2”有\n明显辨识度。\n\nCopyright © MCSLTeam. All right reserved.\n") # noqa : E501
)
self.aboutTitle.setText(self.tr("关于"))
self.generateSysReport.clicked.connect(self.generateSystemReport)
Expand Down
9 changes: 5 additions & 4 deletions MCSL2Lib/ServerControllers/serverInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ def __init__(
self.installPlan = ForgeInstaller.InstallPlan.PlanA
else:
raise InstallerError(
f"不支持的自动安装版本:{self._mcVersion}\nMCSL2的Forge自动安装仅支持Minecraft 1.8+"
# noqa: E501
self.tr(
"不支持的自动安装版本:{mcVersion}\nMCSL2的Forge自动安装仅支持Minecraft 1.8+"
).format(mcVersion=self._mcVersion) # noqa: E501
)

def getInstallerData(self, jarFile):
Expand Down Expand Up @@ -309,7 +310,7 @@ def onServerDownloadProgress(self, bytesReceived, bytesTotal):
percent = 0
MCSL2Logger.info(f"(正在下载核心... {percent:.0f}%) 使用BMCLAPI下载")
self.downloadServerProgress.emit(
self.tr("(正在下载核心... ") + f"{percent:.0f}" + self.tr("%) 使用BMCLAPI下载")
self.tr("(正在下载核心... {:.0f}%) 使用BMCLAPI下载").format(percent)
)

def onServerDownloadFinished(self, success: bool):
Expand Down Expand Up @@ -645,7 +646,7 @@ def onServerDownloadProgress(self, bytesReceived, bytesTotal):
percent = bytesReceived * 100 / bytesTotal
MCSL2Logger.info(f"(正在下载核心... {percent:.0f}%) 使用BMCLAPI下载")
self.downloadServerProgress.emit(
self.tr("(正在下载核心... ") + f"{percent:.0f}" + self.tr("%) 使用BMCLAPI下载")
self.tr("(正在下载核心... {:.0f}%) 使用BMCLAPI下载").format(percent)
)

def onServerDownloadFinished(self, success: bool):
Expand Down
28 changes: 15 additions & 13 deletions MCSL2Lib/ServerControllers/serverUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def backupServer(serverName: str, parent):
try:
s = QFileDialog.getSaveFileName(
parent,
f"MCSL2 - 备份服务器“{serverName}”",
parent.tr("MCSL2 - 备份服务器“{serverName}”").format(serverName),
f"{serverName}_backup.zip",
"Zip压缩包(*.zip)",
parent.tr("Zip压缩包(*.zip)"),
)[0]
if s == "":
return
Expand All @@ -139,8 +139,8 @@ def backupServer(serverName: str, parent):
)
tmpArchiveThread.successSignal.connect(
lambda: InfoBar.success(
title="备份完毕",
content=f"已保存至{s}",
title=parent.tr("备份完毕"),
content=parent.tr("已保存至{s}").format(s),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
Expand All @@ -151,7 +151,7 @@ def backupServer(serverName: str, parent):
tmpArchiveThread.start()
except Exception:
InfoBar.success(
title="备份失败",
title=parent.tr("备份失败"),
content=str(Exception.args),
orient=Qt.Horizontal,
isClosable=True,
Expand All @@ -162,12 +162,12 @@ def backupServer(serverName: str, parent):


def isBedrockServer(serverName):
directoryPath = f'./Servers/{serverName}/resource_packs'
directoryPath = f"./Servers/{serverName}/resource_packs"
return exists(directoryPath) and isdir(directoryPath)


def isBungeeCordServer(serverName):
filePath = f'./Servers/{serverName}/locations.yml'
filePath = f"./Servers/{serverName}/locations.yml"
return exists(filePath)


Expand All @@ -191,9 +191,9 @@ def backupSaves(serverConfig: ServerVariables, parent):
rmtree(f"MCSL2/BackupTemp_{serverConfig.serverName}/")
s = QFileDialog.getSaveFileName(
parent,
f"MCSL2 - 备份服务器“{serverConfig.serverName}”的存档",
parent.tr("MCSL2 - 备份服务器存档"),
f"{serverConfig.serverName}_{levelName}_backup.zip",
"Zip压缩包(*.zip)",
parent.tr("Zip压缩包(*.zip)"),
)[0]
if s == "":
return
Expand All @@ -216,8 +216,10 @@ def backupSaves(serverConfig: ServerVariables, parent):
)
tmpArchiveThread.successSignal.connect(
lambda: InfoBar.success(
title="备份完毕",
content=f"已保存至{s}\n备份了以下文件夹:\n{existsDir}",
title=parent.tr("备份完毕"),
content=parent.tr("已保存至{s}。\n备份了以下文件夹:\n{existsDir}").format(
s=s, existsDir=existsDir
),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
Expand All @@ -234,8 +236,8 @@ def backupSaves(serverConfig: ServerVariables, parent):
tmpArchiveThread.start()
else:
InfoBar.warning(
title="保存失败",
content="代理服务端没有存档,无法保存",
title=parent.tr("保存失败"),
content=parent.tr("代理服务端没有存档,无法保存"),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_LEFT,
Expand Down
Loading

0 comments on commit 8431721

Please sign in to comment.