예제 #1
0
        private void GTranslateBt_Click(object sender, EventArgs e)
        {
            if (GSelectedLanguageCb.SelectedItem == null)
            {
                MessageBox.Show("Please Select a Language to translate !");
                return;
            }
            if (GTranslateLanguageCb.SelectedItem == null)
            {
                MessageBox.Show("Please Select a Language to use for the translation !");
                return;
            }
            this.translateBt.Enabled = false;
            LangueObject GSelectedLanguage = (LangueObject)GSelectedLanguageCb.SelectedItem;

            if (!GTranslateLanguageCb.SelectedItem.ToString().Equals("All"))
            {
                this.GTranslate(GSelectedLanguage, GTranslateLanguageCb.SelectedItem.ToString());
            }
            else
            {
                for (int i = 0; i < GTranslateLanguageCb.Items.Count; i++)
                {
                    if (!GTranslateLanguageCb.Items[i].ToString().Equals(GSelectedLanguage.Langue) && !GTranslateLanguageCb.Items[i].ToString().Equals("All"))
                    {
                        this.GTranslate(GSelectedLanguage, GTranslateLanguageCb.Items[i].ToString());
                    }
                }
            }
            this.reloadComboBox();
            translateBt.Enabled = true;
        }
예제 #2
0
 private void languagesListBx_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (languagesListBx.SelectedItems.Count > 0)
     {
         this.selectedLangue = (LangueObject)languagesListBx.SelectedItems[0].Tag;
         this.reloadListTranslation();
     }
 }
예제 #3
0
 private void GSelectedLanguageCb_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (GSelectedLanguageCb.SelectedItem != null)
     {
         this.selectedLangue = (LangueObject)listLangueLb.SelectedItem;
         this.reloadListTranslation();
     }
 }
예제 #4
0
 private void translateFromLanguageCmbBx_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (translateFromLanguageCmbBx.SelectedItem != null)
     {
         if (this.languagesListBx.SelectedItems.Count > 0)
         {
             this.selectedLangue = (LangueObject)this.languagesListBx.SelectedItems[0].Tag;
             this.reloadListTranslation();
         }
     }
 }
예제 #5
0
        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);
            }
        }
예제 #6
0
 private void AddBt_Click(object sender, EventArgs e)
 {
     if (langueNameCb.SelectedItem != null)
     {
         if (CheckForDuplicateElement(langueNameCb.SelectedItem.ToString()))
         {
             MessageBox.Show("The language already exists");
             return;
         }
         LangueObject newLangueObject = new LangueObject(langueNameCb.SelectedItem.ToString());
         this.project.Langues.Add(newLangueObject);
         this.reloadComboBox();
     }
     else
     {
         MessageBox.Show("Please select a language !");
     }
 }
예제 #7
0
        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;
                }
            }
        }