Эх сурвалжийг харах

finished improved whitespace handling

Scrublord1336 6 жил өмнө
parent
commit
303b0890f5

+ 1 - 1
README.md

@@ -60,7 +60,7 @@ EnableBatching=True              ;Indicates whether batching of translations sho
 TrimAllText=True                 ;Indicates whether spaces in front and behind translation candidates should be removed before translation
 UseStaticTranslations=True       ;Indicates whether or not to use translations from the included static translation cache
 OverrideFont=                    ;Overrides the fonts used for texts when updating text components. NOTE: Only works for UGUI
-WhitespaceHandlingStrategy=TrimPerNewline ;Indicates how whitespace/newline removal should be handled before attempting translation. Can be ["TrimPerNewline", "AllOccurrences"]
+WhitespaceRemovalStrategy=TrimPerNewline ;Indicates how whitespace/newline removal should be handled before attempting translation. Can be ["TrimPerNewline", "AllOccurrences"]
 
 [Http]
 UserAgent=                       ;Override the user agent used by APIs requiring a user agent

+ 5 - 5
src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs

@@ -71,7 +71,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
       public static bool UseStaticTranslations;
       public static string OverrideFont;
       public static string UserAgent;
-      public static WhitespaceHandlingStrategy WhitespaceHandlingStrategy;
+      public static WhitespaceHandlingStrategy WhitespaceRemovalStrategy;
 
       public static bool CopyToClipboard;
       public static int MaxClipboardCopyCharacters;
@@ -113,7 +113,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
          MaxCharactersPerTranslation = Config.Current.Preferences[ "Behaviour" ][ "MaxCharactersPerTranslation" ].GetOrDefault( 200 );
          IgnoreWhitespaceInDialogue = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInDialogue" ].GetOrDefault( Types.AdvEngine == null );
          IgnoreWhitespaceInNGUI = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInNGUI" ].GetOrDefault( true );
-         MinDialogueChars = Config.Current.Preferences[ "Behaviour" ][ "MinDialogueChars" ].GetOrDefault( 18 );
+         MinDialogueChars = Config.Current.Preferences[ "Behaviour" ][ "MinDialogueChars" ].GetOrDefault( 20 );
          ForceSplitTextAfterCharacters = Config.Current.Preferences[ "Behaviour" ][ "ForceSplitTextAfterCharacters" ].GetOrDefault( 0 );
          CopyToClipboard = Config.Current.Preferences[ "Behaviour" ][ "CopyToClipboard" ].GetOrDefault( false );
          MaxClipboardCopyCharacters = Config.Current.Preferences[ "Behaviour" ][ "MaxClipboardCopyCharacters" ].GetOrDefault( 450 );
@@ -126,13 +126,13 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
          // special handling because of P/Invoke / exe name handling
          try
          {
-            WhitespaceHandlingStrategy = Config.Current.Preferences[ "Behaviour" ][ "WhitespaceHandlingStrategy" ].GetOrDefault( GetDefaultWhitespaceHandlingStrategy() );
+            WhitespaceRemovalStrategy = Config.Current.Preferences[ "Behaviour" ][ "WhitespaceRemovalStrategy" ].GetOrDefault( GetDefaultWhitespaceHandlingStrategy() );
          }
          catch( Exception e )
          {
-            WhitespaceHandlingStrategy = WhitespaceHandlingStrategy.TrimPerNewline;
+            WhitespaceRemovalStrategy = WhitespaceHandlingStrategy.TrimPerNewline;
 
-            Logger.Current.Warn( e, "An error occurred while configuring 'WhitespaceHandlingStrategy'. Using default." );
+            Logger.Current.Warn( e, "An error occurred while configuring 'WhitespaceRemovalStrategy'. Using default." );
          }
 
          UserAgent = Config.Current.Preferences[ "Http" ][ "UserAgent" ].GetOrDefault( string.Empty );

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Extensions/ObjectExtensions.cs

@@ -60,7 +60,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
          return ui is UnityEngine.GUIContent;
       }
 
-      public static bool IgnoreAllWhitespace( this object ui )
+      public static bool IsNGUI( this object ui )
       {
          if( ui == null ) return false;
 

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Extensions/StringExtensions.cs

@@ -199,7 +199,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
       public static string RemoveWhitespaceAndNewlines( this string text )
       {
          var builder = new StringBuilder( text.Length );
-         if( Settings.WhitespaceHandlingStrategy == WhitespaceHandlingStrategy.AllOccurrences )
+         if( Settings.WhitespaceRemovalStrategy == WhitespaceHandlingStrategy.AllOccurrences )
          {
             for( int i = 0 ; i < text.Length ; i++ )
             {

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/TranslationKey.cs

@@ -14,7 +14,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
          OriginalText = key;
 
          if( !neverRemoveWhitespace
-            && ( ( Settings.IgnoreWhitespaceInDialogue && key.Length > Settings.MinDialogueChars ) || ( Settings.IgnoreWhitespaceInNGUI && ui.IgnoreAllWhitespace() ) ) )
+            && ( ( Settings.IgnoreWhitespaceInDialogue && key.Length > Settings.MinDialogueChars ) || ( Settings.IgnoreWhitespaceInNGUI && ui.IsNGUI() ) ) )
          {
             RelevantText = key.RemoveWhitespaceAndNewlines();
          }