private void addFieldBt_Click(object sender, EventArgs e) { if (selectedLangue == null) { MessageBox.Show("Please select a Language"); return; } if (this.newKeyTxtBx.Text.Equals("")) { MessageBox.Show("Please enter a translation key"); return; } if (this.newValueTxtBx.Text.Equals("")) { MessageBox.Show("Please enter a translation for the Key : " + newKeyTxtBx.Text); return; } if (selectedLangue.CheckForDuplicateElement(newKeyTxtBx.Text)) { MessageBox.Show("The Key " + newKeyTxtBx.Text + " is already stored."); return; } LangueElement newLangueElement = new LangueElement(newKeyTxtBx.Text, newValueTxtBx.Text); selectedLangue.TranslationElement.Add(newLangueElement); this.reloadListTranslation(); }
private void btAddTranslation_Click(object sender, EventArgs e) { if (selectedLangue == null) { MessageBox.Show("Please select a Language"); return; } if (KeyTb.Text.Equals("")) { MessageBox.Show("Please Enter a Key"); return; } if (TranslationTb.Text.Equals("")) { MessageBox.Show("Please Enter a Translation for the Key : " + KeyTb.Text); return; } if (selectedLangue.CheckForDuplicateElement(KeyTb.Text)) { MessageBox.Show("The Key " + KeyTb.Text + " is already stored."); return; } LangueElement newLangueElement = new LangueElement(KeyTb.Text, TranslationTb.Text); selectedLangue.TranslationElement.Add(newLangueElement); this.reloadListTranslation(); }
private void tranlationGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < this.tranlationGridView.Rows.Count) { DataGridViewRow rowSelected = this.tranlationGridView.Rows[e.RowIndex]; LangueElement elem = rowSelected.Tag as LangueElement; elem.Key = rowSelected.Cells[0].Value.ToString().Replace("!NL!", "\n"); elem.Translation = rowSelected.Cells[1].Value.ToString().Replace("!NL!", "\n"); } }
private void GTranslate(LangueObject From, String To) { if (From.Langue == To.ToString()) { return; } if (toolStrip1.Equals("")) { return; } LangueObject newLangue = new LangueObject(To.ToString()); String CFrom = this.GetGoogleTranslateLanguageName(From.Langue); String CTo = GetGoogleTranslateLanguageName(To.ToString()); try { for (int i = 0; i < From.TranslationElement.Count; i++) { string key = From.TranslationElement[i].Translation; MicrosoftTranslator.LanguageServiceClient TranslateC = new MicrosoftTranslator.LanguageServiceClient(); string[] l = TranslateC.GetLanguagesForTranslate("A1720512EE086AC9060D14F925EE3D0543CEDF90"); var availableLanguages = String.Join(",", l.Select(x => x.ToString()).ToArray()); MicrosoftTranslator.TranslateOptions options = new MicrosoftTranslator.TranslateOptions(); // Use the default options string translation = TranslateC.GetTranslations("A1720512EE086AC9060D14F925EE3D0543CEDF90", key.ToString(), CFrom, CTo, 1, options).Translations[0].TranslatedText; LangueElement newLangueElement = new LangueElement(key, translation); newLangue.TranslationElement.Add(newLangueElement); } } catch (Exception ex) { MessageBox.Show("It seems that Microsoft Bing translator can't perform the request."); } //Add new Language if (newLangue.TranslationElement.Count > 0) { // Check if the new language exist for (int i = 0; i < this.project.Langues.Count; i++) { if (this.project.Langues[i].Langue.Equals(To.ToString())) { // Removes the previous Langues files this.project.Langues.Remove(this.project.Langues[i]); } } this.project.Langues.Add(newLangue); } }
private void LoadtBt_Click(object sender, EventArgs e) { if (languagesListBx.SelectedItems.Count > 0) { String langue = languagesListBx.SelectedItems[0].Text; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "CSV file format (UTF-8) |*.csv"; openFileDialog1.Title = "Open as CSV File (semicolon separator)"; openFileDialog1.ShowDialog(); try { if (openFileDialog1.FileName != "" && File.Exists(openFileDialog1.FileName)) { StringBuilder buffer = new StringBuilder(); Stream stream = openFileDialog1.OpenFile(); TextReader tr = new StreamReader(stream, Encoding.UTF8); buffer.Append(tr.ReadToEnd()); tr.Close(); stream.Close(); String[] splittedbuff = buffer.ToString().Split('\n'); List <String> dicoLangue = new List <string>(); for (int i = 0; i < splittedbuff.Length; i++) { if (splittedbuff[i].StartsWith("#")) { //Is a comment, Do Nothing continue; } String[] elements = splittedbuff[i].Split(';'); for (int j = 0; j < elements.Length; j++) { dicoLangue.Add(elements[j].ToString().Replace("\n", "!NL!")); } } //Reload DicoLangue this.selectedLangue = (LangueObject)this.languagesListBx.SelectedItems[0].Tag; this.selectedLangue.TranslationElement.Clear(); for (int i = 0; i < dicoLangue.Count - 1; i++) { LangueElement newLangueElement = new LangueElement(dicoLangue[i], dicoLangue[i + 1]); this.selectedLangue.TranslationElement.Add(newLangueElement); i++; } this.reloadListTranslation(); MessageBox.Show("Import sucess!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("You need to select a CSV file to import it.", "Warning !", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }