-
Notifications
You must be signed in to change notification settings - Fork 30
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Build on release | ||
on: | ||
release: | ||
types: created | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install Net | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
cache: true | ||
|
||
- name: Dowmload Powertoys | ||
run: | | ||
curl -L https://github.com/microsoft/PowerToys/releases/download/v0.84.0/PowerToysUserSetup-0.84.0-x64.exe -o powertoys.exe | ||
run powertoys.exe -install -quiet -norestart | ||
timeout /t 15 | ||
mkdir lib | ||
copy "%LOCALAPPDATA%\PowerToys\PowerToys.Common.UI.dll" "lib\PowerToys.Common.UI.dll" | ||
copy "%LOCALAPPDATA%\PowerToys\PowerToys.ManagedCommon.dll" "lib\PowerToys.ManagedCommon.dll" | ||
copy "%LOCALAPPDATA%\PowerToys\PowerToys.Settings.UI.Lib.dll" "lib\PowerToys.Settings.UI.Lib.dll" | ||
copy "%LOCALAPPDATA%\PowerToys\Wox.Infrastructure.dll" "lib\Wox.Infrastructure.dll" | ||
copy "%LOCALAPPDATA%\PowerToys\Wox.Plugin.dll" "lib\Wox.Plugin.dll" | ||
|
||
- name: Package | ||
run: dotnet pack | ||
|
||
- name: Upload | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
# Artifact name | ||
name: Translator_x64 | ||
# A file, directory or wildcard pattern that describes what to upload | ||
path: "bin/out" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
obj | ||
bin | ||
*.dll | ||
lib | ||
|
||
.vs/ | ||
src/lib | ||
src/lib | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
copy "C:\Program Files\PowerToys\PowerToys.Common.UI.dll" "lib\PowerToys.Common.UI.dll" | ||
copy "C:\Program Files\PowerToys\PowerToys.ManagedCommon.dll" "lib\PowerToys.ManagedCommon.dll" | ||
copy "C:\Program Files\PowerToys\PowerToys.Settings.UI.Lib.dll" "lib\PowerToys.Settings.UI.Lib.dll" | ||
copy "C:\Program Files\PowerToys\Wox.Infrastructure.dll" "lib\Wox.Infrastructure.dll" | ||
copy "C:\Program Files\PowerToys\Wox.Plugin.dll" "lib\Wox.Plugin.dll" | ||
mkdir -p -e lib | ||
copy "C:\Program Files\PowerToys\PowerToys.Common.UI.dll" "lib\PowerToys.Common.UI.dll" /y | ||
copy "C:\Program Files\PowerToys\PowerToys.ManagedCommon.dll" "lib\PowerToys.ManagedCommon.dll" /y | ||
copy "C:\Program Files\PowerToys\PowerToys.Settings.UI.Lib.dll" "lib\PowerToys.Settings.UI.Lib.dll" /y | ||
copy "C:\Program Files\PowerToys\Wox.Infrastructure.dll" "lib\Wox.Infrastructure.dll" /y | ||
copy "C:\Program Files\PowerToys\Wox.Plugin.dll" "lib\Wox.Plugin.dll" /y | ||
copy "%LOCALAPPDATA%\PowerToys.Common.UI.dll" "lib\PowerToys.Common.UI.dll" /y | ||
copy "%LOCALAPPDATA%\PowerToys.ManagedCommon.dll" "lib\PowerToys.ManagedCommon.dll" /y | ||
copy "%LOCALAPPDATA%\PowerToys.Settings.UI.Lib.dll" "lib\PowerToys.Settings.UI.Lib.dll" /y | ||
copy "%LOCALAPPDATA%\Wox.Infrastructure.dll" "lib\Wox.Infrastructure.dll" /y | ||
copy "%LOCALAPPDATA%\Wox.Plugin.dll" "lib\Wox.Plugin.dll" /y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": { | ||
"net8.0-windows7.0": {} | ||
} | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没有必要用包管理 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是的,不需要。这只是为了通过现有的编译actions。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 原来是这样,之前加 Action 目的是为了尝试一下 GitHub 能否提供 arm 平台,那倒是应该保留 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不必要的包管理器可以被移除了#58 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该可以在一个 pr 里去提交这些更改? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我更喜欢将不同的功能拆分。当一个pr的commit很多时,如果其中一个feat出了问题,可能导致其他的feat也被堵住。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我指的就是拆开,但是这里明显不是优化 language 相关的,分离出去 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 事实上,还有一个问题是。编译脚本的分支只能从release的commit点fork出来,否则现在的代码库无法通过编译。但是其他的没有问题,可以直接从HEAD节点fork。 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,27 +4,62 @@ namespace Translator | |
{ | ||
public class SettingHelper | ||
{ | ||
public static readonly List<string> languagesKeys = new List<string> { "auto", "zh-CHS", "zh-CHT", "en", "ja", "ko", "ru", "fr", "es", "ar", "de", "it", "he" }; | ||
public static readonly List<string> languagesOptions = new List<string> { "auto", "Chinese (Simplified)", "Chinese (Traditional)", "English", "Japanese", "Korean", "Russian", "French", "Spanish", "Arabic", "German", "Italian", "Hebrew" }; | ||
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]; | ||
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]; | ||
Comment on lines
+7
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 更倾向于 lower camel case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 抱歉,编辑器设置成了自动调整规范。C# 标识符命名规则和约定 如果你坚持,我会与你同步。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 其他的规范我倒是没问题,主要是字段也是 PascalCase,首字母大写不是很舒服 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 也可以改吧,我使用的是 vscode 作为编辑器,没有太多的 C# 内置支持,所以一直按照的是自己的规范 |
||
|
||
public static List<PluginAdditionalOption> GetAdditionalOptions() | ||
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(); | ||
} | ||
} | ||
Comment on lines
+19
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我倾向于单独出来,不要放到 SettingHelper下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 赞成,把配置里允许的选项和Setting本身单独封装是一个不错的想法。 |
||
|
||
public static List<PluginAdditionalOption> GetAdditionalOptions() | ||
{ | ||
var lanuageItems = Languages.ContrastList(); | ||
var dictItems = DictUrlPatternKeys.Select((val, idx) => | ||
{ | ||
return new KeyValuePair<string, string>(val, idx.ToString()); | ||
}).ToList(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
using Wox.Plugin.Logger; | ||
using Translator.Utils; | ||
using System.Windows.Media; | ||
using Translator.Youdao; | ||
|
||
namespace Translator; | ||
|
||
public class TranslateFailedException : Exception | ||
|
@@ -16,6 +18,11 @@ public class TranslateHelper | |
{ | ||
public struct TranslateTarget | ||
{ | ||
public TranslateTarget(string source, string target) | ||
{ | ||
src = source; | ||
target = SettingHelper.Languages.MatchLanguageCode(target); | ||
} | ||
public string src; | ||
public string toLan; | ||
} | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 多余的?同下 |
||
private List<Type> translatorTypes; | ||
private bool isSpeaking = false; | ||
private bool isIniting = false; | ||
|
@@ -35,7 +42,7 @@ public TranslateHelper(IPublicAPI publicAPI, string defaultLanguageKey = "auto") | |
null, null, null | ||
}; | ||
translatorTypes = new List<Type>{ | ||
typeof(Youdao.V2.YoudaoTranslator), | ||
typeof(Translator), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不能这样做,是需要实现了 ITranslator 的类型 |
||
typeof(Youdao.old.YoudaoTranslator), | ||
typeof(Youdao.Backup.BackUpTranslator) | ||
}; | ||
|
@@ -72,7 +79,7 @@ public List<ResultItem> QueryTranslate(string raw, string translateFrom = "user | |
var target = ParseRawSrc(raw); | ||
string src = target.src; | ||
string toLan = toLanuage ?? target.toLan; | ||
Youdao.ITranslateResult? translateResult = null; | ||
Translator.Youdao.ITranslateResult? translateResult = null; | ||
int idx = 0; | ||
translateResult = this.translators.FirstNotNoneCast((it) => | ||
{ | ||
|
@@ -199,7 +206,7 @@ public bool InitTranslater() | |
try | ||
{ | ||
var tran = tp.GetConstructor(Type.EmptyTypes)?.Invoke(null); | ||
this.translators[idx] = tran as Youdao.ITranslator; | ||
this.translators[idx] = tran as Translator.Youdao.ITranslator; | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
using Translator.Utils; | ||
using Wox.Plugin.Logger; | ||
|
||
namespace Translator.Youdao.V2; | ||
namespace Translator.Youdao; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需要单独开,他是 youdao 下单独的版本 |
||
|
||
public class KeyResponse | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有必要再传 lib 文件夹,我理解有需要的话会运行 lib.bat 来生成