diff --git a/Japanese Conjugation Helper/App.config b/Japanese Conjugation Helper/App.config index 56efbc7..d1428ad 100644 --- a/Japanese Conjugation Helper/App.config +++ b/Japanese Conjugation Helper/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/Japanese Conjugation Helper/Japanese Conjugation Helper.vbproj b/Japanese Conjugation Helper/Japanese Conjugation Helper.vbproj index 0cef350..05387d7 100644 --- a/Japanese Conjugation Helper/Japanese Conjugation Helper.vbproj +++ b/Japanese Conjugation Helper/Japanese Conjugation Helper.vbproj @@ -11,9 +11,11 @@ Japanese Conjugation Helper 512 Console - v4.7.2 + v4.5 true true + false + C:\Users\PC-IVCHSPD\Desktop\Conjugator\ true Disk @@ -26,7 +28,6 @@ true 0 1.0.0.%2a - false false true @@ -39,6 +40,7 @@ bin\Debug\ Japanese Conjugation Helper.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false AnyCPU @@ -49,6 +51,7 @@ bin\Release\ Japanese Conjugation Helper.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false On @@ -66,10 +69,14 @@ ConjugatorIco.ico + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + @@ -93,6 +100,7 @@ True Application.myapp + True True @@ -124,6 +132,7 @@ Settings.Designer.vb + diff --git a/Japanese Conjugation Helper/Module1.vb b/Japanese Conjugation Helper/Module1.vb index da0816b..894e45c 100644 --- a/Japanese Conjugation Helper/Module1.vb +++ b/Japanese Conjugation Helper/Module1.vb @@ -1,8 +1,10 @@ -Imports System +Imports System.Web +Imports System Imports System.Net -Imports System.Text.RegularExpressions -Imports Microsoft.VisualBasic Imports System.IO +Imports System.Text +Imports Newtonsoft.Json.Linq + Module Module1 Sub Main() Console.Clear() @@ -14,12 +16,12 @@ Module Module1 Const QUOTE = """" - 'Download() + 'Template for sound 'My.Computer.Audio.Play("", AudioPlayMode.Background) - Dim ExePath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase) - Dim User As String = Mid(ExePath, ExePath.IndexOf("Users") + 7) - User = Left(User, User.IndexOf("\")) + ' Dim ExePath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase) + 'Dim User As String = Mid(ExePath, ExePath.IndexOf("Users") + 7) + 'User = Left(User, User.IndexOf("\")) If Int((50) * Rnd()) <> 2 Then Console.WriteLine("Enter a command, or type " & QUOTE & "/h" & QUOTE & " for help") @@ -28,15 +30,30 @@ Module Module1 End If 'This is getting the word that is being searched ready for more accurate search with ActualSearchWord, ActualSearch Word (should) always be in japanese while Word won't be if the user inputs english or romaji: - Dim Word As String = Console.ReadLine.ToLower 'This is the word that will be searched, this needs to be kept the same because it is the original search value that may be needed later + Dim Word As String = Console.ReadLine.ToLower.Trim 'This is the word that will be searched, this needs to be kept the same because it is the original search value that may be needed later + If Word = "" Or Word.IndexOf(vbCrLf) <> -1 Then Main() End If - If Word = "!test" Then 'This is just a test - Download() - Console.WriteLine("Done.") + Dim Translated As String = "" + If Left(Word, 1) = "!" Then + Word = Mid(Word, 2) + Console.Clear() + Console.WriteLine("Translate:") + + Console.WriteLine(Word) + Word = Word.Replace(QUOTE, "`") + Console.WriteLine() + + Translated = gtranslate(Word, "ja", "en") + If Translated.ToLower = Word Then + Translated = gtranslate(Word, "en", "ja") + End If + Translated = Translated.Replace("`", QUOTE) + Console.WriteLine(Translated) + Console.ReadLine() Main() End If @@ -1483,7 +1500,7 @@ Module Module1 'End If Console.Clear() - Console.WriteLine("Sentence breakdown (not a translator):") + Console.WriteLine("Sentence breakdown:") Console.WriteLine() Console.WriteLine(Sentence) Console.WriteLine() @@ -1576,6 +1593,13 @@ Module Module1 Catch End Try + If WordGroups.Length = 1 Or WordGroups(0).Length < 2 Then + Console.WriteLine("Trying again.") + Threading.Thread.Sleep(1000) + Console.Clear() + TranslateSentence(Sentence) + End If + WriteWord = WriteWord.Trim WriteWord2 = WriteWord2.Trim If Left(WriteWord2, 2) = ", " Then @@ -1587,7 +1611,7 @@ Module Module1 Else Console.WriteLine(WriteWord & ": " & Definition(I - 1)) End If - Console.WriteLine() + 'Console.WriteLine() WriteWord2 = "" @@ -1595,9 +1619,9 @@ Module Module1 Next Array.Resize(Definition, Definition.Length - 1) - Console.WriteLine() Console.WriteLine() + Console.WriteLine(gtranslate(Sentence, "ja", "en")) Console.WriteLine() Console.ForegroundColor = ConsoleColor.DarkGray Console.WriteLine("Note: Entering ungrammatical nonsense leads to weird results.") @@ -3821,6 +3845,24 @@ Module Module1 Return (ActualSearchWord & " (" & Snip & ")") End Function + Function GTranslate(ByVal inputtext As String, ByVal fromlangid As String, ByVal tolangid As String) As String + inputtext = HttpUtility.HtmlAttributeEncode(inputtext) + Dim step1 As New WebClient + step1.Encoding = Encoding.UTF8 + + Dim step2 As String = step1.DownloadString("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" & tolangid & "&hl=" & fromlangid & "&dt=t&dt=bd&dj=1&source=icon&q=" & inputtext) + Dim step3 As Newtonsoft.Json.Linq.JObject = JObject.Parse(step2) + Dim step4 As String = "{nothing}" + Try + step4 = step3.SelectToken("sentences[0]").SelectToken("trans").ToString() + Catch + Console.WriteLine("Error; step 4") + Threading.Thread.Sleep(1000) + Console.WriteLine(step2) + End Try + + Return step4 + End Function Sub Preferences() Const QUOTE = """" Dim MsgResponse As Integer diff --git a/Japanese Conjugation Helper/My Project/Resources.Designer.vb b/Japanese Conjugation Helper/My Project/Resources.Designer.vb index d496a7e..0bddb13 100644 --- a/Japanese Conjugation Helper/My Project/Resources.Designer.vb +++ b/Japanese Conjugation Helper/My Project/Resources.Designer.vb @@ -11,9 +11,10 @@ Option Strict On Option Explicit On +Imports System Namespace My.Resources - + 'This class was auto-generated by the StronglyTypedResourceBuilder 'class via a tool like ResGen or Visual Studio. 'To add or remove a member, edit your .ResX file then rerun ResGen @@ -21,20 +22,20 @@ Namespace My.Resources ''' ''' A strongly-typed resource class, for looking up localized strings, etc. ''' - _ + _ Friend Module Resources - + Private resourceMan As Global.System.Resources.ResourceManager - + Private resourceCulture As Global.System.Globalization.CultureInfo - + ''' ''' Returns the cached ResourceManager instance used by this class. ''' - _ + _ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then @@ -44,17 +45,17 @@ Namespace My.Resources Return resourceMan End Get End Property - + ''' ''' Overrides the current thread's CurrentUICulture property for all ''' resource lookups using this strongly typed resource class. ''' - _ + _ Friend Property Culture() As Global.System.Globalization.CultureInfo Get Return resourceCulture End Get - Set(ByVal value As Global.System.Globalization.CultureInfo) + Set resourceCulture = value End Set End Property diff --git a/Japanese Conjugation Helper/My Project/Settings.Designer.vb b/Japanese Conjugation Helper/My Project/Settings.Designer.vb index f92a8c2..fba83cd 100644 --- a/Japanese Conjugation Helper/My Project/Settings.Designer.vb +++ b/Japanese Conjugation Helper/My Project/Settings.Designer.vb @@ -13,42 +13,42 @@ Option Explicit On Namespace My - - _ + + _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) - + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + #Region "My.Settings Auto-Save Functionality" #If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean + Private Shared addedHandler As Boolean - Private Shared addedHandlerLockObject As New Object + Private Shared addedHandlerLockObject As New Object - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub + _ + Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub #End If #End Region - + Public Shared ReadOnly Property [Default]() As MySettings Get - + #If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If #End If Return defaultInstance End Get @@ -57,13 +57,13 @@ Namespace My End Namespace Namespace My - - _ + + _ Friend Module MySettingsProperty - - _ + + _ Friend ReadOnly Property Settings() As Global.Japanese_Conjugation_Helper.My.MySettings Get Return Global.Japanese_Conjugation_Helper.My.MySettings.Default diff --git a/Japanese Conjugation Helper/packages.config b/Japanese Conjugation Helper/packages.config new file mode 100644 index 0000000..a9de8b5 --- /dev/null +++ b/Japanese Conjugation Helper/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file