Skip to content

Commit fc56550

Browse files
authored
Merge pull request PCL-Community#242 from JustQiyi/main
2 parents c9af568 + ef91cec commit fc56550

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Public Module ModComp
1+
Imports System.Threading.Tasks
2+
3+
Public Module ModComp
24

35
Public Enum CompType
46
''' <summary>
@@ -211,6 +213,34 @@
211213
Return If(DatabaseEntry Is Nothing OrElse DatabaseEntry.ChineseName = "", RawName, DatabaseEntry.ChineseName)
212214
End Get
213215
End Property
216+
''' <summary>
217+
''' 中文描述。若为 Nothing 则没有。
218+
''' </summary>
219+
Public ReadOnly Property ChineseDescription As Task(Of String)
220+
Get
221+
Return GetChineseDescriptionAsync()
222+
End Get
223+
End Property
224+
225+
Private Async Function GetChineseDescriptionAsync() As Task(Of String)
226+
Dim from = If(FromCurseForge, "curseforge", "modrinth")
227+
Dim para = If(FromCurseForge, "modId", "project_id")
228+
Dim result As String = Nothing
229+
230+
Try
231+
Dim jsonObject = Await Task.Run(Function() NetGetCodeByRequestOnce($"https://mod.mcimirror.top/translate/{from}?{para}={Id}", Encode:=Encoding.UTF8, IsJson:=True))
232+
If jsonObject.ContainsKey("translated") Then
233+
result = jsonObject("translated").ToString()
234+
Else
235+
Hint($"{TranslatedName} 的简介暂无译文!", HintType.Critical)
236+
End If
237+
Catch ex As Exception
238+
Log(ex, "获取中文描述时出现错误!")
239+
Hint($"获取译文时出现错误,信息:{ex.Message}", HintType.Critical)
240+
End Try
241+
242+
Return result
243+
End Function
214244

215245
'实例化
216246

Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<local:MyButton x:Name="BtnIntroWiki" MinWidth="140" Text="转到 MC 百科" Padding="13,10" Margin="0,8,20,0" HorizontalAlignment="Left" />
1818
<local:MyButton x:Name="BtnIntroCopy" MinWidth="140" Text="复制名称" Padding="13,10" Margin="0,8,20,0" HorizontalAlignment="Left" />
1919
<local:MyButton x:Name="BtnIntroLinkCopy" MinWidth="140" Text="复制链接" Padding="13,10" Margin="0,8,20,0" HorizontalAlignment="Left" />
20+
<local:MyButton x:Name="BtnTranslate" MinWidth="140" Text="翻译简介" Padding="13,10" Margin="0,8,20,0" HorizontalAlignment="Left" />
2021
<local:MyButton x:Name="BtnFavorites" MinWidth="140" Text="收藏" Padding="13,10" Margin="0,8,20,0" HorizontalAlignment="Left" />
2122
</WrapPanel>
2223
</StackPanel>

Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb

+7-3
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@
224224
End Function
225225

226226
#End Region
227-
228227
Private IsFirstInit As Boolean = True
229228
Public Sub Init() Handles Me.PageEnter
230229
AniControlEnabled += 1
@@ -238,7 +237,6 @@
238237
Else
239238
PageLoaderRestart(IsForceRestart:=True)
240239
End If
241-
242240
'放置当前工程
243241
If CompItem IsNot Nothing Then PanIntro.Children.Remove(CompItem)
244242
CompItem = Project.ToCompItem(True, True)
@@ -466,5 +464,11 @@
466464
CompClipboard.CurrentText = Project.Website
467465
ClipboardSet(Project.Website)
468466
End Sub
469-
467+
'翻译简介
468+
Private Async Sub BtnTranslate_Click(sender As Object, e As RoutedEventArgs) Handles BtnTranslate.Click
469+
Hint($"正在获取 {Project.TranslatedName} 的简介译文……")
470+
Dim ChineseDescription = Await Project.ChineseDescription
471+
If ChineseDescription Is Nothing Then Return
472+
MyMsgBox($"原文:{Project.Description}{Environment.NewLine}译文:{ChineseDescription}")
473+
End Sub
470474
End Class

0 commit comments

Comments
 (0)