示例#1
0
 static void Main()
 {
     PDDText.Init();
     PDDCorpus.Init();
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainForm());
 }
示例#2
0
        private static string TranslateSegment(string input, string extension)
        {
            if (!cyrillicRx.Match(input).Success)
            {
                return(input);
            }

            string result;

            if (PDDCorpus.GetFromCorpus(input, out result))
            {
                ProgressForm.AddCorpus(input.Length);
                return(result);
            }

            string lang = PDDLanguage.Current.GoogleCode;

            lock (translations)
            {
                if (!translations.ContainsKey(input))
                {
                    translations[input] = new ConcurrentDictionary <string, TranslateItem>();
                }
                if (!translations[input].ContainsKey(lang))
                {
                    translations[input][lang] = new TranslateItem();
                }
            }

            lock (translations[input][lang].Locker)
            {
                if (translations[input][lang].Done)
                {
                    return(translations[input][lang].Result);
                }

                if (extension == ".script")
                {
                    result = input.Replace("%%", "%");
                    result = MachineTranslate(result);
                    result = result.Replace("%", "%%");
                }
                else
                {
                    result = MachineTranslate(input);
                }

                translations[input][lang].Finish(result);
                return(result);
            }
        }
示例#3
0
        private static string TranslateString(string input, string extension)
        {
            if (!cyrillicRx.Match(input).Success)
            {
                return(input);
            }

            string result;

            if (PDDCorpus.GetFromCorpus(input, out result))
            {
                ProgressForm.AddCorpus(input.Length);
                return(result);
            }

            List <Match> matches = new List <Match>();

            foreach (Regex pattern in splitPoints)
            {
                foreach (Match match in pattern.Matches(input))
                {
                    matches.Add(match);
                }
            }
            matches.Sort((m1, m2) => m1.Index.CompareTo(m2.Index));
            int           nextIndex = 0;
            StringBuilder resultSb  = new StringBuilder();

            for (int i = 0; i < matches.Count; i++)
            {
                Match match = matches[i];
                if (match.Index > 0)
                {
                    resultSb.Append(TranslateSegment(input.Substring(nextIndex, match.Index - nextIndex), extension));
                }
                resultSb.Append(match.Value);
                nextIndex = match.Index + match.Length;
            }
            if (nextIndex < input.Length)
            {
                resultSb.Append(TranslateSegment(input.Substring(nextIndex, input.Length - nextIndex), extension));
            }
            return(resultSb.ToString());
        }