-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.xaml.cs
2992 lines (2700 loc) · 103 KB
/
Main.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Docker.DotNet;
using Docker.DotNet.Models;
namespace T4C_Translator
{
public partial class Main : Window, INotifyPropertyChanged
{
#region Class Variables
private bool testMode;
private const string ContainerName = "libretranslate";
private const string ImageName = "libretranslate/libretranslate";
private const string DockerUri = "npipe://./pipe/docker_engine";
private readonly string configFilePath = "config.json";
private readonly string logFilePath = @"\TranslatedLogs.txt";
private float translationSeconds = 10;
private readonly float noShade = 0;
private readonly float halfShade = 0.5F;
private readonly float fullShade = 1;
private readonly string keywordMatch = @"""([^""]*)""";
private readonly string bracketMatch = @"\{([^{}]*)\}";
private readonly System.Windows.Media.Brush whiteBrush = new SolidColorBrush(Colors.White);
private readonly System.Windows.Media.Brush grayBrush = new SolidColorBrush(Colors.Gray);
private long lastReadFilePosition = 0;
private FileSystemWatcher? logFileWatcher;
private readonly int messageDelay = 3000;
private readonly string originalWindowMessage = "T4C Log Translator - Waiting to translate...";
private string windowMessage = "T4C Log Translator - Waiting to translate...";
private string emptyFlowDocument;
readonly Encoding enc1252 = Encoding.GetEncoding(1252);
private bool loadFinished = false;
private List<TranslatedLine> translatedLines = new List<TranslatedLine>();
private List<TranslatedLineType> translatedLineTypes = new List<TranslatedLineType>();
private List<DispatcherTimer> timers = new List<DispatcherTimer>();
private List<string> hyperlinkXamlNames = new List<string>();
private DateTime lastTranslatedLineTimestamp = DateTime.MinValue;
private string lastTranslatedLine = string.Empty;
#endregion
#region Properties
private ICollectionView _quickTranslatefilteredItems;
public ICollectionView QuickTranslatefilteredItems => _quickTranslatefilteredItems;
private ObservableCollection<TranslatedLine> _quickTranslateComboBoxItems;
public ObservableCollection<TranslatedLine> QuickTranslateComboBoxItems
{
get => _quickTranslateComboBoxItems;
set
{
if (_quickTranslateComboBoxItems != value)
{
_quickTranslateComboBoxItems = value;
OnPropertyChanged(nameof(QuickTranslateComboBoxItems));
}
}
}
private ICollectionView _sourceLanguagefilteredItems;
public ICollectionView SourceLanguagefilteredItems => _sourceLanguagefilteredItems;
private ObservableCollection<string> _sourceLanguageComboBoxItems;
public ObservableCollection<string> SourceLanguageComboBoxItems
{
get => _sourceLanguageComboBoxItems;
set
{
if (_sourceLanguageComboBoxItems != value)
{
_sourceLanguageComboBoxItems = value;
OnPropertyChanged(nameof(SourceLanguageComboBoxItems));
}
}
}
private ICollectionView _outputLanguagefilteredItems;
public ICollectionView OutputLanguagefilteredItems => _outputLanguagefilteredItems;
private ObservableCollection<string> _outputLanguageComboBoxItems;
public ObservableCollection<string> OutputLanguageComboBoxItems
{
get => _outputLanguageComboBoxItems;
set
{
if (_outputLanguageComboBoxItems != value)
{
_outputLanguageComboBoxItems = value;
OnPropertyChanged(nameof(OutputLanguageComboBoxItems));
}
}
}
private string _characterName;
public string CharacterName
{
get => _characterName;
set
{
if (_characterName != value)
{
_characterName = value;
OnPropertyChanged(nameof(CharacterName));
}
}
}
private string _sourceFolder;
public string SourceFolder
{
get => _sourceFolder;
set
{
if (_sourceFolder != value)
{
_sourceFolder = value;
OnPropertyChanged(nameof(SourceFolder));
}
}
}
private string _outputFileName;
public string OutputFileName
{
get => _outputFileName;
set
{
if (_outputFileName != value)
{
_outputFileName = value;
OnPropertyChanged(nameof(OutputFileName));
}
}
}
private string _apiLimit;
public string APILimit
{
get => _apiLimit;
set
{
if (_apiLimit != value)
{
_apiLimit = value;
OnPropertyChanged(nameof(APILimit));
}
}
}
private string _apiCount;
public string APICount
{
get => _apiCount;
set
{
if (_apiCount != value)
{
if (loadFinished)
SaveConfig();
_apiCount = value;
OnPropertyChanged(nameof(APICount));
}
}
}
private string _apiKey;
public string APIKey
{
get => _apiKey;
set
{
if (_apiKey != value)
{
_apiKey = value;
OnPropertyChanged(nameof(APIKey));
}
}
}
private string _selectedOutputLanguage;
public string SelectedOutputLanguage
{
get => _selectedOutputLanguage;
set
{
if (_selectedOutputLanguage != value)
{
_selectedOutputLanguage = value;
OnPropertyChanged(nameof(SelectedOutputLanguage));
}
}
}
private string _selectedSourceLanguage;
public string SelectedSourceLanguage
{
get => _selectedSourceLanguage;
set
{
if (_selectedSourceLanguage != value)
{
_selectedSourceLanguage = value;
OnPropertyChanged(nameof(SelectedSourceLanguage));
}
}
}
private string _selectedQTOutputLanguage;
public string SelectedQTOutputLanguage
{
get => _selectedQTOutputLanguage;
set
{
if (_selectedQTOutputLanguage != value)
{
_selectedQTOutputLanguage = value;
OnPropertyChanged(nameof(SelectedQTOutputLanguage));
OnPropertyChanged(nameof(TranslatedTextLabel));
OnPropertyChanged(nameof(TexttotranslateLabel));
OnPropertyChanged(nameof(QuickTranslatefilteredItems));
OnPropertyChanged(nameof(QuickTranslateComboBoxItems));
}
}
}
private string _selectedQTSourceLanguage;
public string SelectedQTSourceLanguage
{
get => _selectedQTSourceLanguage;
set
{
if (_selectedQTSourceLanguage != value)
{
_selectedQTSourceLanguage = value;
OnPropertyChanged(nameof(SelectedQTSourceLanguage));
OnPropertyChanged(nameof(TranslatedTextLabel));
OnPropertyChanged(nameof(TexttotranslateLabel));
OnPropertyChanged(nameof(QuickTranslatefilteredItems));
OnPropertyChanged(nameof(QuickTranslateComboBoxItems));
}
}
}
private TranslatedLine _selectedQuickTranslate;
public TranslatedLine SelectedQuickTranslate
{
get => _selectedQuickTranslate;
set
{
_selectedQuickTranslate = value;
OnPropertyChanged(nameof(SelectedQuickTranslate));
}
}
private ObservableCollection<IgnoreChat> _ignoreChatComboBoxItems;
public ObservableCollection<IgnoreChat> IgnoreChatComboBoxItems
{
get => _ignoreChatComboBoxItems;
set
{
if (_ignoreChatComboBoxItems != value)
{
_ignoreChatComboBoxItems = value;
OnPropertyChanged(nameof(IgnoreChatComboBoxItems));
}
}
}
private IgnoreChat _selectedIgnoreChat;
public IgnoreChat SelectedIgnoreChat
{
get => _selectedIgnoreChat;
set
{
_selectedIgnoreChat = value;
OnPropertyChanged(nameof(SelectedIgnoreChat));
}
}
private ObservableCollection<FontColor> _fontColorComboBoxItems;
public ObservableCollection<FontColor> FontColorComboBoxItems
{
get => _fontColorComboBoxItems;
set
{
if (_fontColorComboBoxItems != value)
{
_fontColorComboBoxItems = value;
OnPropertyChanged(nameof(FontColorComboBoxItems));
}
}
}
private FontColor _selectedFontColor;
public FontColor SelectedFontColor
{
get => _selectedFontColor;
set
{
_selectedFontColor = value;
OnPropertyChanged(nameof(SelectedFontColor));
OnPropertyChanged(nameof(SelectedFontColorLight));
}
}
public string SelectedFontColorLight
{
get => ChangeColorBrightness(SelectedFontColor.Color, 0.5F);
}
private ObservableCollection<FontSize> _fontSizeComboBoxItems;
public ObservableCollection<FontSize> FontSizeComboBoxItems
{
get => _fontSizeComboBoxItems;
set
{
if (_fontSizeComboBoxItems != value)
{
_fontSizeComboBoxItems = value;
OnPropertyChanged(nameof(FontSizeComboBoxItems));
}
}
}
private FontSize _selectedFontSize;
public FontSize SelectedFontSize
{
get => _selectedFontSize;
set
{
_selectedFontSize = value;
OnPropertyChanged(nameof(SelectedFontSize));
}
}
private bool isTranslating;
public bool IsTranslating
{
get => isTranslating;
set
{
if (isTranslating != value)
{
isTranslating = value;
OnPropertyChanged(nameof(IsTranslating));
}
}
}
private bool _ignoreChatMessages;
public bool IgnoreChatMessages
{
get { return _ignoreChatMessages; }
set
{
_ignoreChatMessages = value;
OnPropertyChanged(nameof(IgnoreChatMessages));
}
}
private bool _showOriginalText;
public bool ShowOriginalText
{
get { return _showOriginalText; }
set
{
_showOriginalText = value;
OnPropertyChanged(nameof(ShowOriginalText));
}
}
private bool _useFreeAPI;
public bool UseFreeAPI
{
get { return _useFreeAPI; }
set
{
_useFreeAPI = value;
OnPropertyChanged(nameof(UseFreeAPI));
}
}
public string TexttotranslateLabel
{
get { return $"Translate to {SelectedQTSourceLanguage.ToString()}"; }
}
public string TranslatedTextLabel
{
get { return $"Translate from {SelectedQTOutputLanguage.ToString()}"; }
}
private string _statusMessage;
public string StatusMessage
{
get { return _statusMessage; }
set
{
_statusMessage = value;
OnPropertyChanged(nameof(StatusMessage));
}
}
#endregion
#region OnPropertyChanged Event Handlers
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
// Raise property changed so the UI will update in our application
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region Constructor
public Main()
{
// Set test mode on/off
testMode = false;
// Set data context and bootstrap application
InitializeComponent();
// Set default values on startup
_quickTranslateComboBoxItems = new ObservableCollection<TranslatedLine>();
_ignoreChatComboBoxItems = new ObservableCollection<IgnoreChat>();
_quickTranslateComboBoxItems = new ObservableCollection<TranslatedLine>();
_fontColorComboBoxItems = new ObservableCollection<FontColor>();
_fontSizeComboBoxItems = new ObservableCollection<FontSize>();
_sourceLanguageComboBoxItems = new ObservableCollection<string>();
_outputLanguageComboBoxItems = new ObservableCollection<string>();
_quickTranslatefilteredItems = CollectionViewSource.GetDefaultView(QuickTranslateComboBoxItems);
_sourceLanguagefilteredItems = CollectionViewSource.GetDefaultView(SourceLanguageComboBoxItems);
_outputLanguagefilteredItems = CollectionViewSource.GetDefaultView(OutputLanguageComboBoxItems);
IsTranslating = false;
UseFreeAPI = false;
IgnoreChatMessages = false;
ShowOriginalText = false;
StatusMessage = windowMessage;
OutputFileName = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + logFilePath;
SourceFolder = @"C:\Users\yourusername\AppData\Local\Dialsoft\Logs";
CharacterName = "YourCharacterName";
APIKey = "YourApiKey";
APILimit = "450000";
APICount = "0";
// Add translated line types
translatedLineTypes.Add(new TranslatedLineType() { Id = 1, Type = "Local Chat", Example = "08/10/2024 17:09:12-- {Himinbjörg}\":\" vendre" });
translatedLineTypes.Add(new TranslatedLineType() { Id = 2, Type = "Chat Channel", Example = "08/10/2024 17:18:23-- [\"Main\"] \"Astaroth Asgard\": c mort trop dur pour moi tt seul lol" });
translatedLineTypes.Add(new TranslatedLineType() { Id = 3, Type = "Server Chat", Example = "08/10/2024 17:19:12-- [Beyond The Kingdom] Il est fortement conseillé, avant d'aller voir Rackis, de faire la quête du diable (consultez {Kalastor}) si vous désirez plus tard suivre les quêtes de karma mauvais pour Beyond the Kingdom." });
translatedLineTypes.Add(new TranslatedLineType() { Id = 4, Type = "Server Message", Example = "08/10/2024 17:59:27-- Le saviez-vous ? <> Il existe des { familiers} sur Neerya. Acquis en récompense lors d'une animation ou en les achetant dans un repaire de faction, ils vous suivront partout !" });
// Load default values for comboboxes
FontColorComboBoxItems.Add(new FontColor() { Color = "#11B5CD" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#11B5CD" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#FF214B" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#5A77D8" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#DCCA06" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#05C525" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#C70ACC" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#C0C0C0" });
FontColorComboBoxItems.Add(new FontColor() { Color = "#E0640A" });
// Add languges to comboboxes
SourceLanguageComboBoxItems.Add("en");
SourceLanguageComboBoxItems.Add("fr");
SourceLanguageComboBoxItems.Add("af");
SourceLanguageComboBoxItems.Add("sq");
SourceLanguageComboBoxItems.Add("am");
SourceLanguageComboBoxItems.Add("ar");
SourceLanguageComboBoxItems.Add("hy");
SourceLanguageComboBoxItems.Add("as");
SourceLanguageComboBoxItems.Add("ay");
SourceLanguageComboBoxItems.Add("az");
SourceLanguageComboBoxItems.Add("bm");
SourceLanguageComboBoxItems.Add("eu");
SourceLanguageComboBoxItems.Add("be");
SourceLanguageComboBoxItems.Add("bn");
SourceLanguageComboBoxItems.Add("bho");
SourceLanguageComboBoxItems.Add("bs");
SourceLanguageComboBoxItems.Add("bg");
SourceLanguageComboBoxItems.Add("ca");
SourceLanguageComboBoxItems.Add("ceb");
SourceLanguageComboBoxItems.Add("co");
SourceLanguageComboBoxItems.Add("hr");
SourceLanguageComboBoxItems.Add("cs");
SourceLanguageComboBoxItems.Add("da");
SourceLanguageComboBoxItems.Add("dv");
SourceLanguageComboBoxItems.Add("doi");
SourceLanguageComboBoxItems.Add("nl");
SourceLanguageComboBoxItems.Add("eo");
SourceLanguageComboBoxItems.Add("et");
SourceLanguageComboBoxItems.Add("ee");
SourceLanguageComboBoxItems.Add("fil");
SourceLanguageComboBoxItems.Add("fi");
SourceLanguageComboBoxItems.Add("fy");
SourceLanguageComboBoxItems.Add("gl");
SourceLanguageComboBoxItems.Add("ka");
SourceLanguageComboBoxItems.Add("de");
SourceLanguageComboBoxItems.Add("el");
SourceLanguageComboBoxItems.Add("gn");
SourceLanguageComboBoxItems.Add("gu");
SourceLanguageComboBoxItems.Add("ht");
SourceLanguageComboBoxItems.Add("ha");
SourceLanguageComboBoxItems.Add("haw");
SourceLanguageComboBoxItems.Add("hi");
SourceLanguageComboBoxItems.Add("hmn");
SourceLanguageComboBoxItems.Add("hu");
SourceLanguageComboBoxItems.Add("is");
SourceLanguageComboBoxItems.Add("ig");
SourceLanguageComboBoxItems.Add("ilo");
SourceLanguageComboBoxItems.Add("id");
SourceLanguageComboBoxItems.Add("ga");
SourceLanguageComboBoxItems.Add("it");
SourceLanguageComboBoxItems.Add("ja");
SourceLanguageComboBoxItems.Add("kn");
SourceLanguageComboBoxItems.Add("kk");
SourceLanguageComboBoxItems.Add("km");
SourceLanguageComboBoxItems.Add("rw");
SourceLanguageComboBoxItems.Add("gom");
SourceLanguageComboBoxItems.Add("ko");
SourceLanguageComboBoxItems.Add("kri");
SourceLanguageComboBoxItems.Add("ku");
SourceLanguageComboBoxItems.Add("ckb");
SourceLanguageComboBoxItems.Add("ky");
SourceLanguageComboBoxItems.Add("lo");
SourceLanguageComboBoxItems.Add("la");
SourceLanguageComboBoxItems.Add("lv");
SourceLanguageComboBoxItems.Add("ln");
SourceLanguageComboBoxItems.Add("lt");
SourceLanguageComboBoxItems.Add("lg");
SourceLanguageComboBoxItems.Add("lb");
SourceLanguageComboBoxItems.Add("mk");
SourceLanguageComboBoxItems.Add("ma");
SourceLanguageComboBoxItems.Add("mg");
SourceLanguageComboBoxItems.Add("ms");
SourceLanguageComboBoxItems.Add("ml");
SourceLanguageComboBoxItems.Add("mt");
SourceLanguageComboBoxItems.Add("mi");
SourceLanguageComboBoxItems.Add("mr");
SourceLanguageComboBoxItems.Add("lus");
SourceLanguageComboBoxItems.Add("mn");
SourceLanguageComboBoxItems.Add("my");
SourceLanguageComboBoxItems.Add("ne");
SourceLanguageComboBoxItems.Add("no");
SourceLanguageComboBoxItems.Add("ny");
SourceLanguageComboBoxItems.Add("or");
SourceLanguageComboBoxItems.Add("om");
SourceLanguageComboBoxItems.Add("ps");
SourceLanguageComboBoxItems.Add("fa");
SourceLanguageComboBoxItems.Add("pl");
SourceLanguageComboBoxItems.Add("pt");
SourceLanguageComboBoxItems.Add("pa");
SourceLanguageComboBoxItems.Add("qu");
SourceLanguageComboBoxItems.Add("ro");
SourceLanguageComboBoxItems.Add("ru");
SourceLanguageComboBoxItems.Add("sm");
SourceLanguageComboBoxItems.Add("sa");
SourceLanguageComboBoxItems.Add("gd");
SourceLanguageComboBoxItems.Add("nso");
SourceLanguageComboBoxItems.Add("sr");
SourceLanguageComboBoxItems.Add("st");
SourceLanguageComboBoxItems.Add("sn");
SourceLanguageComboBoxItems.Add("sd");
SourceLanguageComboBoxItems.Add("si");
SourceLanguageComboBoxItems.Add("sk");
SourceLanguageComboBoxItems.Add("sl");
SourceLanguageComboBoxItems.Add("so");
SourceLanguageComboBoxItems.Add("es");
SourceLanguageComboBoxItems.Add("su");
SourceLanguageComboBoxItems.Add("sw");
SourceLanguageComboBoxItems.Add("sv");
SourceLanguageComboBoxItems.Add("tl");
SourceLanguageComboBoxItems.Add("tg");
SourceLanguageComboBoxItems.Add("ta");
SourceLanguageComboBoxItems.Add("tt");
SourceLanguageComboBoxItems.Add("te");
SourceLanguageComboBoxItems.Add("th");
SourceLanguageComboBoxItems.Add("ti");
SourceLanguageComboBoxItems.Add("ts");
SourceLanguageComboBoxItems.Add("tr");
SourceLanguageComboBoxItems.Add("tk");
SourceLanguageComboBoxItems.Add("ak");
SourceLanguageComboBoxItems.Add("uk");
SourceLanguageComboBoxItems.Add("ur");
SourceLanguageComboBoxItems.Add("ug");
SourceLanguageComboBoxItems.Add("uz");
SourceLanguageComboBoxItems.Add("vi");
SourceLanguageComboBoxItems.Add("cy");
SourceLanguageComboBoxItems.Add("xh");
SourceLanguageComboBoxItems.Add("yi");
SourceLanguageComboBoxItems.Add("yo");
SourceLanguageComboBoxItems.Add("zu");
OutputLanguageComboBoxItems.Add("en");
OutputLanguageComboBoxItems.Add("fr");
OutputLanguageComboBoxItems.Add("af");
OutputLanguageComboBoxItems.Add("sq");
OutputLanguageComboBoxItems.Add("am");
OutputLanguageComboBoxItems.Add("ar");
OutputLanguageComboBoxItems.Add("hy");
OutputLanguageComboBoxItems.Add("as");
OutputLanguageComboBoxItems.Add("ay");
OutputLanguageComboBoxItems.Add("az");
OutputLanguageComboBoxItems.Add("bm");
OutputLanguageComboBoxItems.Add("eu");
OutputLanguageComboBoxItems.Add("be");
OutputLanguageComboBoxItems.Add("bn");
OutputLanguageComboBoxItems.Add("bho");
OutputLanguageComboBoxItems.Add("bs");
OutputLanguageComboBoxItems.Add("bg");
OutputLanguageComboBoxItems.Add("ca");
OutputLanguageComboBoxItems.Add("ceb");
OutputLanguageComboBoxItems.Add("co");
OutputLanguageComboBoxItems.Add("hr");
OutputLanguageComboBoxItems.Add("cs");
OutputLanguageComboBoxItems.Add("da");
OutputLanguageComboBoxItems.Add("dv");
OutputLanguageComboBoxItems.Add("doi");
OutputLanguageComboBoxItems.Add("nl");
OutputLanguageComboBoxItems.Add("eo");
OutputLanguageComboBoxItems.Add("et");
OutputLanguageComboBoxItems.Add("ee");
OutputLanguageComboBoxItems.Add("fil");
OutputLanguageComboBoxItems.Add("fi");
OutputLanguageComboBoxItems.Add("fy");
OutputLanguageComboBoxItems.Add("gl");
OutputLanguageComboBoxItems.Add("ka");
OutputLanguageComboBoxItems.Add("de");
OutputLanguageComboBoxItems.Add("el");
OutputLanguageComboBoxItems.Add("gn");
OutputLanguageComboBoxItems.Add("gu");
OutputLanguageComboBoxItems.Add("ht");
OutputLanguageComboBoxItems.Add("ha");
OutputLanguageComboBoxItems.Add("haw");
OutputLanguageComboBoxItems.Add("hi");
OutputLanguageComboBoxItems.Add("hmn");
OutputLanguageComboBoxItems.Add("hu");
OutputLanguageComboBoxItems.Add("is");
OutputLanguageComboBoxItems.Add("ig");
OutputLanguageComboBoxItems.Add("ilo");
OutputLanguageComboBoxItems.Add("id");
OutputLanguageComboBoxItems.Add("ga");
OutputLanguageComboBoxItems.Add("it");
OutputLanguageComboBoxItems.Add("ja");
OutputLanguageComboBoxItems.Add("kn");
OutputLanguageComboBoxItems.Add("kk");
OutputLanguageComboBoxItems.Add("km");
OutputLanguageComboBoxItems.Add("rw");
OutputLanguageComboBoxItems.Add("gom");
OutputLanguageComboBoxItems.Add("ko");
OutputLanguageComboBoxItems.Add("kri");
OutputLanguageComboBoxItems.Add("ku");
OutputLanguageComboBoxItems.Add("ckb");
OutputLanguageComboBoxItems.Add("ky");
OutputLanguageComboBoxItems.Add("lo");
OutputLanguageComboBoxItems.Add("la");
OutputLanguageComboBoxItems.Add("lv");
OutputLanguageComboBoxItems.Add("ln");
OutputLanguageComboBoxItems.Add("lt");
OutputLanguageComboBoxItems.Add("lg");
OutputLanguageComboBoxItems.Add("lb");
OutputLanguageComboBoxItems.Add("mk");
OutputLanguageComboBoxItems.Add("ma");
OutputLanguageComboBoxItems.Add("mg");
OutputLanguageComboBoxItems.Add("ms");
OutputLanguageComboBoxItems.Add("ml");
OutputLanguageComboBoxItems.Add("mt");
OutputLanguageComboBoxItems.Add("mi");
OutputLanguageComboBoxItems.Add("mr");
OutputLanguageComboBoxItems.Add("lus");
OutputLanguageComboBoxItems.Add("mn");
OutputLanguageComboBoxItems.Add("my");
OutputLanguageComboBoxItems.Add("ne");
OutputLanguageComboBoxItems.Add("no");
OutputLanguageComboBoxItems.Add("ny");
OutputLanguageComboBoxItems.Add("or");
OutputLanguageComboBoxItems.Add("om");
OutputLanguageComboBoxItems.Add("ps");
OutputLanguageComboBoxItems.Add("fa");
OutputLanguageComboBoxItems.Add("pl");
OutputLanguageComboBoxItems.Add("pt");
OutputLanguageComboBoxItems.Add("pa");
OutputLanguageComboBoxItems.Add("qu");
OutputLanguageComboBoxItems.Add("ro");
OutputLanguageComboBoxItems.Add("ru");
OutputLanguageComboBoxItems.Add("sm");
OutputLanguageComboBoxItems.Add("sa");
OutputLanguageComboBoxItems.Add("gd");
OutputLanguageComboBoxItems.Add("nso");
OutputLanguageComboBoxItems.Add("sr");
OutputLanguageComboBoxItems.Add("st");
OutputLanguageComboBoxItems.Add("sn");
OutputLanguageComboBoxItems.Add("sd");
OutputLanguageComboBoxItems.Add("si");
OutputLanguageComboBoxItems.Add("sk");
OutputLanguageComboBoxItems.Add("sl");
OutputLanguageComboBoxItems.Add("so");
OutputLanguageComboBoxItems.Add("es");
OutputLanguageComboBoxItems.Add("su");
OutputLanguageComboBoxItems.Add("sw");
OutputLanguageComboBoxItems.Add("sv");
OutputLanguageComboBoxItems.Add("tl");
OutputLanguageComboBoxItems.Add("tg");
OutputLanguageComboBoxItems.Add("ta");
OutputLanguageComboBoxItems.Add("tt");
OutputLanguageComboBoxItems.Add("te");
OutputLanguageComboBoxItems.Add("th");
OutputLanguageComboBoxItems.Add("ti");
OutputLanguageComboBoxItems.Add("ts");
OutputLanguageComboBoxItems.Add("tr");
OutputLanguageComboBoxItems.Add("tk");
OutputLanguageComboBoxItems.Add("ak");
OutputLanguageComboBoxItems.Add("uk");
OutputLanguageComboBoxItems.Add("ur");
OutputLanguageComboBoxItems.Add("ug");
OutputLanguageComboBoxItems.Add("uz");
OutputLanguageComboBoxItems.Add("vi");
OutputLanguageComboBoxItems.Add("cy");
OutputLanguageComboBoxItems.Add("xh");
OutputLanguageComboBoxItems.Add("yi");
OutputLanguageComboBoxItems.Add("yo");
OutputLanguageComboBoxItems.Add("zu");
// Add font sizes 1-30 to combobox
int counter = 0;
while (counter < 30)
{
FontSizeComboBoxItems.Add(new FontSize() { Size = counter + 1 });
counter++;
}
// Set default selected items for comboboxes if not selected already
IgnoreChatComboBox.SelectedIndex = -1;
QuickTranslateComboBox.SelectedIndex = -1;
SelectedSourceLanguage = SourceLanguageComboBoxItems.FirstOrDefault(s => s == "fr");
SelectedOutputLanguage = OutputLanguageComboBoxItems.FirstOrDefault(s => s == "en");
SelectedQTSourceLanguage = SourceLanguageComboBoxItems.FirstOrDefault(s => s == "fr");
SelectedQTOutputLanguage = OutputLanguageComboBoxItems.FirstOrDefault(s => s == "en");
if (SelectedFontSize == null)
SelectedFontSize = FontSizeComboBoxItems[13];
if (SelectedFontColor == null)
SelectedFontColor = FontColorComboBoxItems[4];
// Data is set so load datacontext
DataContext = this;
// Load last saved window size
LoadWindowSize();
}
#endregion
#region Window Event Handlers
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// We are finished loading so populate saved values from config file
LoadConfig();
// Load is done so set flag to true
loadFinished = true;
}
private void LoadWindowSize()
{
// Load the window size from settings
if (Properties.Settings.Default.WindowHeight > 0)
{
this.Height = Properties.Settings.Default.WindowHeight;
}
if (Properties.Settings.Default.WindowWidth > 0)
{
this.Width = Properties.Settings.Default.WindowWidth;
}
}
private void SaveWindowSize()
{
// Save the current window size to settings
Properties.Settings.Default.WindowHeight = this.Height;
Properties.Settings.Default.WindowWidth = this.Width;
Properties.Settings.Default.Save();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
QuickTranslateComboBox.MinWidth = QuickTranslateStackPanel.ActualWidth;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
SaveWindowSize();
SaveConfig();
}
#endregion
#region Quick Translate ComboBox Event Handlers
private async void QuickTranslateComboBox_SelectionChanged(object sender, RoutedEventArgs e)
{
if (loadFinished && SelectedQuickTranslate != null)
{
System.Windows.Forms.Clipboard.SetText(SelectedQuickTranslate.TranslatedText);
StatusMessage = $"Quick translate copied to clipboard...";
QuickTranslateComboBox.SelectedIndex = -1;
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
}
}
private async void QuickTranslateComboBoxRemoveItem_Click(object sender, RoutedEventArgs e)
{
if (sender is System.Windows.Controls.Button button && button.DataContext is TranslatedLine item)
{
if (GetRichTextBoxText(ManualTranslationTextBoxOutput) != string.Empty)
{
StatusMessage = $"Quick translate removed...";
_quickTranslateComboBoxItems.Remove(item);
QuickTranslateComboBox.SelectedIndex = -1;
bool isEnabled = true;
if (IsRichTextBoxEmpty(ManualTranslationTextBoxOutput))
isEnabled = false;
else
{
foreach (TranslatedLine tl in QuickTranslatefilteredItems)
{
if (GetRichTextBoxText(ManualTranslationTextBoxOutput) == tl.TranslatedText && !IsRichTextBoxEmpty(ManualTranslationTextBoxOutput))
{
isEnabled = false;
break;
}
}
}
AddQuickTranslateButton.IsEnabled = isEnabled;
}
SaveConfig();
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
}
}
private async void QTOutputLanguageComboBox_SelectionChanged(object sender, EventArgs e)
{
if (SelectedOutputLanguage != null && SelectedSourceLanguage != null)
{
_quickTranslatefilteredItems.Filter = item => ((TranslatedLine)item).OutputLanguage == SelectedQTOutputLanguage && ((TranslatedLine)item).SourceLanguage == SelectedQTSourceLanguage;
}
else
{
_quickTranslatefilteredItems.Filter = null;
}
if (loadFinished)
{
StatusMessage = $"Quick translate from: changed to ''{SelectedQTOutputLanguage}'' ...";
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
SaveConfig();
}
}
private async void QTSourceLanguageComboBox_SelectionChanged(object sender, EventArgs e)
{
if (SelectedSourceLanguage != null && SelectedSourceLanguage != null)
{
_quickTranslatefilteredItems.Filter = item => ((TranslatedLine)item).OutputLanguage == SelectedQTOutputLanguage && ((TranslatedLine)item).SourceLanguage == SelectedQTSourceLanguage;
}
else
{
_quickTranslatefilteredItems.Filter = null;
}
if (loadFinished)
{
StatusMessage = $"Quick translate to: changed to ''{SelectedQTSourceLanguage}'' ...";
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
SaveConfig();
}
}
#endregion
#region Ignore Chat ComboBox Event Handlers
private void IgnoreChatComboBox_SelectionChanged(object sender, RoutedEventArgs e)
{
IgnoreChatComboBox.SelectedIndex = -1;
}
private async void IgnoreChatComboBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (IgnoreChatComboBox.Text != null && IgnoreChatComboBox.Text != string.Empty)
{
bool ignoreChatAlreadyAdded = false;
var enteredItem = IgnoreChatComboBox.Text;
foreach (var item in _ignoreChatComboBoxItems)
{
if (item.ChatChannel == enteredItem)
{
ignoreChatAlreadyAdded = true;
break;
}
}
if (e.Key == Key.Enter && !string.IsNullOrWhiteSpace(IgnoreChatComboBox.Text) && !ignoreChatAlreadyAdded)
{
var ignoreChatChannel = new IgnoreChat();
ignoreChatChannel.ChatChannel = IgnoreChatComboBox.Text;
_ignoreChatComboBoxItems.Add(ignoreChatChannel);
StatusMessage = $"Ignore chat channel ''[{IgnoreChatComboBox.Text}]'' added...";
IgnoreChatComboBox.Text = string.Empty;
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
SaveConfig();
}
else if (e.Key == Key.Enter && ignoreChatAlreadyAdded)
{
StatusMessage = $"Ignore chat channel ''[{IgnoreChatComboBox.Text}]'' already added...";
IgnoreChatComboBox.Text = string.Empty;
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
}
}
}
private async void IgnoreChatComboBoxRemoveItem_Click(object sender, RoutedEventArgs e)
{
if (sender is System.Windows.Controls.Button button && button.DataContext is IgnoreChat item)
{
StatusMessage = $"Ignore chat channel ''[{item.ChatChannel}]'' removed...";
_ignoreChatComboBoxItems.Remove(item);
SaveConfig();
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
}
}
private void IgnoreChatComboBox_Loaded(object sender, RoutedEventArgs e)
{
var comboBox = sender as System.Windows.Controls.ComboBox;
if (comboBox != null)
{
var textBox = comboBox.Template.FindName("PART_EditableTextBox", comboBox) as System.Windows.Controls.TextBox;
if (textBox != null)
{
textBox.KeyDown += IgnoreChatComboBox_KeyDown;
}
}
}
#endregion
#region Other ComboxBox Event Handlers
private async void OutputLanguageComboBox_SelectionChanged(object sender, EventArgs e)
{
if (loadFinished)
{
StatusMessage = $"Translate to: changed to ''{SelectedOutputLanguage}'' ...";
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
SaveConfig();
}
}
private async void SourceLanguageComboBox_SelectionChanged(object sender, EventArgs e)
{
if (loadFinished)
{
StatusMessage = $"Translate from: changed to ''{SelectedSourceLanguage}'' ...";
await Task.Delay(messageDelay);
StatusMessage = windowMessage;
SaveConfig();
}
}
private async void FontSizeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{