✨ feat: 支持下载时转换繁体中文#765
Conversation
Summary of ChangesHello @kazukokawagawa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求引入了一项新功能,允许用户在下载歌词文件时选择将其内容自动转换为繁体中文。这通过在设置界面添加一个新选项来实现,并在下载管理器中集成了繁体转换逻辑,确保下载的歌词文件符合用户的语言偏好。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| const traditionalVariantLabel = computed(() => { | ||
| const variantMap: Record<string, string> = { | ||
| s2t: "繁体中文 (标准)", | ||
| s2tw: "台湾正体", | ||
| s2hk: "香港繁体", | ||
| s2twp: "台湾正体 (含词汇)", | ||
| }; | ||
| return variantMap[settingStore.traditionalChineseVariant] || "繁体中文"; | ||
| }); |
There was a problem hiding this comment.
为了提高性能和代码可读性,建议将 variantMap 对象定义在 computed 函数外部,作为一个常量。这样可以避免在每次访问计算属性时都重新创建该对象。
const variantMap: Record<string, string> = {
s2t: "繁体中文 (标准)",
s2tw: "台湾正体",
s2hk: "香港繁体",
s2twp: "台湾正体 (含词汇)",
};
// 繁体变体标签
const traditionalVariantLabel = computed(() => {
return variantMap[settingStore.traditionalChineseVariant] || "繁体中文";
});
| const result = lines.join("\n"); | ||
|
|
||
| // 繁体转换 | ||
| if (settingStore.downloadLyricToTraditional) { | ||
| const variant = (settingStore.traditionalChineseVariant || "s2t") as ConverterMode; | ||
| const converter = await getConverter(variant); | ||
| return converter(result); | ||
| } | ||
|
|
||
| return result; |
There was a problem hiding this comment.
这块繁体转换的逻辑在 processDownload 方法中也存在,导致了代码重复。为了提高代码的可维护性,建议将此逻辑提取到一个私有的辅助方法中。
你可以在 DownloadManager 类中添加如下方法:
private async _convertToTraditionalIfNeeded(text: string): Promise<string> {
const settingStore = useSettingStore();
if (settingStore.downloadLyricToTraditional && text) {
const variant = (settingStore.traditionalChineseVariant || "s2t") as ConverterMode;
const converter = await getConverter(variant);
return converter(text);
}
return text;
}然后,你就可以将当前的 if 代码块替换为对这个新方法的调用。同样的,在 processDownload 方法中(大约在 429 行)也应该使用这个新方法来替换重复的逻辑。
| const result = lines.join("\n"); | |
| // 繁体转换 | |
| if (settingStore.downloadLyricToTraditional) { | |
| const variant = (settingStore.traditionalChineseVariant || "s2t") as ConverterMode; | |
| const converter = await getConverter(variant); | |
| return converter(result); | |
| } | |
| return result; | |
| const result = lines.join("\n"); | |
| return await this._convertToTraditionalIfNeeded(result); |
No description provided.