Exemple #1
0
        public Translation(int id, string source, Options _options)
        {
            options = _options;

            this.id = id;
            this.source = source;
            this.sourceFixed = makeReplacements(source);
            if (options.excludeSpeakers)
                this.sourceNew = excludeSpeaker(sourceFixed);
            else
                this.sourceNew = sourceFixed;
            sourceNew = makeFinalAdjustments(sourceNew);
            List<string> usedTranslators = new List<string>();
            foreach (TranslatorRecord rec in options.translators)
            {
                if (rec.inUse)
                {
                    string trans = Translators[rec.id];
                    if (trans == "Atlas" && !Atlas.Ready())
                        continue;
                    if (trans == "Translit (MeCab)" && !Mecab.Ready())
                        continue;
                    usedTranslators.Add(Translators[rec.id]);
                }
            }
            List<object> args = new List<object>();
            args.Add(id);
            bool parseWords = options.displayOriginal && (options.wordParseMethod == Options.PARSE_BUILTIN && Edict.instance.Ready && Inflect.instance.Ready || options.wordParseMethod == Options.PARSE_WWWJDIC);
            bool reserveLineHeight = parseWords && options.displayReadings;
            args.Add(reserveLineHeight);
            args.Add(options.furiganaRomaji);
            if (options.displayOriginal)
            {
                args.Add(source);
                if (options.displayFixed && source != sourceFixed)
                    args.Add(sourceFixed);
                else
                    args.Add("");
            }
            else
            {
                args.Add("");
                args.Add("");
            }
            args.Add(parseWords && options.wordParseMethod == Options.PARSE_BUILTIN && Edict.Created());
            foreach (string name in usedTranslators)
            {
                args.Add(name);
            }
            Global.RunScript2("AddTranslationBlock", args.ToArray());
            if (parseWords)
                tasksToComplete = usedTranslators.Count + 1;
            else
                tasksToComplete = usedTranslators.Count;
            current.Add(this);
            foreach (string s in usedTranslators)
            {
                if (s == "Translit (MeCab)")
                    new TranslationTask(this, s, this.GetType().GetMethod("TranslateMecabTranslit"), false);
                else if (s == "Translit (Google)")
                    new TranslationTask(this, s, this.GetType().GetMethod("TranslateTranslit"), false);
                else if (s == "Translit (int.)")
                    new TranslationTask(this, s, this.GetType().GetMethod("TranslateMyTranslit"), false);
                else if (s.StartsWith("Hivemind"))
                    new TranslationTask(this, s, this.GetType().GetMethod("TranslateHivemind"), false);
                else
                    new TranslationTask(this, s, this.GetType().GetMethod("Translate" + s), false);
            }
            if (parseWords)
            {
                if (options.wordParseMethod == Options.PARSE_BUILTIN)
                {
                    if (Edict.Created())
                    {
                        BuiltinParserLookup();
                        CompleteTask();
                    }
                    else
                    {
                        new TranslationTask(this, "Builtin", this.GetType().GetMethod("BuiltinParserLookup"), true);
                    }
                }
                else
                {
                    new TranslationTask(this, "JDic", this.GetType().GetMethod("JDicLookup"), true);
                }
            }
        }
Exemple #2
0
 private static void AddTranslationBlock(string source, Options options)
 {
     if (current.Count < 10)
         new Translation(NextTransId(), source, options);
 }
Exemple #3
0
 public static void Translate(string raw_source, Options options)
 {
     Translate(raw_source, options, false);
 }
Exemple #4
0
 public static void Translate(string raw_source, Options options, bool auto)
 {
     if (options == null)
         options = Global.options;
     if (raw_source == "")
         return;
     if (raw_source.Length > options.maxSourceLength * 2)
         raw_source = raw_source.Substring(0, options.maxSourceLength * 2);
     string source = GetSource(raw_source, options);
     if (source != null && source != "" && (!auto || source != lastGoodBuffer))
     {
         if (source.Length > options.maxSourceLength)
         {
             if (auto && options.checkRepeatingPhrasesAdv)
                 return;
             else
                 source = source.Substring(0, options.maxSourceLength);
         }
         lastGoodBuffer = source;
         AddTranslationBlock(source, options);
     }
 }
Exemple #5
0
 private static string GetSource(string raw_text, Options options)
 {
     string result = raw_text;
     if (result.ToCharArray().All(ch => !char.IsLetter(ch)))
         return null;
     if (options.checkRepeatingPhrasesAdv)
     {
         result = CheckRepeatingPhrasesAdv(result, options);
     }
     if (options.checkRepeatingPhrases)
     {
         List<string> rep;
         int n;
         rep = Djon.GetRepeatingPhrases(result, 10, out n);
         if (n > 1)
         {
             result = string.Join("", rep.ToArray());
         }
     }
     if (options.checkDouble)
         result = CheckDouble(result);
     result = result.Trim();
     return result;
 }
Exemple #6
0
 private static string CheckRepeatingPhrasesAdv(string src, Options options)
 {
     // f**k you knuth - we use dumb force
     src = src.Trim();
     if (src.Length < 10)
         return src;
     string key = src.Substring(0, 3);
     int fst = src.IndexOf(key, 3);
     if (fst == -1)
         return src;
     int snd = src.IndexOf(key, fst + 3);
     if (snd == -1)
         return src;
     //trying first and then second
     key = src.Substring(0, fst);
     if (_tryRPA(src, key))
         return key;
     key = src.Substring(fst, snd - fst);
     if (_tryRPA(src, key))
         return key;
     return src;
 }
Exemple #7
0
 private void FormOptions_Shown(object sender, EventArgs e)
 {
     options = Global.options.Clone();
     UpdateControls();
     comboBoxJDic.Select(0, 0);
     comboBoxHivemind.Select(0, 0);
     WindowPosition.Normalize(this);
     userDictInit = false;
     userDictChanged = false;
 }
Exemple #8
0
 private void addButton_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             Options tmp = new Options();
             tmp.LoadReplacements(openFileDialog1.FileName);
             options.replacements.AddRange(tmp.replacements);
             bindingSource1.ResetBindings(false);
         }
         catch (Exception)
         {
             MessageBox.Show("Failed to add replacements!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #9
0
 private void button6_Click(object sender, EventArgs e)
 {
     options = new Options();
     options.SetDefault();
     this.UpdateControls();
 }