Beispiel #1
0
        public bool TranslateText(Scene?scene, object source, TextTranslationEventArgs e, out string translate)
        {
            if (TextTranslationPool.Translate(scene, source, e, out var temp))
            {
                translate = temp;
                return(true);
            }

            translate = temp;
            return(false);
        }
Beispiel #2
0
        public void LoadTextTranslation()
        {
            var textPool = new TextTranslationPool();
            var count    = 0;

            var translationFiles = Directory.GetFiles(TextTranslationDir, "*.txt", SearchOption.AllDirectories);

            foreach (var file in translationFiles)
            {
                var lines           = File.ReadAllLines(file);
                var baseTranslation = new TextTranslation(textPool.NamePool);
                var translation     = baseTranslation.Clone();

                foreach (var line in lines)
                {
                    if (string.IsNullOrEmpty(line) || EmptyStringRegex.IsMatch(line))
                    {
                        if (translation.IsValid)
                        {
                            textPool.AddTranslation(translation);
                            count++;
                        }
                        translation = baseTranslation.Clone();
                        continue;
                    }

                    switch (line[0])
                    {
                    case '#':
                        break;

                    case '&':
                        ConfigTranslationSetting(baseTranslation, line.Substring(1));
                        ConfigTranslationSetting(translation, line.Substring(1));
                        break;

                    case '%':
                        baseTranslation = new TextTranslation(textPool.NamePool);
                        break;

                    case '*':
                        ConfigTranslationSetting(translation, line.Substring(1));
                        break;

                    case '-':
                        translation.Original = line.Substring(1).Unescape();
                        translation.Flag    |= TextTranslationFlag.TextPart;
                        break;

                    case '+':
                        translation.Regex = new Regex($"^{line.Substring(1)}$", RegexOptions.Compiled);
                        translation.Flag |= TextTranslationFlag.Regex;
                        translation.Flag |= TextTranslationFlag.TextPart;
                        break;

                    case '>':
                        translation.Original = line.Substring(1).Unescape();
                        break;

                    case '$':
                        translation.Regex = new Regex($"^{line.Substring(1)}$", RegexOptions.Compiled);
                        translation.Flag |= TextTranslationFlag.Regex;
                        break;

                    case '<':
                        translation.Translation = line.Substring(1).Unescape();
                        break;

                    default:
                        break;
                    }
                }

                if (translation.IsValid)
                {
                    textPool.AddTranslation(translation);
                    count++;
                }
            }

            TextTranslationPool = textPool;
            Logger.Log(LogLevel.Debug, $"[MaidTranslate] {count} text translation loaded.");
        }