Sfoglia il codice sorgente

Version 3.3.1

 * MISC - Options to cache results of regex lookups and whitespace differences
 * BUG FIX - Fixed 'WhitespaceRemovalStrategy.TrimPerNewline' which was broken to remove all non-repeating whitespace, rather than only the non-repeating whitespace surrounding newlines
 * BUG FIX - Fully clear translations before reloading (ALT+R)
randoman 6 anni fa
parent
commit
6dd47ba234

+ 1 - 0
CHANGELOG.md

@@ -1,5 +1,6 @@
 ### 3.3.1
  * MISC - Options to cache results of regex lookups and whitespace differences
+ * BUG FIX - Fixed 'WhitespaceRemovalStrategy.TrimPerNewline' which was broken to remove all non-repeating whitespace, rather than only the non-repeating whitespace surrounding newlines
  * BUG FIX - Fully clear translations before reloading (ALT+R)
 
 ### 3.3.0

+ 1 - 1
src/XUnity.AutoTranslator.Patcher/Patcher.cs

@@ -29,7 +29,7 @@ namespace XUnity.AutoTranslator.Patcher
       {
          get
          {
-            return "3.3.0";
+            return "3.3.1";
          }
       }
 

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net35</TargetFramework>
-    <Version>3.3.0</Version>
+    <Version>3.3.1</Version>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.3.0</Version>
+      <Version>3.3.1</Version>
    </PropertyGroup>
 
    <ItemGroup>

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

@@ -148,7 +148,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
             TranslationPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex );
             EnableExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "EnableExperimentalHooks", false );
             ForceExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "ForceExperimentalHooks", false );
-            CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheRegexLookups", true );
+            CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheRegexLookups", false );
             CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheWhitespaceDifferences", true );
 
             TextureDirectory = PluginEnvironment.Current.Preferences.GetOrDefault( "Texture", "TextureDirectory", @"Translation\Texture" );

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs

@@ -23,6 +23,6 @@ namespace XUnity.AutoTranslator.Plugin.Core.Constants
       /// <summary>
       /// Gets the version of the plugin.
       /// </summary>
-      public const string Version = "3.3.0";
+      public const string Version = "3.3.1";
    }
 }

+ 5 - 2
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/TranslationEndpointManager.cs

@@ -87,8 +87,11 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints
 
       private void AddTranslation( string key, string value )
       {
-         _translations[ key ] = value;
-         _reverseTranslations[ value ] = key;
+         if( key != null && value != null )
+         {
+            _translations[ key ] = value;
+            _reverseTranslations[ value ] = key;
+         }
       }
 
       private void QueueNewTranslationForDisk( string key, string value )

+ 6 - 3
src/XUnity.AutoTranslator.Plugin.Core/TextTranslationCache.cs

@@ -205,8 +205,11 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       private void AddTranslation( string key, string value )
       {
-         _translations[ key ] = value;
-         _reverseTranslations[ value ] = key;
+         if( key != null && value != null )
+         {
+            _translations[ key ] = value;
+            _reverseTranslations[ value ] = key;
+         }
       }
 
       private void QueueNewTranslationForDisk( string key, string value )
@@ -226,7 +229,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
             // also add a trimmed version of the translation
             var ukey = new UntranslatedText( key, false, false );
             var uvalue = new UntranslatedText( value, false, false );
-            if( ukey.TrimmedTranslatableText != key )
+            if( ukey.TrimmedTranslatableText != key && !HasTranslated( ukey.TrimmedTranslatableText ) )
             {
                AddTranslation( ukey.TrimmedTranslatableText, uvalue.TrimmedTranslatableText );
             }

+ 69 - 27
src/XUnity.AutoTranslator.Plugin.Core/UntranslatedText.cs

@@ -71,48 +71,90 @@ namespace XUnity.AutoTranslator.Plugin.Core
                builder.Append( LeadingWhitespace );
             }
 
-            char currentWhitespaceChar = default( char );
-            bool addedCurrentWhitespace = false;
+            int whitespaceStart = -1;
             for( i = firstNonWhitespace; i <= lastNonWhitespace; i++ )
             {
                var c = text[ i ];
-               if( !char.IsWhiteSpace( c ) )
-               {
-                  builder.Append( c );
 
-                  currentWhitespaceChar = default( char );
-               }
-               else
+               if( c == '\n' )
                {
-                  // keep repeating whitespace
-                  if( c == currentWhitespaceChar )
+                  // find first non-whitespace
+                  int u = i - 1;
+                  while( u > firstNonWhitespace && char.IsWhiteSpace( text[ u ] ) ) u--;
+
+                  int o = i + 1;
+                  while( o < lastNonWhitespace && char.IsWhiteSpace( text[ o ] ) ) o++;
+
+                  u++;
+                  o--;
+                  int l = o - u;
+                  if( l > 0 )
                   {
-                     if( !addedCurrentWhitespace )
+                     char currentWhitespaceChar = text[ u ];
+                     bool addedCurrentWhitespace = false;
+                     u++;
+
+                     for( int k = u; k <= o; k++ )
                      {
-                        builder.Append( currentWhitespaceChar );
-                        addedCurrentWhitespace = true;
+                        var ch = text[ k ];
+
+                        // keep repeating whitespace
+                        if( ch == currentWhitespaceChar )
+                        {
+                           if( !addedCurrentWhitespace )
+                           {
+                              builder.Append( currentWhitespaceChar );
+                              addedCurrentWhitespace = true;
+                           }
+
+                           builder.Append( ch );
+                        }
+                        else
+                        {
+                           addedCurrentWhitespace = false;
+                           currentWhitespaceChar = ch;
+                        }
+
+                        if( Settings.UsesWhitespaceBetweenWords && ( ch == '\n' || ch == '\r' ) )
+                        {
+                           if( builder.Length > 0 && builder[ builder.Length - 1 ] != ' ' )
+                           {
+                              builder.Append( ' ' );
+                           }
+
+                           var nextK = k + 1;
+                           if( nextK < lastNonWhitespace && text[ nextK ] == '\n' )
+                           {
+                              k++;
+                           }
+                        }
                      }
-
-                     builder.Append( c );
-                  }
-                  else
-                  {
-                     addedCurrentWhitespace = false;
-                     currentWhitespaceChar = c;
                   }
-               }
 
-               if( Settings.UsesWhitespaceBetweenWords && ( c == '\n' || c == '\r' ) )
+                  i = o;
+                  whitespaceStart = -1;
+               }
+               else if( !char.IsWhiteSpace( c ) )
                {
-                  if( builder.Length > 0 && builder[ builder.Length - 1 ] != ' ' )
+                  if( whitespaceStart != -1 )
                   {
-                     builder.Append( ' ' );
+                     // add from whitespaceStart to i - 1 of characters
+                     for( int b = whitespaceStart; b < i; b++ )
+                     {
+                        builder.Append( text[ b ] );
+                     }
+
+                     whitespaceStart = -1;
                   }
 
-                  var nextI = i + 1;
-                  if( nextI < lastNonWhitespace && text[ nextI ] == '\n' )
+                  builder.Append( c );
+               }
+               else
+               {
+                  // is whitespace char different from \n
+                  if( whitespaceStart == -1 )
                   {
-                     i++;
+                     whitespaceStart = i;
                   }
                }
             }

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.3.0</Version>
+      <Version>3.3.1</Version>
    </PropertyGroup>
 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.3.0</Version>
+      <Version>3.3.1</Version>
    </PropertyGroup>
 
    <ItemGroup>

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.3.0</Version>
+      <Version>3.3.1</Version>
    </PropertyGroup>
 
    <ItemGroup>

+ 1 - 1
src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj

@@ -4,7 +4,7 @@
       <OutputType>Exe</OutputType>
       <TargetFramework>net40</TargetFramework>
       <AssemblyName>SetupReiPatcherAndAutoTranslator</AssemblyName>
-      <Version>3.3.0</Version>
+      <Version>3.3.1</Version>
       <ApplicationIcon>icon.ico</ApplicationIcon>
       <Win32Resource />
    </PropertyGroup>

+ 11 - 3
test/XUnity.AutoTranslator.Plugin.Core.Tests/UntranslatedTextTests.cs

@@ -25,8 +25,9 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       }
 
       [Theory( DisplayName = "Can_Trim_Internal_Whitespace" )]
-      [InlineData( "Hel lo", "Hello" )]
+      [InlineData( "Hel lo", "Hel lo" )]
       [InlineData( "Hel\r\n lo", "Hello" )]
+      [InlineData( "Hel\n\nlo", "Hel\n\nlo" )]
       public void Can_Trim_Internal_Whitespace( string input, string expectedTrimmedText )
       {
          var untranslatedText = new UntranslatedText( input, false, true );
@@ -35,8 +36,15 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       }
 
       [Theory( DisplayName = "Can_Trim_Internal_And_Surrounding_Whitespace" )]
-      [InlineData( "\r\n \r\nHe llo", "Hello", "\r\n \r\n", null )]
+      [InlineData( "\r\n \r\nHe llo", "He llo", "\r\n \r\n", null )]
+      [InlineData( "\r\n \r\nHe   llo", "He   llo", "\r\n \r\n", null )]
       [InlineData( "\r\n \r\nHel\r\nlo\n", "Hello", "\r\n \r\n", "\n" )]
+      [InlineData( "\r\n \r\nHel\n\nlo\n", "Hel\n\nlo", "\r\n \r\n", "\n" )]
+      [InlineData( "\r\n \r\nHel\n\n lo\n", "Hel\n\nlo", "\r\n \r\n", "\n" )]
+      [InlineData( "\r\n \r\nHel\n\n  lo\n", "Hel\n\n  lo", "\r\n \r\n", "\n" )]
+      [InlineData( "\r\n \r\nHel  \n\n  lo\n", "Hel  \n\n  lo", "\r\n \r\n", "\n" )]
+      [InlineData( "\r\n \r\nHel  \n  lo\n", "Hel    lo", "\r\n \r\n", "\n" )]
+      [InlineData( "\r\n \r\nHel \n lo\n", "Hello", "\r\n \r\n", "\n" )]
       [InlineData( "\r\r\r\r\n \n Hell\no  \r\n", "Hello", "\r\r\r\r\n \n ", "  \r\n" )]
       public void Can_Trim_Internal_And_Surrounding_Whitespace( string input, string expectedTrimmedText, string expectedLeadingWhitespace, string expectedTrailingWhitespace )
       {
@@ -48,7 +56,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       }
 
       [Theory( DisplayName = "Can_Trim_Internal_And_Surrounding_Whitespace_And_Template" )]
-      [InlineData( "\r\n \r\nFPS: 60.53", "FPS:{{A}}", "\r\n \r\n", null )]
+      [InlineData( "\r\n \r\nFPS: 60.53", "FPS: {{A}}", "\r\n \r\n", null )]
       public void Can_Trim_Internal_And_Surrounding_Whitespace_And_Template( string input, string expectedTrimmedText, string expectedLeadingWhitespace, string expectedTrailingWhitespace )
       {
          var untranslatedText = new UntranslatedText( input, true, true );