Skip to content

Commit

Permalink
fixed 翻译时会崩溃的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Entity-Now committed Jul 6, 2023
1 parent cf899d2 commit 84b361b
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 42 deletions.
Binary file modified .vs/EnTranslate/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/EnTranslate/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/EnTranslate/v17/.suo
Binary file not shown.
Binary file modified .vs/EnTranslate/v17/fileList.bin
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/entranslate.metadata.v6.1
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/entranslate.projects.v6.1
Binary file not shown.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/testTranslate/bin/Debug/net6.0/testTranslate.dll",
"args": [],
"cwd": "${workspaceFolder}/testTranslate",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "EnTranslate.sln"
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/EnTranslate.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/EnTranslate.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/EnTranslate.sln"
],
"problemMatcher": "$msCompile"
}
]
}
27 changes: 15 additions & 12 deletions EnTranslate/utility/ParseString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ public static class ParseString
/// <returns></returns>
public static IEnumerable<string> getWordArray(string character)
{
List<string> Words = new List<string>();
if (string.IsNullOrEmpty(character) && character.Length < 2)
{
return Words;
return null;
}
List<string> Words = new List<string>();
var RegexValue = Regex.Matches(character, @"[A-Z\s]{2,}").Cast<Match>();
if (RegexValue.Count() > 0)
character = RegexValue.Select(I =>
{
string tempValue = I.Value;
// 将大写的单词转换为小写的
return tempValue.Replace(tempValue, Pascalize(tempValue.ToLower()));
}).Aggregate(string.Empty,(totall, current) =>
if (RegexValue.Count() > 0 )
{
/** 将字符串连接起来 */
return totall + current;
});
character = RegexValue.Select(I =>
{
string tempValue = I.Value;
// 将大写的单词转换为小写的
return tempValue.Replace(tempValue, Pascalize(tempValue.ToLower()));
}).Aggregate(string.Empty, (totall, current) =>
{
/** 将字符串连接起来 */
return totall + current;
});
}

// 判断是否是字母并且全部大写
if (Regex.IsMatch(character, @"^[A-Z]+$"))
{
Expand Down
7 changes: 2 additions & 5 deletions EnTranslate/utility/QueryDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ public static Dictionarys getDir(string word)
{
try
{
if (string.IsNullOrEmpty(word))
{
return null;
}
if (word.Length < 2 || word == "." || word == " ")
word = word.Trim();
if (string.IsNullOrEmpty(word) || word.Length < 2)
{
return null;
}
Expand Down
12 changes: 11 additions & 1 deletion EnTranslate_Chinese/EnTranslate_Chinese.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EnTranslate\EnTranslate.csproj">
<Project>{4D0498B7-FC49-4E0A-ACCA-161E3DC1C040}</Project>
<Project>{4d0498b7-fc49-4e0a-acca-161e3dc1c040}</Project>
<Name>EnTranslate</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Logo.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="view.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Binary file added EnTranslate_Chinese/Logo.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion EnTranslate_Chinese/QuickInfo/EnQuickInfoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Action<Action> debounce
{
if (_debounce == null)
{
_debounce = utlis.Debounce(50);
_debounce = utlis.Debounce(5);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions EnTranslate_Chinese/QuickInfo/EnQuickInfoSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiC
// 在范围内查找我们的 QuickInfo 单词的出现
ITextStructureNavigator navigator = m_provider.NavigatorService.GetTextStructureNavigator(m_subjectBuffer);
TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
string searchText = extent.Span.GetText();
string searchText = extent.Span.GetText().Trim();

// 判断字符串是否包含中文
bool containsChinese = Regex.IsMatch(searchText, @"[\u4e00-\u9fff]");
if (string.IsNullOrEmpty(searchText) || searchText.Length < 2 || containsChinese)
if (containsChinese)
{
applicableToSpan = null;
return;
Expand Down
50 changes: 30 additions & 20 deletions EnTranslate_Chinese/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="EnTranslate_Chinese.77fe69ff-888b-48d5-af2b-f47aa5087733" Version="1.0" Language="en-US" Publisher="dujutese" />
<DisplayName>EnTranslate_Chinese</DisplayName>
<Description>Empty VSIX Project.</Description>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
<Metadata>
<Identity Id="EnTranslate_Chinese.77fe69ff-888b-48d5-af2b-f47aa5087733" Version=" 1.2.2" Language="zh-CN" Publisher="Entity-Now" />
<DisplayName>EnTranslate_Chinese</DisplayName>
<Description xml:space="preserve">EnTranslate是一款功能强大的离线划词翻译插件,拥有超过340万条离线词库,能够准确翻译各种生僻单词。作为Visual Studio的VSIX插件,它为您提供了出色的英语单词翻译功能,而且具备灵活的单词拆分能力,支持驼峰命名和下划线命名等多种形式的单词拆分。无论您是在编写代码还是阅读文档,EnTranslate都是您的最佳翻译助手。</Description>
<MoreInfo>https://github.com/Entity-Now/EnTranslate</MoreInfo>
<Icon>Logo.ico</Icon>
<PreviewImage>view.png</PreviewImage>
<Tags >单词翻译,划词翻译,英文翻译中文,VSIX翻译插件,英译汉助手</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0, 18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[16.0,18.0)" Id="Microsoft.VisualStudio.Pro">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[16.0,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
</PackageManifest>
Binary file added EnTranslate_Chinese/view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Logo.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion testTranslate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace testTranslate
{
internal class Program
{
static void Main(string[] args)
static void Main()
{
var word = Console.ReadLine();
var words = ParseString.getWordArray(word);
Expand Down

0 comments on commit 84b361b

Please sign in to comment.