Explorar el Código

removing duplicate interface implementations

randoman hace 6 años
padre
commit
cd7293bb4f

+ 11 - 6
README.md

@@ -515,11 +515,12 @@ I recommend using this class, or in case that cannot be used, falling back to th
 
 ### How-To
 Follow these steps:
- * Start a new project in Visual Studio 2017 or later. I recommend using the same name for your assembly/project as the "Id" you are going to use in your interface implementation.
- * Add a reference to the XUnity.AutoTranslator.Plugin.Core.dll
- * You do not need to directly reference the UnityEngine.dll assembly. This is good, because you do not need to worry about which version of Unity is used then.
-   * If you do need a reference to this assembly consider using an old version of it (if `UnityEngine.CoreModule.dll` exists in the Managed folder, it is not an old version!)
- * Create a new class that either:
+ 1. Download XUnity.AutoTranslator-Developer-{VERSION}.zip from [releases](../../releases)
+ 2. Start a new project in Visual Studio 2017 or later. I recommend using the same name for your assembly/project as the "Id" you are going to use in your interface implementation. This makes it easier for users to know how to configure your translator
+ 3. Add a reference to the XUnity.AutoTranslator.Plugin.Core.dll that you downloaded in step 1
+ 4. You do not need to directly reference the UnityEngine.dll assembly. This is good, because you do not need to worry about which version of Unity is used.
+   * If you do need a reference to this assembly (because you need functionality from it) consider using an old version of it (if `UnityEngine.CoreModule.dll` exists in the Managed folder, it is not an old version!)
+ 5. Create a new class that either:
    * Implements the `ITranslateEndpoint` interface
    * Inherits from the `HttpEndpoint` class
    * Inherits from the `WwwEndpoint` class
@@ -607,7 +608,7 @@ internal class YandexTranslateEndpoint : HttpEndpoint
       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;
 
@@ -630,6 +631,10 @@ As you can see, the `XUnityWebClient` class is not even used. We simply specify
 
 After implementing the class, simply build the project and place the generated DLL file in the "Translators" directory of the plugin folder. That's it.
 
+**NOTE**: If you implement a class based on the `HttpEndpoint` and you get an error where the web request is never completed, then it is likely due to the web server requiring Tls1.2. Unity-mono has issues with this spec and it will cause the request to lock up forever. The only solutions to this for now are:
+ * Disable SSL, if you can. There are many sitauations where it is simply not possible to do this because the web server will simply redirect back to the HTTPS endoint.
+ * Use the `WwwEndpoint` instead.
+
 As mentioned earlier, you  can also use the abstract class `WwwEndpoint` to implement roughly the same thing. However, I do not recommend doing so, unless it is an authenticated service.
 
 Another way to implement a translator is to implement the `ExtProtocolEndpoint` class. This can be used to delegate the actual translation logic to an external process. Currently there is no documentation on this, but you can take a look at the LEC implementation, which uses it.

+ 1 - 28
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/Http/IHttpTranslationContext.cs

@@ -5,34 +5,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Http
    /// <summary>
    /// Interface used in the context of the HttpEndpoint.
    /// </summary>
-   public interface IHttpTranslationContext
+   public interface IHttpTranslationContext : ITranslationContextBase
    {
-      /// <summary>
-      /// Gets the untranslated text.
-      /// </summary>
-      string UntranslatedText { get; }
-
-      /// <summary>
-      /// Gets the source language.
-      /// </summary>
-      string SourceLanguage { get; }
-
-      /// <summary>
-      /// Gets the destination language.
-      /// </summary>
-      string DestinationLanguage { get; }
-
-      /// <summary>
-      /// Fails the translation. Immediately throws an exception.
-      /// </summary>
-      /// <param name="reason"></param>
-      /// <param name="exception"></param>
-      void Fail( string reason, Exception exception );
-
-      /// <summary>
-      /// Fails the translation. Immediately throws an exception.
-      /// </summary>
-      /// <param name="reason"></param>
-      void Fail( string reason );
    }
 }

+ 13 - 7
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/ITranslationContext.cs

@@ -5,7 +5,19 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints
    /// <summary>
    /// Interface used in the context of translating a text.
    /// </summary>
-   public interface ITranslationContext
+   public interface ITranslationContext : ITranslationContextBase
+   {
+      /// <summary>
+      /// Completes the translation by providing the translated text.
+      /// </summary>
+      /// <param name="translatedText"></param>
+      void Complete( string translatedText );
+   }
+
+   /// <summary>
+   /// Interface used in the context of translating a text.
+   /// </summary>
+   public interface ITranslationContextBase
    {
       /// <summary>
       /// Gets the untranslated text.
@@ -22,12 +34,6 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints
       /// </summary>
       string DestinationLanguage { get; }
 
-      /// <summary>
-      /// Completes the translation by providing the translated text.
-      /// </summary>
-      /// <param name="translatedText"></param>
-      void Complete( string translatedText );
-
       /// <summary>
       /// Fails the translation. Immediately throws an exception.
       /// </summary>

+ 1 - 28
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/Www/IWwwTranslationContext.cs

@@ -5,34 +5,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Www
    /// <summary>
    /// Interface used in the context of the WwwEndpoint.
    /// </summary>
-   public interface IWwwTranslationContext
+   public interface IWwwTranslationContext : ITranslationContextBase
    {
-      /// <summary>
-      /// Gets the untranslated text.
-      /// </summary>
-      string UntranslatedText { get; }
-
-      /// <summary>
-      /// Gets the source language.
-      /// </summary>
-      string SourceLanguage { get; }
-
-      /// <summary>
-      /// Gets the destination language.
-      /// </summary>
-      string DestinationLanguage { get; }
-
-      /// <summary>
-      /// Fails the translation. Immediately throws an exception.
-      /// </summary>
-      /// <param name="reason"></param>
-      /// <param name="exception"></param>
-      void Fail( string reason, Exception exception );
-
-      /// <summary>
-      /// Fails the translation. Immediately throws an exception.
-      /// </summary>
-      /// <param name="reason"></param>
-      void Fail( string reason );
    }
 }

+ 2 - 2
src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextComponentExtensions.cs

@@ -61,9 +61,9 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
 
       public static bool IsSpammingComponent( this object ui )
       {
-         if( ui == null ) return false;
+         if( ui == null ) return true;
 
-         return ui is UnityEngine.GUIContent;
+         return ui is GUIContent;
       }
 
       public static bool IsWhitelistedForImmediateRichTextTranslation( this object ui )