Skip to content

Commit

Permalink
v1.0 Translation and more...
Browse files Browse the repository at this point in the history
  • Loading branch information
hopto-dot committed Aug 23, 2020
1 parent 3625a65 commit ae79418
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 62 deletions.
6 changes: 3 additions & 3 deletions Japanese Conjugation Helper/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
</configuration>
13 changes: 11 additions & 2 deletions Japanese Conjugation Helper/Japanese Conjugation Helper.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<AssemblyName>Japanese Conjugation Helper</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Console</MyType>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
<PublishUrl>C:\Users\PC-IVCHSPD\Desktop\Conjugator\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -26,7 +28,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand All @@ -39,6 +40,7 @@
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>Japanese Conjugation Helper.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -49,6 +51,7 @@
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>Japanese Conjugation Helper.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
Expand All @@ -66,10 +69,14 @@
<ApplicationIcon>ConjugatorIco.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Speech" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -93,6 +100,7 @@
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -124,6 +132,7 @@
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
Expand Down
70 changes: 56 additions & 14 deletions Japanese Conjugation Helper/Module1.vb
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -1587,17 +1611,17 @@ Module Module1
Else
Console.WriteLine(WriteWord & ": " & Definition(I - 1))
End If
Console.WriteLine()
'Console.WriteLine()
WriteWord2 = ""


Array.Resize(Definition, Definition.Length + 1)
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.")
Expand Down Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions Japanese Conjugation Helper/My Project/Resources.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 31 additions & 31 deletions Japanese Conjugation Helper/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Japanese Conjugation Helper/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
</packages>

0 comments on commit ae79418

Please sign in to comment.