Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize language options #56

Closed
wants to merge 6 commits into from

Conversation

NtskwK
Copy link
Contributor

@NtskwK NtskwK commented Sep 5, 2024

No description provided.

@N0I0C0K
Copy link
Owner

N0I0C0K commented Sep 5, 2024

Hi! 首先很高兴看到你的 PR,提出了一些问题,期待讨论

@N0I0C0K
Copy link
Owner

N0I0C0K commented Sep 5, 2024

同时前面几个如果有重复的话可以关闭掉了

@NtskwK
Copy link
Contributor Author

NtskwK commented Sep 5, 2024

优化语言选项,安装脚本修复,自动化编译测试脚本。这三个是不同的分开提交方向(是的,他们没有重复)有利于单独进行调整。

需要进行单独讨论的问题不会影响其他功能的提交。🤣

@N0I0C0K
Copy link
Owner

N0I0C0K commented Sep 6, 2024

同时回复一下 cr 中的 comment 吧

@NtskwK
Copy link
Contributor Author

NtskwK commented Sep 6, 2024

#36

@@ -0,0 +1 @@
./*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有必要再传 lib 文件夹,我理解有需要的话会运行 lib.bat 来生成

Comment on lines +1 to +5
{
"version": 1,
"dependencies": {
"net8.0-windows7.0": {}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有必要用包管理

Copy link
Contributor Author

@NtskwK NtskwK Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,不需要。这只是为了通过现有的编译actions。
https://github.com/N0I0C0K/PowerTranslator/actions/runs/9919108964
如果你确实不需要包管理,可以在actions中删除对应的步骤。我会马上跟进。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来是这样,之前加 Action 目的是为了尝试一下 GitHub 能否提供 arm 平台,那倒是应该保留

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不必要的包管理器可以被移除了#58

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该可以在一个 pr 里去提交这些更改?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我更喜欢将不同的功能拆分。当一个pr的commit很多时,如果其中一个feat出了问题,可能导致其他的feat也被堵住。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我指的就是拆开,但是这里明显不是优化 language 相关的,分离出去

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

事实上,还有一个问题是。编译脚本的分支只能从release的commit点fork出来,否则现在的代码库无法通过编译。但是其他的没有问题,可以直接从HEAD节点fork。

Comment on lines +19 to +57
public abstract class Languages
{
var lanuageItems = languagesOptions.Select((val, idx) =>
private static readonly Dictionary<string, string> LanguageContrast = new Dictionary<string, string>
{
return new KeyValuePair<string, string>(val, idx.ToString());
}).ToList();
var dictItems = dictUrlPatternKeys.Select((val, idx) =>
{ "auto", "auto" },
{ "zh-CHS", "Chinese (Simplified)" },
{ "zh-CHT", "Chinese (Traditional)" },
{ "en", "English" },
{ "ja", "Japanese" },
{ "ko", "Korean" },
{ "ru", "Russian" },
{ "fr", "French" },
{ "es", "Spanish" },
{ "ar", "Arabic" },
{ "de", "German" },
{ "it", "Italian" },
{ "he", "Hebrew" },
};

private static readonly Dictionary<string, string> LanguageAbbreviation = new Dictionary<string, string>
{
{ "zhs", "zh-CHS" },
{ "zht", "zh-CHT" },
};

public static string MatchLanguageCode(string languageKey)
{
string defaultLanguageCode = "auto";
languageKey = languageKey is null ? defaultLanguageCode : languageKey;
LanguageAbbreviation.TryGetValue(languageKey, out languageKey);
LanguageContrast.TryGetValue(languageKey, out defaultLanguageCode);
return defaultLanguageCode;
}

public static List<KeyValuePair<string, string>> ContrastList()
{
return LanguageContrast.ToList();
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我倾向于单独出来,不要放到 SettingHelper下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

赞成,把配置里允许的选项和Setting本身单独封装是一个不错的想法。

@@ -24,7 +31,7 @@ public struct TranslateTarget
private object initLock = new Object();
private long lastInitTime = 0;
private IPublicAPI publicAPI;
private List<Youdao.ITranslator?> translators;
private List<Translator.Youdao.ITranslator?> translators;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余的?同下

@@ -35,7 +42,7 @@ public TranslateHelper(IPublicAPI publicAPI, string defaultLanguageKey = "auto")
null, null, null
};
translatorTypes = new List<Type>{
typeof(Youdao.V2.YoudaoTranslator),
typeof(Translator),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能这样做,是需要实现了 ITranslator 的类型

@@ -8,7 +8,7 @@
using Translator.Utils;
using Wox.Plugin.Logger;

namespace Translator.Youdao.V2;
namespace Translator.Youdao;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要单独开,他是 youdao 下单独的版本

Comment on lines +7 to +17
public static readonly List<string> DictUrlPatternKeys = new List<string> { "Youdao", "Oxford", "Cambridge" };
public static readonly List<string> DictUrlPatternValues = new List<string> { "https://www.youdao.com/result?word={0}&lang=en", "https://www.oed.com/search/dictionary/?scope=Entries&q={0}", "https://dictionary.cambridge.org/us/dictionary/english/{0}" };
public static readonly List<PluginAdditionalOption> PluginAdditionalOptions = GetAdditionalOptions();
public string DefaultLanguageKey = "auto";
public bool EnableSuggest = true;
public bool EnableAutoRead = false;
public bool EnableSecondLanuage = false;
public string SecondLanuageKey = "auto";
public bool ShowOriginalQuery = false;
public bool EnableJumpToDict = false;
public string DictUtlPattern = DictUrlPatternValues[0];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更倾向于 lower camel case

Copy link
Contributor Author

@NtskwK NtskwK Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抱歉,编辑器设置成了自动调整规范。C# 标识符命名规则和约定

如果你坚持,我会与你同步。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他的规范我倒是没问题,主要是字段也是 PascalCase,首字母大写不是很舒服

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以改吧,我使用的是 vscode 作为编辑器,没有太多的 C# 内置支持,所以一直按照的是自己的规范

@N0I0C0K
Copy link
Owner

N0I0C0K commented Sep 6, 2024

#36

忘记提交 review 了,我的问题

@N0I0C0K
Copy link
Owner

N0I0C0K commented Sep 6, 2024

还有一个想法想提一下,之前一直想把常量数据转移到 Resources 下,方便管理,也为了后面接入 i18n,但奈何一直没有时间

@NtskwK
Copy link
Contributor Author

NtskwK commented Sep 6, 2024

抱歉,我不是很懂C#项目的标准目录结构,请问有关语言选项的重构是直接独立成新的文件和其他选项放在另一个文件夹里吗。

如果你已经在做,那真是太好了。🥳🥳

此PR的内容已经结束。如果没有其他问题,你可以关闭它。我们可以在其他的议题中讨论。

@NtskwK
Copy link
Contributor Author

NtskwK commented Sep 7, 2024

我指的就是拆开,但是这里明显不是优化 language 相关的,分离出去

@N0I0C0K 好的,我会先关闭#56,因为这个拉取太乱了。如果还有需要处理的内容,请告诉我,我会重新开始一个分支。

@NtskwK NtskwK closed this Sep 7, 2024
@N0I0C0K
Copy link
Owner

N0I0C0K commented Sep 10, 2024

好的,很高兴你的贡献

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants