Ejemplo n.º 1
0
        public void Start()
        {
            ConsoleWriteLine("Checking \'" + SourceFile + "\'...");
            int line = 0;

            using (StreamReader streamReader = new StreamReader(SourceFile))
            {
                while (!streamReader.EndOfStream)
                {
                    line++;
                    string lineText = streamReader.ReadLine();
                    if (lineText == null)
                    {
                        continue;
                    }
                    lineText = lineText.Replace(SourceLanguage.ToString(), TargetLanguage.ToString());
                    _lines.Add(lineText);
                    //if (lineText.Contains("\"") && lineText.Contains(".Add"))
                    //    ConsoleWriteLine(line + ": " + GetSourceText(lineText));
                    //else
                    //    ConsoleWriteLine(line + ": " + lineText);
                }
            }
            ProcessLines();
        }
        public static string GetLanguageName(SourceLanguage language)
        {
            switch (language)
            {
            case SourceLanguage.CSharp: return("C#");

            default: return(language.ToString());
            }
        }
Ejemplo n.º 3
0
        public static string GetContractContent(string contractFileName)
        {
            SourceLanguage language = SourceLanguage.Other;

            //Check the filename for the language
            if (contractFileName.ToLower().EndsWith(".cs"))
            {
                language = SourceLanguage.CSharp;
            }
            else if (contractFileName.ToLower().EndsWith(".py"))
            {
                language = SourceLanguage.Python;
            }

            string templateFile = Path.Combine(HttpContext.Current.Server.MapPath("~"), "Contracts", language.ToString(), contractFileName);

            if (!File.Exists(templateFile))
            {
                throw new FileNotFoundException(templateFile);
            }

            return(File.ReadAllText(templateFile));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs the actual search by looping through the
        /// delimited segment pairs contained in the text file.
        /// Depening on the search mode, a segment lookup (with exact machting) or a source / target
        /// concordance search is done.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="segment"></param>
        /// <returns></returns>
        #region "SearchSegment"
        public SearchResults SearchSegment(SearchSettings settings, Segment segment)
        {
            //FUTURE: consider making GT and MT lookup classes static utility classes

            Segment translation = new Segment(_languageDirection.TargetCulture);//this will be the target segment

            #region "SearchResultsObject"
            SearchResults results = new SearchResults();
            results.SourceSegment = segment.Duplicate();

            #endregion

            #region "Confirmation Level"
            if (!_options.ResendDrafts && inputTu.ConfirmationLevel != ConfirmationLevel.Unspecified) //i.e. if it's status is other than untranslated
            {                                                                                         //don't do the lookup, b/c we don't need to pay google to translate text already translated if we edit a segment
                translation.Add(PluginResources.TranslationLookupDraftNotResentMessage);
                //later get these strings from resource file
                results.Add(CreateSearchResult(segment, translation, segment.ToString()));
                return(results);
            }
            #endregion


            // Look up the currently selected segment in the collection (normal segment lookup).
            #region "SegmentLookup"
            string sourceLang     = SourceLanguage.ToString();
            string targetLang     = TargetLanguage.ToString();
            string translatedText = "";
            //a new seg avoids modifying the current segment object
            Segment newseg = segment.Duplicate();

            //do preedit if checked
            bool sendTextOnly = _options.SendPlainTextOnly || !newseg.HasTags;
            if (!sendTextOnly)
            {
                //do preedit with tagged segment
                if (_options.UsePreEdit)
                {
                    if (preLookupSegmentEditor == null)
                    {
                        preLookupSegmentEditor = new SegmentEditor(_options.PreLookupFilename);
                    }
                    newseg = getEditedSegment(preLookupSegmentEditor, newseg);
                }
                //return our tagged target segment
                MtTranslationProviderTagPlacer tagplacer = new MtTranslationProviderTagPlacer(newseg);
                ////tagplacer is constructed and gives us back a properly marked up source string for google
                if (_options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    translatedText = LookupGT(tagplacer.PreparedSourceText, _options, "html");
                }
                else if (_options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    translatedText = LookupMST(tagplacer.PreparedSourceText, _options, "text/html");
                }
                //now we send the output back to tagplacer for our properly tagged segment
                translation = tagplacer.GetTaggedSegment(translatedText).Duplicate();

                //now do post-edit if that option is checked
                if (_options.UsePostEdit)
                {
                    if (postLookupSegmentEditor == null)
                    {
                        postLookupSegmentEditor = new SegmentEditor(_options.PostLookupFilename);
                    }
                    translation = getEditedSegment(postLookupSegmentEditor, translation);
                }
            }
            else //only send plain text
            {
                string sourcetext = newseg.ToPlain();
                //do preedit with string
                if (_options.UsePreEdit)
                {
                    if (preLookupSegmentEditor == null)
                    {
                        preLookupSegmentEditor = new SegmentEditor(_options.PreLookupFilename);
                    }
                    sourcetext = getEditedString(preLookupSegmentEditor, sourcetext);
                    //change our source segment so it gets sent back with modified text to show in translation results window that it was changed before sending
                    newseg.Clear();
                    newseg.Add(sourcetext);
                }

                //now do lookup
                if (_options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    translatedText = LookupGT(sourcetext, _options, "html"); //plain??
                }
                else if (_options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    translatedText = LookupMST(sourcetext, _options, "text/plain");
                }

                //now do post-edit if that option is checked
                if (_options.UsePostEdit)
                {
                    if (postLookupSegmentEditor == null)
                    {
                        postLookupSegmentEditor = new SegmentEditor(_options.PostLookupFilename);
                    }
                    translatedText = getEditedString(postLookupSegmentEditor, translatedText);
                }
                translation.Add(translatedText);
            }

            results.Add(CreateSearchResult(newseg, translation, newseg.ToPlain()));

            #endregion

            #region "Close"
            return(results);

            #endregion
        }
Ejemplo n.º 5
0
        public static Dictionary <string, string> GetContractList(SourceLanguage language)
        {
            Dictionary <string, string> contracts = new Dictionary <string, string>();
            string templatePath = Path.Combine(HttpContext.Current.Server.MapPath("~"), "Contracts", language.ToString());

            if (!Directory.Exists(templatePath))
            {
                throw new DirectoryNotFoundException(templatePath);
            }

            var files = Directory.EnumerateFiles(templatePath);

            foreach (var file in files)
            {
                contracts.Add(file, Path.GetFileNameWithoutExtension(file).Humanize());
            }

            return(contracts);
        }