TranslationPlugin.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using TMPro;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. namespace BepInEx.Internal
  10. {
  11. public class TranslationPlugin : IUnityPlugin
  12. {
  13. Dictionary<string, string> translations = new Dictionary<string, string>();
  14. public TranslationPlugin()
  15. {
  16. string[] japanese = File.ReadAllLines(Utility.CombinePaths(Utility.ExecutingDirectory, "translation", "japanese.txt"));
  17. string[] translation = File.ReadAllLines(Utility.CombinePaths(Utility.ExecutingDirectory, "translation", "translated.txt"));
  18. for (int i = 0; i < japanese.Length; i++)
  19. translations[japanese[i]] = translation[i];
  20. }
  21. public void OnStart()
  22. {
  23. }
  24. public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
  25. {
  26. Translate();
  27. }
  28. public void OnFixedUpdate()
  29. {
  30. }
  31. public void OnLateUpdate()
  32. {
  33. }
  34. public void OnUpdate()
  35. {
  36. if (UnityEngine.Event.current.Equals(Event.KeyboardEvent("f9")))
  37. {
  38. Translate();
  39. }
  40. }
  41. void Translate()
  42. {
  43. foreach (TextMeshProUGUI gameObject in GameObject.FindObjectsOfType<TextMeshProUGUI>())
  44. {
  45. //gameObject.text = "Harsh is shit";
  46. if (translations.ContainsKey(gameObject.text))
  47. gameObject.text = translations[gameObject.text];
  48. }
  49. }
  50. }
  51. }