Now tries to use current encoding to determine current language - thx fox :)

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1665 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-02-21 20:20:56 +00:00
parent be292c3637
commit d3451b359d
5 changed files with 70 additions and 6 deletions

View File

@ -246,7 +246,9 @@ namespace Nikse.SubtitleEdit.Forms
public void Initialize(Subtitle subtitle, SubtitleFormat format, Encoding encoding)
{
_autoDetectGoogleLanguage = Utilities.AutoDetectGoogleLanguage(subtitle);
_autoDetectGoogleLanguage = Utilities.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
if (string.IsNullOrEmpty(_autoDetectGoogleLanguage))
_autoDetectGoogleLanguage = Utilities.AutoDetectGoogleLanguage(subtitle); // Guess language based on subtitle contents
if (_autoDetectGoogleLanguage.ToLower() == "zh")
_autoDetectGoogleLanguage = "zh-CHS"; // Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures
CultureInfo ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);

View File

@ -107,7 +107,7 @@ namespace Nikse.SubtitleEdit.Forms
GoogleTranslate gt = new GoogleTranslate();
Subtitle subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(0,0,textBoxSourceText.Text));
gt.Initialize(subtitle, string.Empty, false);
gt.Initialize(subtitle, string.Empty, false, System.Text.Encoding.UTF8);
from = FixMsLocale(from);
to = FixMsLocale(to);
gt.DoMicrosoftTranslate(from, to);

View File

@ -92,7 +92,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
internal void Initialize(Subtitle subtitle, string title, bool googleTranslate)
internal void Initialize(Subtitle subtitle, string title, bool googleTranslate, Encoding encoding)
{
if (title != null)
Text = title;
@ -108,7 +108,10 @@ namespace Nikse.SubtitleEdit.Forms
_subtitle = subtitle;
_translatedSubtitle = new Subtitle(subtitle);
string defaultFromLanguage = Utilities.AutoDetectGoogleLanguage(subtitle);
string defaultFromLanguage = Utilities.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
if (string.IsNullOrEmpty(defaultFromLanguage))
defaultFromLanguage = Utilities.AutoDetectGoogleLanguage(subtitle); // Guess language based on subtitle contents
FillComboWithLanguages(comboBoxFrom);
int i = 0;
foreach (ComboBoxItem item in comboBoxFrom.Items)

View File

@ -4557,11 +4557,11 @@ namespace Nikse.SubtitleEdit.Forms
foreach (int index in SubtitleListview1.SelectedIndices)
selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
title += " - " + _language.SelectedLines;
googleTranslate.Initialize(selectedLines, title, useGoogle);
googleTranslate.Initialize(selectedLines, title, useGoogle, GetCurrentEncoding());
}
else
{
googleTranslate.Initialize(_subtitle, title, useGoogle);
googleTranslate.Initialize(_subtitle, title, useGoogle, GetCurrentEncoding());
}
if (googleTranslate.ShowDialog(this) == DialogResult.OK)
{

View File

@ -1066,6 +1066,65 @@ namespace Nikse.SubtitleEdit.Logic
return count;
}
public static string AutoDetectGoogleLanguage(Encoding encoding)
{
if (encoding.CodePage == 949)
return "ko"; // Korean
if (encoding.CodePage == 950)
return "zh"; // Chinese
if (encoding.CodePage == 1253)
return "el"; // Greek
if (encoding.CodePage == 1254)
return "tr"; // Turkish
if (encoding.CodePage == 1255)
return "he"; // Hebrew
if (encoding.CodePage == 1256)
return "ar"; // Arabic
if (encoding.CodePage == 1258)
return "vi"; // Vietnamese
if (encoding.CodePage == 1361)
return "ko"; // Korean
if (encoding.CodePage == 10001)
return "ja"; // Japanese
if (encoding.CodePage == 20000)
return "zh"; // Chinese
if (encoding.CodePage == 20002)
return "zh"; // Chinese
if (encoding.CodePage == 20932)
return "ja"; // Japanese
if (encoding.CodePage == 20936)
return "zh"; // Chinese
if (encoding.CodePage == 20949)
return "ko"; // Korean
if (encoding.CodePage == 28596)
return "ar"; // Arabic
if (encoding.CodePage == 28597)
return "el"; // Greek
if (encoding.CodePage == 28598)
return "he"; // Hebrew
if (encoding.CodePage == 28599)
return "tr"; // Turkish
if (encoding.CodePage == 50220)
return "ja"; // Japanese
if (encoding.CodePage == 50221)
return "ja"; // Japanese
if (encoding.CodePage == 50222)
return "ja"; // Japanese
if (encoding.CodePage == 50225)
return "ko"; // Korean
if (encoding.CodePage == 51932)
return "ja"; // Japanese
if (encoding.CodePage == 51936)
return "zh"; // Chinese
if (encoding.CodePage == 51949)
return "ko"; // Korean
if (encoding.CodePage == 52936)
return "zh"; // Chinese
if (encoding.CodePage == 54936)
return "zh"; // Chinese
return null;
}
public static string AutoDetectGoogleLanguage(string text, int bestCount)
{
int count = GetCount(text, "we", "are", "and", "you", "your", "what");