Exemple #1
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);
            }
        }
Exemple #2
0
        private void GTranslate(LangueObject From, String To)
        {
            if (From.Langue == To.ToString()) 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's seems like google translate 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);

            }
        }