void LoadLanguages() { LockUpdate(true); lbFrom.BeginUpdate(); lbFrom.Items.Clear(); lbTo.Items.Clear(); LanguageCollection fromLangs = new LanguageCollection(); int index; foreach (LanguagePair lp in languages) { index = fromLangs.BinarySearch(lp.From); if (index < 0) { fromLangs.Insert(~index, lp.From); } } string val = ""; if (fromLangs.Count > 1) { val = "+" + LangPack.TranslateLanguage(Language.Any); lbFrom.Items.Add(new LanguageDataContainer(Language.Any, val)); } foreach (Language l in fromLangs) { val = LangPack.TranslateLanguage(l); if (l == Language.Autodetect) { val = "÷" + val; } lbFrom.Items.Add(new LanguageDataContainer(l, val)); } lbFrom.EndUpdate(); if (lbFrom.Items.Count > 0 && !profileChanging) { lbFrom.SelectedIndex = 0; } LockUpdate(false); }
public GoogleTranslator() { LanguageCollection tmp = new LanguageCollection(languages); foreach (Language from in languages) { foreach (Language to in tmp) { if (from != to && to != Language.Autodetect) { if (from == Language.English) { AddSupportedTranslationFromEnglish(to); if (to == Language.Filipino) { AddSupportedTranslationFromEnglish(Language.Tagalog); } } else if (to == Language.English) { AddSupportedTranslationToEnglish(from); if (from == Language.Filipino) { AddSupportedTranslationToEnglish(Language.Tagalog); } } else { AddSupportedTranslation(from, to); if (from == Language.Filipino) { AddSupportedTranslation(Language.Tagalog, to); } else if (to == Language.Filipino) { AddSupportedTranslation(from, Language.Tagalog); } } } } } AddSupportedSubject(SubjectConstants.Common); CharsLimit = 2500; }
public LiveTranslator() { CharsLimit = 15000; WordsLimit = 500; Name = "_translator"; AddSupportedSubject(SubjectConstants.Common); LanguageCollection tmp = new LanguageCollection(); LanguageCollection languages = new LanguageCollection(); foreach (KeyValuePair <Language, string> kvp in langToKey) { if (kvp.Key != Language.English_GB && kvp.Key != Language.English_US) { tmp.Add(kvp.Key); languages.Add(kvp.Key); } } foreach (Language from in languages) { foreach (Language to in tmp) { if (from != to && to != Language.Autodetect) { if (from == Language.English) { AddSupportedTranslationFromEnglish(to); } else if (to == Language.English) { AddSupportedTranslationToEnglish(from); } else { AddSupportedTranslation(from, to); } } } } }
void LoadLanguages() { SuspendLayout(); lbFrom.Items.Clear(); lbTo.Items.Clear(); LanguageCollection fromLangs = new LanguageCollection(); LanguageCollection toLangs = new LanguageCollection(); foreach (LanguagePair lp in Manager.LanguagePairServiceItems.Keys) { if (!fromLangs.Contains(lp.From)) { fromLangs.Add(lp.From); } if (!toLangs.Contains(lp.To)) { toLangs.Add(lp.To); } } fromLangs.Sort(); string val = ""; int idx; val = "+" + TranslateString("Toggle all"); lbFrom.Items.Add(new LanguageDataContainer(Language.Any, val)); foreach (Language l in fromLangs) { val = LangPack.TranslateLanguage(l); idx = lbFrom.Items.Add(new LanguageDataContainer(l, val)); lbFrom.SetItemChecked(idx, !profile.DisabledSourceLanguages.Contains(l)); } lbFrom.SetItemChecked(0, lbFrom.CheckedItems.Count == fromLangs.Count); if (lbFrom.Items.Count > 0) { lbFrom.SelectedIndex = 0; } toLangs.Sort(); val = "+" + TranslateString("Toggle all"); lbTo.Items.Add(new LanguageDataContainer(Language.Any, val)); foreach (Language l in toLangs) { val = LangPack.TranslateLanguage(l); idx = lbTo.Items.Add(new LanguageDataContainer(l, val)); lbTo.SetItemChecked(idx, !profile.DisabledTargetLanguages.Contains(l)); } lbTo.SetItemChecked(0, lbTo.CheckedItems.Count == toLangs.Count); if (lbTo.Items.Count > 0) { lbTo.SelectedIndex = 0; } ResumeLayout(true); }
public ReadOnlyLanguageCollection(LanguageCollection list) : base(list) { }
public LanguageCollection(LanguageCollection list) : base(list) { }
void LbFromSelectedIndexChanged(object sender, EventArgs e) { LockUpdate(true); if (lbFrom.SelectedIndex == -1) { return; } Language fromLanguage = ((LanguageDataContainer)lbFrom.SelectedItem).Language; LanguageDataContainer toLanguage = null; if (lbTo.SelectedItem != null) { toLanguage = ((LanguageDataContainer)lbTo.SelectedItem); } lbTo.BeginUpdate(); lbTo.Items.Clear(); LanguageCollection toLangs = new LanguageCollection(); int index; foreach (LanguagePair lp in languages) { if ((lp.From == fromLanguage || fromLanguage == Language.Any)) { index = toLangs.BinarySearch(lp.To); if (index < 0) { toLangs.Insert(~index, lp.To); } } } string val = ""; if (toLangs.Count > 1) { val = "+" + LangPack.TranslateLanguage(Language.Any); lbTo.Items.Add(new LanguageDataContainer(Language.Any, val)); } foreach (Language l in toLangs) { val = LangPack.TranslateLanguage(l); lbTo.Items.Add(new LanguageDataContainer(l, val)); } lbTo.EndUpdate(); string caption = LangPack.TranslateLanguage(fromLanguage); lFrom.Text = caption; int idx = -1; if (toLanguage != null) { idx = lbTo.Items.IndexOf(toLanguage); } if (idx == -1) { idx = 0; } lbTo.SelectedIndex = idx; LockUpdate(false); }