TranslationKey.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using XUnity.AutoTranslator.Plugin.Core.Configuration;
  6. using XUnity.AutoTranslator.Plugin.Core.Extensions;
  7. namespace XUnity.AutoTranslator.Plugin.Core
  8. {
  9. internal struct TranslationKey
  10. {
  11. public TranslationKey( object ui, string key, bool templatizeByNumbers, bool neverRemoveWhitespace = false )
  12. {
  13. OriginalText = key;
  14. if( !neverRemoveWhitespace
  15. && ( ( Settings.IgnoreWhitespaceInDialogue && key.Length > Settings.MinDialogueChars ) || ( Settings.IgnoreWhitespaceInNGUI && ui.IsNGUI() ) ) )
  16. {
  17. RelevantText = key.RemoveWhitespaceAndNewlines();
  18. }
  19. else
  20. {
  21. RelevantText = key;
  22. }
  23. if( templatizeByNumbers )
  24. {
  25. TemplatedText = RelevantText.TemplatizeByNumbers();
  26. }
  27. else
  28. {
  29. TemplatedText = null;
  30. }
  31. }
  32. public TemplatedString TemplatedText { get; }
  33. public string RelevantText { get; }
  34. public string OriginalText { get; set; }
  35. public string GetDictionaryLookupKey()
  36. {
  37. if( TemplatedText != null )
  38. {
  39. return TemplatedText.Template;
  40. }
  41. return RelevantText;
  42. }
  43. public string Untemplate( string text )
  44. {
  45. if( TemplatedText != null )
  46. {
  47. return TemplatedText.Untemplate( text );
  48. }
  49. return text;
  50. }
  51. public string RepairTemplate( string text )
  52. {
  53. if( TemplatedText != null )
  54. {
  55. return TemplatedText.RepairTemplate( text );
  56. }
  57. return text;
  58. }
  59. }
  60. }