瀏覽代碼

"unfixed" yandex translate

randoman 6 年之前
父節點
當前提交
519d1dd9cf

+ 0 - 1
CHANGELOG.md

@@ -8,7 +8,6 @@
  * FEATURE - Updated Watson translate to v3
  * FEATURE - Support for 'romaji' as output language. Only google supports this at the  moment
  * BUG FIX - Too many small fixes to mention
- * BUG FIX - Fixed bug in YandexTranslated that caused translations to be cut off
  * MISC - {GameExeName} variable can now be used in configuration of directories and files
  * MISC - Changed the way the 'Custom' endpoint works. See README for more info
  * MISC - Added new configuration 'GameLogTextPaths' to enable special handling of text components that text is being appended to continuously (requires export knowledge to setup)

+ 10 - 12
README.md

@@ -572,7 +572,7 @@ internal class YandexTranslateEndpoint : HttpEndpoint
    public override void Initialize( IInitializationContext context )
    {
       _key = context.GetOrCreateSetting( "Yandex", "YandexAPIKey", "" );
-      context.EnableSslFor( "translate.yandex.net" );
+      context.DisableCerfificateChecksFor( "translate.yandex.net" );
 
       // if the plugin cannot be enabled, simply throw so the user cannot select the plugin
       if( string.IsNullOrEmpty( _key ) ) throw new Exception( "The YandexTranslate endpoint requires an API key which has not been provided." );
@@ -587,7 +587,7 @@ internal class YandexTranslateEndpoint : HttpEndpoint
             HttpsServicePointTemplateUrl,
             context.SourceLanguage,
             context.DestinationLanguage,
-            WWW.EscapeURL( context.UntranslatedText ),
+            WwwHelper.EscapeUrl( context.UntranslatedText ),
             _key ) );
 
       request.Headers[ HttpRequestHeader.UserAgent ] = string.IsNullOrEmpty( AutoTranslatorSettings.UserAgent ) ? "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.183 Safari/537.36 Vivaldi/1.96.1147.55" : AutoTranslatorSettings.UserAgent;
@@ -604,21 +604,19 @@ internal class YandexTranslateEndpoint : HttpEndpoint
       var lineBuilder = new StringBuilder( data.Length );
 
       var code = obj.AsObject[ "code" ].ToString();
+      if( code != "200" ) context.Fail( "Received bad response code: " + code );
 
-      if( code == "200" )
-      {
-         var token = obj.AsObject[ "text" ].ToString();
-         token = token.Substring( 2, token.Length - 4 ).UnescapeJson();
+      var token = obj.AsObject[ "text" ].ToString();
+      token = JsonHelper.Unescape( token.Substring( 1, token.Length - 2 ) );
 
-         if( string.IsNullOrEmpty( token ) ) return; 
+      if( string.IsNullOrEmpty( token ) ) return;
 
-         if( !lineBuilder.EndsWithWhitespaceOrNewline() ) lineBuilder.Append( "\n" );
-         lineBuilder.Append( token );
+      if( !lineBuilder.EndsWithWhitespaceOrNewline() ) lineBuilder.Append( "\n" );
+      lineBuilder.Append( token );
 
-         var translated = lineBuilder.ToString();
+      var translated = lineBuilder.ToString();
 
-         context.Complete( translated );
-      }
+      context.Complete( translated );
    }
 }
 ```

+ 1 - 1
src/Translators/YandexTranslate/YandexTranslateEndpoint.cs

@@ -64,7 +64,7 @@ namespace YandexTranslate
          if( code != "200" ) context.Fail( "Received bad response code: " + code );
 
          var token = obj.AsObject[ "text" ].ToString();
-         token = JsonHelper.Unescape( token.Substring( 1, token.Length - 2 ) );
+         token = JsonHelper.Unescape( token.Substring( 2, token.Length - 4 ) );
 
          if( string.IsNullOrEmpty( token ) ) return;
 

+ 3 - 10
src/XUnity.AutoTranslator.Plugin.IPA/AutoTranslatorPlugin.cs

@@ -16,12 +16,11 @@ namespace XUnity.AutoTranslator.Plugin.IPA
    {
       private IniFile _file;
       private string _configPath;
-      private string _dataFolder;
 
       public AutoTranslatorPlugin()
       {
-         _dataFolder = "Plugins";
-         _configPath = Path.Combine( _dataFolder, "AutoTranslatorConfig.ini" );
+         DataPath = "Plugins";
+         _configPath = Path.Combine( DataPath, "AutoTranslatorConfig.ini" );
       }
 
       public IniFile Preferences
@@ -32,13 +31,7 @@ namespace XUnity.AutoTranslator.Plugin.IPA
          }
       }
 
-      public string DataPath
-      {
-         get
-         {
-            return _dataFolder;
-         }
-      }
+      public string DataPath { get; }
 
       public IniFile ReloadConfig()
       {