|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using TMPro;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.SceneManagement;
|
|
@@ -12,14 +13,22 @@ namespace BepInEx.Internal
|
|
|
public class TranslationPlugin : ITranslationPlugin, IUnityPlugin
|
|
|
{
|
|
|
Dictionary<string, string> translations = new Dictionary<string, string>();
|
|
|
+ List<string> untranslated = new List<string>();
|
|
|
|
|
|
public TranslationPlugin()
|
|
|
{
|
|
|
- string[] japanese = File.ReadAllLines(Utility.CombinePaths(Utility.ExecutingDirectory, "translation", "japanese.txt"));
|
|
|
- string[] translation = File.ReadAllLines(Utility.CombinePaths(Utility.ExecutingDirectory, "translation", "translated.txt"));
|
|
|
+ string[] translation = File.ReadAllLines(Utility.CombinePaths(Utility.ExecutingDirectory, "translation", "translation.txt"));
|
|
|
|
|
|
- for (int i = 0; i < japanese.Length; i++)
|
|
|
- translations[japanese[i]] = translation[i];
|
|
|
+ for (int i = 0; i < translation.Length; i++)
|
|
|
+ {
|
|
|
+ string line = translation[i];
|
|
|
+ if (!line.Contains('='))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ string[] split = line.Split('=');
|
|
|
+
|
|
|
+ translations[split[0]] = split[1];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void OnStart()
|
|
@@ -48,6 +57,11 @@ namespace BepInEx.Internal
|
|
|
{
|
|
|
Translate();
|
|
|
}
|
|
|
+ else if (UnityEngine.Event.current.Equals(Event.KeyboardEvent("f10")))
|
|
|
+ {
|
|
|
+ Dump();
|
|
|
+ Console.WriteLine($"Text dumped to \"{Path.GetFullPath("dumped-tl.txt")}\"");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Translate()
|
|
@@ -58,9 +72,29 @@ namespace BepInEx.Internal
|
|
|
|
|
|
if (translations.ContainsKey(gameObject.text))
|
|
|
gameObject.text = translations[gameObject.text];
|
|
|
+ else
|
|
|
+ if (!untranslated.Contains(gameObject.text))
|
|
|
+ untranslated.Add(gameObject.text);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void Dump()
|
|
|
+ {
|
|
|
+ string output = "";
|
|
|
+
|
|
|
+ foreach (var kv in translations)
|
|
|
+ output += $"{kv.Key.Trim()}={kv.Value.Trim()}\r\n";
|
|
|
+
|
|
|
+ foreach (var text in untranslated)
|
|
|
+ if (!text.IsNullOrWhiteSpace()
|
|
|
+ && !text.Contains("Reset")
|
|
|
+ && !Regex.Replace(text, @"[\d-]", string.Empty).IsNullOrWhiteSpace()
|
|
|
+ && !translations.ContainsValue(text.Trim()))
|
|
|
+ output += $"{text.Trim()}=\r\n";
|
|
|
+
|
|
|
+ File.WriteAllText("dumped-tl.txt", output);
|
|
|
+ }
|
|
|
+
|
|
|
public bool TryTranslate(string input, out string output)
|
|
|
{
|
|
|
if (translations.ContainsKey(input))
|
|
@@ -69,6 +103,10 @@ namespace BepInEx.Internal
|
|
|
return true;
|
|
|
}
|
|
|
output = null;
|
|
|
+
|
|
|
+ if (!untranslated.Contains(input))
|
|
|
+ untranslated.Add(input);
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
}
|