A little more cleanup

This commit is contained in:
Nikolaj Olsson 2024-05-09 15:27:43 +02:00
parent 266ac09b80
commit 2c6bcc5db9
7 changed files with 166 additions and 178 deletions

View File

@ -1,6 +1,5 @@
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Translate; using Nikse.SubtitleEdit.Core.Translate;
using Nikse.SubtitleEdit.Core.Translate.Service;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -37,12 +36,12 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
public List<TranslationPair> GetSupportedSourceLanguages() public List<TranslationPair> GetSupportedSourceLanguages()
{ {
return GoogleTranslationService.GetTranslationPairs(); return GetTranslationPairs();
} }
public List<TranslationPair> GetSupportedTargetLanguages() public List<TranslationPair> GetSupportedTargetLanguages()
{ {
return GoogleTranslationService.GetTranslationPairs(); return GetTranslationPairs();
} }
public Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken) public Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken)
@ -72,6 +71,148 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
return Task.FromResult(string.Join(Environment.NewLine, resultList)); return Task.FromResult(string.Join(Environment.NewLine, resultList));
} }
public static List<TranslationPair> GetTranslationPairs()
{
return new List<TranslationPair>
{
new TranslationPair("AFRIKAANS", "af"),
new TranslationPair("ALBANIAN", "sq"),
new TranslationPair("AMHARIC", "am"),
new TranslationPair("ARABIC", "ar"),
new TranslationPair("ARMENIAN", "hy"),
new TranslationPair("ASSAMESE", "as"),
new TranslationPair("AYMARA", "ay"),
new TranslationPair("AZERBAIJANI", "az"),
new TranslationPair("BAMBARA", "bm"),
new TranslationPair("BASQUE", "eu"),
new TranslationPair("BELARUSIAN", "be"),
new TranslationPair("BENGALI", "bn"),
new TranslationPair("BHOJPURI", "bho"),
new TranslationPair("BOSNIAN", "bs"),
new TranslationPair("BULGARIAN", "bg"),
new TranslationPair("CATALAN", "ca"),
new TranslationPair("CEBUANO", "ceb"),
new TranslationPair("CHICHEWA", "ny"),
new TranslationPair("CHINESE", "zh"),
new TranslationPair("CHINESE_SIMPLIFIED", "zh-CN"),
new TranslationPair("CHINESE_TRADITIONAL", "zh-TW"),
new TranslationPair("CORSICAN", "co"),
new TranslationPair("CROATIAN", "hr"),
new TranslationPair("CZECH", "cs"),
new TranslationPair("DANISH", "da"),
new TranslationPair("DHIVEHI", "dv"),
new TranslationPair("DOGRI", "doi"),
new TranslationPair("DUTCH", "nl"),
new TranslationPair("ENGLISH", "en"),
new TranslationPair("ESPERANTO", "eo"),
new TranslationPair("ESTONIAN", "et"),
new TranslationPair("EWE", "ee"),
new TranslationPair("FILIPINO", "tl"),
new TranslationPair("FINNISH", "fi"),
new TranslationPair("FRENCH", "fr"),
new TranslationPair("FRISIAN", "fy"),
new TranslationPair("GALICIAN", "gl"),
new TranslationPair("GEORGIAN", "ka"),
new TranslationPair("GERMAN", "de"),
new TranslationPair("GREEK", "el"),
new TranslationPair("GUARANI", "gn"),
new TranslationPair("GUJARATI", "gu"),
new TranslationPair("HAITIAN CREOLE", "ht"),
new TranslationPair("HAUSA", "ha"),
new TranslationPair("HAWAIIAN", "haw"),
new TranslationPair("HEBREW", "he"),
new TranslationPair("HINDI", "hi"),
new TranslationPair("HMOUNG", "hmn"),
new TranslationPair("HUNGARIAN", "hu"),
new TranslationPair("ICELANDIC", "is"),
new TranslationPair("IGBO", "ig"),
new TranslationPair("ILOCANO", "ilo"),
new TranslationPair("INDONESIAN", "id"),
new TranslationPair("IRISH", "ga"),
new TranslationPair("ITALIAN", "it"),
new TranslationPair("JAPANESE", "ja"),
new TranslationPair("JAVANESE", "jw"),
new TranslationPair("KANNADA", "kn"),
new TranslationPair("KAZAKH", "kk"),
new TranslationPair("KHMER", "km"),
new TranslationPair("KINYARWANDA", "rw"),
new TranslationPair("KONKANI", "gom"),
new TranslationPair("KOREAN", "ko"),
new TranslationPair("KRIO", "kri"),
new TranslationPair("KURDISH", "ku"),
new TranslationPair("KURDISH (SORANI)", "ckb"),
new TranslationPair("KYRGYZ", "ky"),
new TranslationPair("LAO", "lo"),
new TranslationPair("LATIN", "la"),
new TranslationPair("LATVIAN", "lv"),
new TranslationPair("LINGALA", "ln"),
new TranslationPair("LITHUANIAN", "lt"),
new TranslationPair("LUGANDA", "lg"),
new TranslationPair("LUXEMBOURGISH", "lb"),
new TranslationPair("MACEDONIAN", "mk"),
new TranslationPair("MAITILI", "mai"),
new TranslationPair("MALAGASY", "mg"),
new TranslationPair("MALAY", "ms"),
new TranslationPair("MALAYALAM", "ml"),
new TranslationPair("MALTESE", "mt"),
new TranslationPair("MAORI", "mi"),
new TranslationPair("MARATHI", "mr"),
new TranslationPair("MEITEILON (MANIPURI)", "mni"),
new TranslationPair("MIZO", "lus"),
new TranslationPair("MONGOLIAN", "mn"),
new TranslationPair("MYANMAR", "my"),
new TranslationPair("NEPALI", "ne"),
new TranslationPair("NORWEGIAN", "no"),
new TranslationPair("ODIA", "or"),
new TranslationPair("OROMO", "om"),
new TranslationPair("PASHTO", "ps"),
new TranslationPair("PERSIAN", "fa"),
new TranslationPair("POLISH", "pl"),
new TranslationPair("PORTUGUESE", "pt"),
new TranslationPair("PUNJABI", "pa"),
new TranslationPair("QUECHUABI", "qu"),
new TranslationPair("ROMANIAN", "ro"),
// new TranslationPair("ROMANJI", "romanji"),
new TranslationPair("RUSSIAN", "ru"),
new TranslationPair("SAMOAN", "sm"),
new TranslationPair("SANSKRIT", "sa"),
new TranslationPair("SCOTS GAELIC", "gd"),
new TranslationPair("SEPEDI", "nso"),
new TranslationPair("SERBIAN", "sr"),
new TranslationPair("SESOTHO", "st"),
new TranslationPair("SHONA", "sn"),
new TranslationPair("SINDHI", "sd"),
new TranslationPair("SINHALA", "si"),
new TranslationPair("SLOVAK", "sk"),
new TranslationPair("SLOVENIAN", "sl"),
new TranslationPair("SOMALI", "so"),
new TranslationPair("SPANISH", "es"),
new TranslationPair("SUNDANESE", "su"),
new TranslationPair("SWAHILI", "sw"),
new TranslationPair("SWEDISH", "sv"),
new TranslationPair("TAJIK", "tg"),
new TranslationPair("TAMIL", "ta"),
new TranslationPair("TATAR", "tt"),
new TranslationPair("TELUGU", "te"),
new TranslationPair("THAI", "th"),
new TranslationPair("TIGRINYA", "ti"),
new TranslationPair("TSONGA", "ts"),
new TranslationPair("TURKISH", "tr"),
new TranslationPair("TWI", "ak"),
new TranslationPair("TURKMEN", "tk"),
new TranslationPair("UKRAINIAN", "uk"),
new TranslationPair("URDU", "ur"),
new TranslationPair("UYGHUR", "ug"),
new TranslationPair("UZBEK", "uz"),
new TranslationPair("VIETNAMESE", "vi"),
new TranslationPair("WELSH", "cy"),
new TranslationPair("XHOSA", "xh"),
new TranslationPair("YIDDISH", "yi"),
new TranslationPair("YORUBA", "yo"),
new TranslationPair("ZULU", "zu"),
};
}
private static List<string> ConvertJsonObjectToStringLines(string result) private static List<string> ConvertJsonObjectToStringLines(string result)
{ {
var sbAll = new StringBuilder(); var sbAll = new StringBuilder();

View File

@ -1,4 +1,7 @@
using System; using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Http;
using Nikse.SubtitleEdit.Core.Translate;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
@ -7,10 +10,6 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Http;
using Nikse.SubtitleEdit.Core.Translate;
using Nikse.SubtitleEdit.Core.Translate.Service;
namespace Nikse.SubtitleEdit.Core.AutoTranslate namespace Nikse.SubtitleEdit.Core.AutoTranslate
{ {
@ -38,12 +37,12 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
public List<TranslationPair> GetSupportedSourceLanguages() public List<TranslationPair> GetSupportedSourceLanguages()
{ {
return GoogleTranslationService.GetTranslationPairs(); return GoogleTranslateV1.GetTranslationPairs();
} }
public List<TranslationPair> GetSupportedTargetLanguages() public List<TranslationPair> GetSupportedTargetLanguages()
{ {
return GoogleTranslationService.GetTranslationPairs(); return GoogleTranslateV1.GetTranslationPairs();
} }
public Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken) public Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken)

View File

@ -1,4 +1,8 @@
using System; using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Http;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.Translate;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
@ -6,11 +10,6 @@ using System.Net.Http.Headers;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Http;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.Translate;
using Nikse.SubtitleEdit.Core.Translate.Service;
namespace Nikse.SubtitleEdit.Core.AutoTranslate namespace Nikse.SubtitleEdit.Core.AutoTranslate
{ {

View File

@ -1,149 +0,0 @@
using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Core.Translate.Service
{
public class GoogleTranslationService
{
public static List<TranslationPair> GetTranslationPairs()
{
return new List<TranslationPair>
{
new TranslationPair("AFRIKAANS", "af"),
new TranslationPair("ALBANIAN", "sq"),
new TranslationPair("AMHARIC", "am"),
new TranslationPair("ARABIC", "ar"),
new TranslationPair("ARMENIAN", "hy"),
new TranslationPair("ASSAMESE", "as"),
new TranslationPair("AYMARA", "ay"),
new TranslationPair("AZERBAIJANI", "az"),
new TranslationPair("BAMBARA", "bm"),
new TranslationPair("BASQUE", "eu"),
new TranslationPair("BELARUSIAN", "be"),
new TranslationPair("BENGALI", "bn"),
new TranslationPair("BHOJPURI", "bho"),
new TranslationPair("BOSNIAN", "bs"),
new TranslationPair("BULGARIAN", "bg"),
new TranslationPair("CATALAN", "ca"),
new TranslationPair("CEBUANO", "ceb"),
new TranslationPair("CHICHEWA", "ny"),
new TranslationPair("CHINESE", "zh"),
new TranslationPair("CHINESE_SIMPLIFIED", "zh-CN"),
new TranslationPair("CHINESE_TRADITIONAL", "zh-TW"),
new TranslationPair("CORSICAN", "co"),
new TranslationPair("CROATIAN", "hr"),
new TranslationPair("CZECH", "cs"),
new TranslationPair("DANISH", "da"),
new TranslationPair("DHIVEHI", "dv"),
new TranslationPair("DOGRI", "doi"),
new TranslationPair("DUTCH", "nl"),
new TranslationPair("ENGLISH", "en"),
new TranslationPair("ESPERANTO", "eo"),
new TranslationPair("ESTONIAN", "et"),
new TranslationPair("EWE", "ee"),
new TranslationPair("FILIPINO", "tl"),
new TranslationPair("FINNISH", "fi"),
new TranslationPair("FRENCH", "fr"),
new TranslationPair("FRISIAN", "fy"),
new TranslationPair("GALICIAN", "gl"),
new TranslationPair("GEORGIAN", "ka"),
new TranslationPair("GERMAN", "de"),
new TranslationPair("GREEK", "el"),
new TranslationPair("GUARANI", "gn"),
new TranslationPair("GUJARATI", "gu"),
new TranslationPair("HAITIAN CREOLE", "ht"),
new TranslationPair("HAUSA", "ha"),
new TranslationPair("HAWAIIAN", "haw"),
new TranslationPair("HEBREW", "he"),
new TranslationPair("HINDI", "hi"),
new TranslationPair("HMOUNG", "hmn"),
new TranslationPair("HUNGARIAN", "hu"),
new TranslationPair("ICELANDIC", "is"),
new TranslationPair("IGBO", "ig"),
new TranslationPair("ILOCANO", "ilo"),
new TranslationPair("INDONESIAN", "id"),
new TranslationPair("IRISH", "ga"),
new TranslationPair("ITALIAN", "it"),
new TranslationPair("JAPANESE", "ja"),
new TranslationPair("JAVANESE", "jw"),
new TranslationPair("KANNADA", "kn"),
new TranslationPair("KAZAKH", "kk"),
new TranslationPair("KHMER", "km"),
new TranslationPair("KINYARWANDA", "rw"),
new TranslationPair("KONKANI", "gom"),
new TranslationPair("KOREAN", "ko"),
new TranslationPair("KRIO", "kri"),
new TranslationPair("KURDISH", "ku"),
new TranslationPair("KURDISH (SORANI)", "ckb"),
new TranslationPair("KYRGYZ", "ky"),
new TranslationPair("LAO", "lo"),
new TranslationPair("LATIN", "la"),
new TranslationPair("LATVIAN", "lv"),
new TranslationPair("LINGALA", "ln"),
new TranslationPair("LITHUANIAN", "lt"),
new TranslationPair("LUGANDA", "lg"),
new TranslationPair("LUXEMBOURGISH", "lb"),
new TranslationPair("MACEDONIAN", "mk"),
new TranslationPair("MAITILI", "mai"),
new TranslationPair("MALAGASY", "mg"),
new TranslationPair("MALAY", "ms"),
new TranslationPair("MALAYALAM", "ml"),
new TranslationPair("MALTESE", "mt"),
new TranslationPair("MAORI", "mi"),
new TranslationPair("MARATHI", "mr"),
new TranslationPair("MEITEILON (MANIPURI)", "mni"),
new TranslationPair("MIZO", "lus"),
new TranslationPair("MONGOLIAN", "mn"),
new TranslationPair("MYANMAR", "my"),
new TranslationPair("NEPALI", "ne"),
new TranslationPair("NORWEGIAN", "no"),
new TranslationPair("ODIA", "or"),
new TranslationPair("OROMO", "om"),
new TranslationPair("PASHTO", "ps"),
new TranslationPair("PERSIAN", "fa"),
new TranslationPair("POLISH", "pl"),
new TranslationPair("PORTUGUESE", "pt"),
new TranslationPair("PUNJABI", "pa"),
new TranslationPair("QUECHUABI", "qu"),
new TranslationPair("ROMANIAN", "ro"),
// new TranslationPair("ROMANJI", "romanji"),
new TranslationPair("RUSSIAN", "ru"),
new TranslationPair("SAMOAN", "sm"),
new TranslationPair("SANSKRIT", "sa"),
new TranslationPair("SCOTS GAELIC", "gd"),
new TranslationPair("SEPEDI", "nso"),
new TranslationPair("SERBIAN", "sr"),
new TranslationPair("SESOTHO", "st"),
new TranslationPair("SHONA", "sn"),
new TranslationPair("SINDHI", "sd"),
new TranslationPair("SINHALA", "si"),
new TranslationPair("SLOVAK", "sk"),
new TranslationPair("SLOVENIAN", "sl"),
new TranslationPair("SOMALI", "so"),
new TranslationPair("SPANISH", "es"),
new TranslationPair("SUNDANESE", "su"),
new TranslationPair("SWAHILI", "sw"),
new TranslationPair("SWEDISH", "sv"),
new TranslationPair("TAJIK", "tg"),
new TranslationPair("TAMIL", "ta"),
new TranslationPair("TATAR", "tt"),
new TranslationPair("TELUGU", "te"),
new TranslationPair("THAI", "th"),
new TranslationPair("TIGRINYA", "ti"),
new TranslationPair("TSONGA", "ts"),
new TranslationPair("TURKISH", "tr"),
new TranslationPair("TWI", "ak"),
new TranslationPair("TURKMEN", "tk"),
new TranslationPair("UKRAINIAN", "uk"),
new TranslationPair("URDU", "ur"),
new TranslationPair("UYGHUR", "ug"),
new TranslationPair("UZBEK", "uz"),
new TranslationPair("VIETNAMESE", "vi"),
new TranslationPair("WELSH", "cy"),
new TranslationPair("XHOSA", "xh"),
new TranslationPair("YIDDISH", "yi"),
new TranslationPair("YORUBA", "yo"),
new TranslationPair("ZULU", "zu"),
};
}
}
}

View File

@ -1,10 +1,11 @@
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Controls;
using Nikse.SubtitleEdit.Core.AutoTranslate;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Enums; using Nikse.SubtitleEdit.Core.Enums;
using Nikse.SubtitleEdit.Core.SubtitleFormats; using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.Translate.Service; using Nikse.SubtitleEdit.Forms.BeautifyTimeCodes;
using Nikse.SubtitleEdit.Logic; using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.VideoPlayers; using Nikse.SubtitleEdit.Logic.VideoPlayers;
using Nikse.SubtitleEdit.Forms.BeautifyTimeCodes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -15,8 +16,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Controls;
using Nikse.SubtitleEdit.Core.AutoTranslate;
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
namespace Nikse.SubtitleEdit.Forms.Options namespace Nikse.SubtitleEdit.Forms.Options

View File

@ -1,4 +1,4 @@
namespace Nikse.SubtitleEdit.Forms namespace Nikse.SubtitleEdit.Forms.Translate
{ {
partial class GoogleOrMicrosoftTranslate partial class GoogleOrMicrosoftTranslate
{ {

View File

@ -1,14 +1,13 @@
using Nikse.SubtitleEdit.Core.AutoTranslate; using System;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Translate;
using Nikse.SubtitleEdit.Forms.Translate;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.AutoTranslate;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.Translate;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms namespace Nikse.SubtitleEdit.Forms.Translate
{ {
public sealed partial class GoogleOrMicrosoftTranslate : Form public sealed partial class GoogleOrMicrosoftTranslate : Form
{ {