Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var tlData = TranslationData.ImportFrom(TranslationFilePath);

            TranslateScripts(ScriptInputPath, ScriptOutputPath, tlData);
            Console.ReadLine();
        }
Exemplo n.º 2
0
 private static void TranslateScripts(string inPath, string outPath, TranslationData tlData)
 {
     foreach (string filePath in Directory.EnumerateFiles(inPath, "*.cst", SearchOption.TopDirectoryOnly))
     {
         string fileName   = Path.GetFileName(filePath);
         string targetPath = Path.Combine(outPath, fileName);
         TranslateScript(filePath, targetPath, tlData);
     }
 }
Exemplo n.º 3
0
        private static void TranslateScript(string inPath, string outPath, TranslationData tlData)
        {
            string baseName = Path.GetFileNameWithoutExtension(inPath);

            if (IgnoredScripts.Contains(baseName))
            {
                File.Copy(inPath, outPath, true);
                return;
            }

            var script = new CstScript();

            using (var fs = File.OpenRead(inPath)) script.ReadFrom(fs, baseName);

            var lastType = ScriptLineType.Command;

            for (int i = 0; i < script.Lines.Count; i++)
            {
                var line = script.Lines[i];
                if (line.Type == ScriptLineType.Message && lastType == ScriptLineType.Message)
                {
                    Debug.Assert(line.Content.StartsWith("\\n"));
                    //Log.Info($"Merging lines {baseName}:{i - 1} and {baseName}:{i}");
                    //Log.Info("    " + script.Lines[i - 1].Content);
                    //Log.Info("  + " + line.Content.Substring(2));
                    script.Lines[i - 1].Content += line.Content.Substring(2);
                    script.DeleteLine(i);
                    i--;
                }
                lastType = line.Type;
            }

            var lines = tlData.LinesFor(baseName);

            using var enumerator = lines.GetEnumerator();

            foreach (var scriptLine in script.Lines)
            {
                if (scriptLine.Content.Length == 0)
                {
                    continue;
                }

                switch (scriptLine.Type)
                {
                case ScriptLineType.Message:

                    if (!enumerator.MoveNext())
                    {
                        throw new Exception($"Not enough translation lines for {scriptLine.Location}\n    {scriptLine.Content}");
                    }

                    var tlLine = enumerator.Current;

                    if (scriptLine.Content != tlLine !.JapaneseText)
                    {
                        throw new Exception($"Mismatching japanese text in {scriptLine.Location}\n    {scriptLine.Content}\n    {tlLine.JapaneseText}");
                    }

                    scriptLine.Content = ProcessText(scriptLine, tlLine.EnglishText);

                    break;

                case ScriptLineType.Name:
                    if (!tlData.Names.ContainsKey(scriptLine.Content))
                    {
                        throw new Exception($"Untranslated name in {baseName}: {scriptLine.Content}");
                    }

                    scriptLine.Content = tlData.Names[scriptLine.Content];

                    break;
                }
            }

            using (var fs = File.OpenWrite(outPath)) script.WriteTo(fs, CompressScripts);
        }