[Only registered and activated users can see links. Click Here To Register...]
Download
[Only registered and activated users can see links. Click Here To Register...]
Source
Download
[Only registered and activated users can see links. Click Here To Register...]
Source
Imports System.IO
Imports System.Net.Http
Imports System.Text.Json
Imports System.Text.Json.Nodes
Imports System.Threading.Tasks
Public Class JTT
Private ReadOnly httpClient As New HttpClient()
Private stringsToTranslate As Integer = 0
Private translatedCount As Integer = 0
Private Sub JTTMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim languages As String() = {"en", "de", "fr", "es", "ru", "zh", "it", "ja"}
ComboBoxSource.Items.AddRange(languages)
ComboBoxTarget.Items.AddRange(languages)
ComboBoxSource.SelectedItem = "en"
ComboBoxTarget.SelectedItem = "de"
End Sub
Private Async Sub TSMRead_Click(sender As Object, e As EventArgs) Handles TSMRead.Click
If ComboBoxSource.SelectedItem Is Nothing OrElse ComboBoxTarget.SelectedItem Is Nothing Then
MsgBox("Bitte wähle eine Ausgangs- und eine Zielsprache aus.", MsgBoxStyle.Exclamation)
Return
End If
Dim openFileDialog As New OpenFileDialog With {.Filter = "JSON Files|*.json", .Title = "Wähle die Minecraft Sprachdatei aus"}
If openFileDialog.ShowDialog() = DialogResult.OK Then
TSMRead.Enabled = False
' Datei in RichTextBox laden
RichTextBox1.Text = File.ReadAllText(openFileDialog.FileName)
Await ProcessTranslationAsync(openFileDialog.FileName, ComboBoxSource.SelectedItem.ToString(), ComboBoxTarget.SelectedItem.ToString())
TSMRead.Enabled = True
End If
End Sub
Private Async Function ProcessTranslationAsync(filePath As String, sourceLang As String, targetLang As String) As Task
Dim jsonContent As String = File.ReadAllText(filePath)
Dim rootNode As JsonNode = JsonNode.Parse(jsonContent)
' Fortschritt initialisieren
translatedCount = 0
stringsToTranslate = CountStrings(rootNode)
ProgressBar1.Value = 0
ProgressBar1.Maximum = stringsToTranslate
' Rekursive Übersetzung
Await TranslateNodeRecursiveAsync(rootNode, sourceLang, targetLang)
' Ergebnis in RichTextBox und speichern
Dim options As New JsonSerializerOptions With {.WriteIndented = True, .Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Unsafe RelaxedJsonEscaping}
Dim outputJson As String = rootNode.ToJsonString(options)
RichTextBox1.Text = outputJson ' Nur das Ergebnis anzeigen
Dim savePath As String = Path.Combine(Path.GetDirectoryName(filePath), $"{targetLang}_translated.json")
File.WriteAllText(savePath, outputJson)
MsgBox("Übersetzung abgeschlossen!", MsgBoxStyle.Information)
End Function
' Hilfsfunktion zum Zählen der Strings für die ProgressBar
Private Function CountStrings(node As JsonNode) As Integer
Dim count As Integer = 0
If node Is Nothing Then Return 0
If node.GetValueKind() = JsonValueKind.String Then Return 1
If TypeOf node Is JsonObject Then
For Each kvp In node.AsObject() : count += CountStrings(kvp.Value) : Next
ElseIf TypeOf node Is JsonArray Then
For Each element In node.AsArray() : count += CountStrings(element) : Next
End If
Return count
End Function
Private Async Function TranslateNodeRecursiveAsync(node As JsonNode, sourceLang As String, targetLang As String) As Task
If node Is Nothing Then Return
If node.GetValueKind() = JsonValueKind.String Then
Dim originalText As String = node.GetValue(Of String)()
If Not String.IsNullOrWhiteSpace(originalText) Then
node.ReplaceWith(JsonValue.Create(Await TranslateTextAsync(originalText, sourceLang, targetLang)))
' Fortschritt aktualisieren
translatedCount += 1
ProgressBar1.Value = Math.Min(translatedCount, ProgressBar1.Maximum)
End If
ElseIf TypeOf node Is JsonObject Then
For Each kvp In node.AsObject().ToList() : Await TranslateNodeRecursiveAsync(kvp.Value, sourceLang, targetLang) : Next
ElseIf TypeOf node Is JsonArray Then
For Each element In node.AsArray().ToList() : Await TranslateNodeRecursiveAsync(element, sourceLang, targetLang) : Next
End If
End Function
Private Async Function TranslateTextAsync(text As String, fromLang As String, toLang As String) As Task(Of String)
Try
Dim url As String = $"https://translate.googleapis.com/translate_a/single?client=gtx&sl={fromLang}&tl={toLang}&dt=t&q ={Uri.EscapeDataString(text)}"
Dim response As String = Await httpClient.GetStringAsync(url)
Using doc As JsonDocument = JsonDocument.Parse(response)
Return doc.RootElement(0)(0)(0).GetString()
End Using
Catch
Return text
End Try
End Function
End Class
Imports System.Net.Http
Imports System.Text.Json
Imports System.Text.Json.Nodes
Imports System.Threading.Tasks
Public Class JTT
Private ReadOnly httpClient As New HttpClient()
Private stringsToTranslate As Integer = 0
Private translatedCount As Integer = 0
Private Sub JTTMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim languages As String() = {"en", "de", "fr", "es", "ru", "zh", "it", "ja"}
ComboBoxSource.Items.AddRange(languages)
ComboBoxTarget.Items.AddRange(languages)
ComboBoxSource.SelectedItem = "en"
ComboBoxTarget.SelectedItem = "de"
End Sub
Private Async Sub TSMRead_Click(sender As Object, e As EventArgs) Handles TSMRead.Click
If ComboBoxSource.SelectedItem Is Nothing OrElse ComboBoxTarget.SelectedItem Is Nothing Then
MsgBox("Bitte wähle eine Ausgangs- und eine Zielsprache aus.", MsgBoxStyle.Exclamation)
Return
End If
Dim openFileDialog As New OpenFileDialog With {.Filter = "JSON Files|*.json", .Title = "Wähle die Minecraft Sprachdatei aus"}
If openFileDialog.ShowDialog() = DialogResult.OK Then
TSMRead.Enabled = False
' Datei in RichTextBox laden
RichTextBox1.Text = File.ReadAllText(openFileDialog.FileName)
Await ProcessTranslationAsync(openFileDialog.FileName, ComboBoxSource.SelectedItem.ToString(), ComboBoxTarget.SelectedItem.ToString())
TSMRead.Enabled = True
End If
End Sub
Private Async Function ProcessTranslationAsync(filePath As String, sourceLang As String, targetLang As String) As Task
Dim jsonContent As String = File.ReadAllText(filePath)
Dim rootNode As JsonNode = JsonNode.Parse(jsonContent)
' Fortschritt initialisieren
translatedCount = 0
stringsToTranslate = CountStrings(rootNode)
ProgressBar1.Value = 0
ProgressBar1.Maximum = stringsToTranslate
' Rekursive Übersetzung
Await TranslateNodeRecursiveAsync(rootNode, sourceLang, targetLang)
' Ergebnis in RichTextBox und speichern
Dim options As New JsonSerializerOptions With {.WriteIndented = True, .Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Unsafe RelaxedJsonEscaping}
Dim outputJson As String = rootNode.ToJsonString(options)
RichTextBox1.Text = outputJson ' Nur das Ergebnis anzeigen
Dim savePath As String = Path.Combine(Path.GetDirectoryName(filePath), $"{targetLang}_translated.json")
File.WriteAllText(savePath, outputJson)
MsgBox("Übersetzung abgeschlossen!", MsgBoxStyle.Information)
End Function
' Hilfsfunktion zum Zählen der Strings für die ProgressBar
Private Function CountStrings(node As JsonNode) As Integer
Dim count As Integer = 0
If node Is Nothing Then Return 0
If node.GetValueKind() = JsonValueKind.String Then Return 1
If TypeOf node Is JsonObject Then
For Each kvp In node.AsObject() : count += CountStrings(kvp.Value) : Next
ElseIf TypeOf node Is JsonArray Then
For Each element In node.AsArray() : count += CountStrings(element) : Next
End If
Return count
End Function
Private Async Function TranslateNodeRecursiveAsync(node As JsonNode, sourceLang As String, targetLang As String) As Task
If node Is Nothing Then Return
If node.GetValueKind() = JsonValueKind.String Then
Dim originalText As String = node.GetValue(Of String)()
If Not String.IsNullOrWhiteSpace(originalText) Then
node.ReplaceWith(JsonValue.Create(Await TranslateTextAsync(originalText, sourceLang, targetLang)))
' Fortschritt aktualisieren
translatedCount += 1
ProgressBar1.Value = Math.Min(translatedCount, ProgressBar1.Maximum)
End If
ElseIf TypeOf node Is JsonObject Then
For Each kvp In node.AsObject().ToList() : Await TranslateNodeRecursiveAsync(kvp.Value, sourceLang, targetLang) : Next
ElseIf TypeOf node Is JsonArray Then
For Each element In node.AsArray().ToList() : Await TranslateNodeRecursiveAsync(element, sourceLang, targetLang) : Next
End If
End Function
Private Async Function TranslateTextAsync(text As String, fromLang As String, toLang As String) As Task(Of String)
Try
Dim url As String = $"https://translate.googleapis.com/translate_a/single?client=gtx&sl={fromLang}&tl={toLang}&dt=t&q ={Uri.EscapeDataString(text)}"
Dim response As String = Await httpClient.GetStringAsync(url)
Using doc As JsonDocument = JsonDocument.Parse(response)
Return doc.RootElement(0)(0)(0).GetString()
End Using
Catch
Return text
End Try
End Function
End Class