diff --git a/.vs/CsgoTranslator/v16/.suo b/.vs/CsgoTranslator/v16/.suo index 1188a80..5e88a30 100644 Binary files a/.vs/CsgoTranslator/v16/.suo and b/.vs/CsgoTranslator/v16/.suo differ diff --git a/CsgoTranslator/Controllers/LogsController.cs b/CsgoTranslator/Controllers/LogsController.cs index e6d4250..2fa5a20 100644 --- a/CsgoTranslator/Controllers/LogsController.cs +++ b/CsgoTranslator/Controllers/LogsController.cs @@ -37,7 +37,7 @@ static public void LoadLogs(int amount) { Chat chat = new Chat(chatTypes[i], names[i], messages[i]); Chats.Add(chat); - if(chat.ChatType == ChatType.All) + if(chat.ChatType == ChatType.All && chat.Translation != chat.Message && chat.Translation != "") { TelnetHelper.SendTranslationInTeamChat(chat); } diff --git a/CsgoTranslator/Helpers/Translator.cs b/CsgoTranslator/Helpers/Translator.cs index 8a9b5b9..9b9a375 100644 --- a/CsgoTranslator/Helpers/Translator.cs +++ b/CsgoTranslator/Helpers/Translator.cs @@ -10,11 +10,15 @@ namespace CsgoTranslator /// public static class Translator { - public static string Translate(string sourceText) + public static string Translate(string sourceText, string lang = null) { //Downloading translation + if(lang == null) + { + lang = Properties.Settings.Default.Lang; + } - string url = string.Format("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={0}&dt=t&q={1}",Properties.Settings.Default.Lang,HttpUtility.UrlEncode (sourceText)); + string url = string.Format("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={0}&dt=t&q={1}", lang , HttpUtility.UrlEncode (sourceText)); string outputFile = Path.GetTempFileName(); //sometimes will throw an exeption when too many requests are made @@ -30,7 +34,7 @@ public static string Translate(string sourceText) } catch(Exception) { - return null; + return ""; } } } diff --git a/CsgoTranslator/MinimalisticTelnet/MinimalisticTelnet.cs b/CsgoTranslator/MinimalisticTelnet/MinimalisticTelnet.cs index e06ecbb..697d831 100644 --- a/CsgoTranslator/MinimalisticTelnet/MinimalisticTelnet.cs +++ b/CsgoTranslator/MinimalisticTelnet/MinimalisticTelnet.cs @@ -61,7 +61,9 @@ private bool Connect() public void WriteLine(string cmd) { - byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes((cmd + "\n").Replace("\0xFF", "\0xFF\0xFF")); + var utf8 = Encoding.UTF8; + byte[] buf = utf8.GetBytes((cmd + "\n").Replace("\0xFF", "\0xFF\0xFF")); + _tcpSocket.GetStream().Write(buf, 0, buf.Length); } diff --git a/CsgoTranslator/Models/Command.cs b/CsgoTranslator/Models/Command.cs index 134455b..7ad12ae 100644 --- a/CsgoTranslator/Models/Command.cs +++ b/CsgoTranslator/Models/Command.cs @@ -1,11 +1,13 @@ -namespace CsgoTranslator +using System; + +namespace CsgoTranslator { public abstract class Command { public string Name { get; private set; } public string Message { get; set; } public ChatType ChatType { get; private set; } - public string CommandParams { get; private set; } + public string LangParam { get; private set; } private bool _executed; public bool Executed @@ -20,12 +22,13 @@ public bool Executed } } - protected Command(ChatType chatType, string name, string message, string commandParams = null) + protected Command(ChatType chatType, string name, string message, string langParam = null) { this.Name = name; this.Message = message; this.ChatType = chatType; - this.CommandParams = commandParams; + this.LangParam = langParam; + Console.WriteLine($"param: {langParam}"); this.Executed = false; } diff --git a/CsgoTranslator/Models/TransAllCommand.cs b/CsgoTranslator/Models/TransAllCommand.cs index b5b6fdf..15c6122 100644 --- a/CsgoTranslator/Models/TransAllCommand.cs +++ b/CsgoTranslator/Models/TransAllCommand.cs @@ -6,7 +6,7 @@ public TransAllCommand(ChatType chatType, string name, string message, string co public override void Execute() { - TelnetHelper.SendInAllChat(Translator.Translate(this.Message)); + TelnetHelper.SendInAllChat(Translator.Translate(this.Message, this.LangParam)); this.Executed = true; } } diff --git a/CsgoTranslator/Models/TransTeamCommand.cs b/CsgoTranslator/Models/TransTeamCommand.cs index f6624ce..3202632 100644 --- a/CsgoTranslator/Models/TransTeamCommand.cs +++ b/CsgoTranslator/Models/TransTeamCommand.cs @@ -6,7 +6,13 @@ public TransTeamCommand(ChatType chatType, string name, string message, string c public override void Execute() { - TelnetHelper.SendInTeamChat(Translator.Translate(this.Message)); + string translation = Translator.Translate(this.Message, this.LangParam).Trim(); + + if(translation != this.Message && translation != "") + { + TelnetHelper.SendInTeamChat(translation); + } + this.Executed = true; } } diff --git a/CsgoTranslator/bin/Release/CsgoTranslator.exe b/CsgoTranslator/bin/Release/CsgoTranslator.exe index ee651df..8a2cb5b 100644 Binary files a/CsgoTranslator/bin/Release/CsgoTranslator.exe and b/CsgoTranslator/bin/Release/CsgoTranslator.exe differ diff --git a/CsgoTranslator/bin/Release/CsgoTranslator.pdb b/CsgoTranslator/bin/Release/CsgoTranslator.pdb index bb86252..8fa4253 100644 Binary files a/CsgoTranslator/bin/Release/CsgoTranslator.pdb and b/CsgoTranslator/bin/Release/CsgoTranslator.pdb differ diff --git a/CsgoTranslator/obj/Release/CSGO-Translator.csproj.CoreCompileInputs.cache b/CsgoTranslator/obj/Release/CSGO-Translator.csproj.CoreCompileInputs.cache index 7f43f86..9661da1 100644 --- a/CsgoTranslator/obj/Release/CSGO-Translator.csproj.CoreCompileInputs.cache +++ b/CsgoTranslator/obj/Release/CSGO-Translator.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -68c945506b189a3d5b31c15201a3460debf61d1e +257c914ca1429d5075537121b4af7d402a879d45 diff --git a/CsgoTranslator/obj/Release/CSGO-Translator.csprojAssemblyReference.cache b/CsgoTranslator/obj/Release/CSGO-Translator.csprojAssemblyReference.cache index a9cce0e..1f94fb6 100644 Binary files a/CsgoTranslator/obj/Release/CSGO-Translator.csprojAssemblyReference.cache and b/CsgoTranslator/obj/Release/CSGO-Translator.csprojAssemblyReference.cache differ diff --git a/CsgoTranslator/obj/Release/CsgoTranslator.exe b/CsgoTranslator/obj/Release/CsgoTranslator.exe index ee651df..8a2cb5b 100644 Binary files a/CsgoTranslator/obj/Release/CsgoTranslator.exe and b/CsgoTranslator/obj/Release/CsgoTranslator.exe differ diff --git a/CsgoTranslator/obj/Release/CsgoTranslator.g.resources b/CsgoTranslator/obj/Release/CsgoTranslator.g.resources index 737fcad..385979a 100644 Binary files a/CsgoTranslator/obj/Release/CsgoTranslator.g.resources and b/CsgoTranslator/obj/Release/CsgoTranslator.g.resources differ diff --git a/CsgoTranslator/obj/Release/CsgoTranslator.pdb b/CsgoTranslator/obj/Release/CsgoTranslator.pdb index bb86252..8fa4253 100644 Binary files a/CsgoTranslator/obj/Release/CsgoTranslator.pdb and b/CsgoTranslator/obj/Release/CsgoTranslator.pdb differ diff --git a/CsgoTranslator/obj/Release/CsgoTranslator_MarkupCompile.cache b/CsgoTranslator/obj/Release/CsgoTranslator_MarkupCompile.cache index ea17def..fd604f9 100644 --- a/CsgoTranslator/obj/Release/CsgoTranslator_MarkupCompile.cache +++ b/CsgoTranslator/obj/Release/CsgoTranslator_MarkupCompile.cache @@ -12,7 +12,7 @@ TRACE C:\Users\Niek Nijland\source\repos\CSGO-Translator\CsgoTranslator\App.xaml 21361147038 -141317569001 +16-2061352256 12613261466 MainWindow.xaml;OptionsWindow.xaml; diff --git a/CsgoTranslator/obj/Release/DesignTimeResolveAssemblyReferences.cache b/CsgoTranslator/obj/Release/DesignTimeResolveAssemblyReferences.cache index c6ceba1..da5f35a 100644 Binary files a/CsgoTranslator/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/CsgoTranslator/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/CsgoTranslator/obj/Release/MainWindow.g.cs b/CsgoTranslator/obj/Release/MainWindow.g.cs index 31d0955..3f2a6c6 100644 --- a/CsgoTranslator/obj/Release/MainWindow.g.cs +++ b/CsgoTranslator/obj/Release/MainWindow.g.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "033F05B18CE74F62E82BED1D099F5854C700B4444B150145057897EF56FB156D" +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "350E6D81018B1C2F7DA8EB6D8E18D815F057F757A9325740339BDF75CB8EE4FE" //------------------------------------------------------------------------------ // // This code was generated by a tool. diff --git a/CsgoTranslator/obj/Release/MainWindow.g.i.cs b/CsgoTranslator/obj/Release/MainWindow.g.i.cs index 31d0955..3f2a6c6 100644 --- a/CsgoTranslator/obj/Release/MainWindow.g.i.cs +++ b/CsgoTranslator/obj/Release/MainWindow.g.i.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "033F05B18CE74F62E82BED1D099F5854C700B4444B150145057897EF56FB156D" +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "350E6D81018B1C2F7DA8EB6D8E18D815F057F757A9325740339BDF75CB8EE4FE" //------------------------------------------------------------------------------ // // This code was generated by a tool.