소스 검색

initial endpoint selection logic fix

randoman 6 년 전
부모
커밋
89527a23e0

+ 2 - 0
README.md

@@ -634,6 +634,8 @@ 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.
 
+For more examples of implementations, you can simply take a look at this projects source code.
+
 **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. I do not recommend using this base class unless it is an authenticated endpoint though.

+ 0 - 5
src/Translators/WatsonTranslate/WatsonTranslateEndpoint.cs

@@ -18,16 +18,11 @@ namespace WatsonTranslate
    internal class WatsonTranslateEndpoint : WwwEndpoint
    {
       private static readonly HashSet<string> SupportedLanguagePairs = new HashSet<string> { "ar-en", "ca-es", "zh-en", "zh-TW-en", "cs-en", "da-en", "nl-en", "en-ar", "en-cs", "en-da", "en-de", "en-es", "en-fi", "en-fr", "en-hi", "en-it", "en-ja", "en-ko", "en-nb", "en-nl", "en-pl", "en-pt", "en-ru", "en-sv", "en-tr", "en-zh", "en-zh-TW", "fi-en", "fr-de", "fr-en", "fr-es", "de-en", "de-fr", "de-it", "hi-en", "hu-en", "it-de", "it-en", "ja-en", "ko-en", "nb-en", "pl-en", "pt-en", "ru-en", "es-ca", "es-en", "es-fr", "sv-en", "tr-en" };
-      private static readonly string RequestTemplate = "{{\"text\":[\"{2}\"],\"model_id\":\"{0}-{1}\"}}";
 
       private string _fullUrl;
       private string _url;
       private string _key;
 
-      public WatsonTranslateEndpoint()
-      {
-      }
-
       public override string Id => "WatsonTranslate";
 
       public override string FriendlyName => "Watson Language Translator";

+ 12 - 9
src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs

@@ -197,18 +197,21 @@ namespace XUnity.AutoTranslator.Plugin.Core
             return;
          }
 
-         try
+         var primaryEndpoint = _configuredEndpoints.FirstOrDefault( x => x.Endpoint.Id == Settings.ServiceEndpoint );
+         if( primaryEndpoint != null )
          {
-            var primaryEndpoint = _configuredEndpoints.FirstOrDefault( x => x.Endpoint.Id == Settings.ServiceEndpoint );
-
-            if( primaryEndpoint == null ) throw new Exception( "The primary endpoint was not properly configured." );
-            if( primaryEndpoint.Error != null ) throw new Exception( "The primary endpoint was not properly configured.", primaryEndpoint.Error );
-
-            _endpoint = primaryEndpoint;
+            if( primaryEndpoint.Error != null )
+            {
+               XuaLogger.Current.Error( primaryEndpoint.Error, "Error occurred during the initialization of the selected translate endpoint." );
+            }
+            else
+            {
+               _endpoint = primaryEndpoint;
+            }
          }
-         catch( Exception e )
+         else if( !string.IsNullOrEmpty( Settings.ServiceEndpoint ) )
          {
-            XuaLogger.Current.Error( e, "An unexpected error occurred during initialization of endpoint." );
+            XuaLogger.Current.Error( $"Could not find the configured endpoint '{Settings.ServiceEndpoint}'." );
          }
 
          // TODO: Perhaps some bleeding edge check to see if this is required?

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/ExtProtocol/ExtProtocolEndpoint.cs

@@ -167,7 +167,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.ExtProtocol
 
          while( _initializing && !_failed ) yield return new WaitForSeconds( 0.2f ); 
 
-         if( _failed ) context.Fail( "Translator failed.", null );
+         if( _failed ) context.Fail( "External process failed." );
 
          var result = new ProtocolTransactionHandle();
          var id = Guid.NewGuid();

+ 2 - 2
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/Http/HttpEndpoint.cs

@@ -78,7 +78,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Http
 
          // prepare request
          OnCreateRequest( httpContext );
-         if( httpContext.Request == null ) httpContext.Fail( "No request object was provided by the translator.", null );
+         if( httpContext.Request == null ) httpContext.Fail( "No request object was provided by the translator." );
          
          // execute request
          var client = new XUnityWebClient();
@@ -95,7 +95,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Http
          if( response.Error != null ) httpContext.Fail( "Error occurred while retrieving translation.", response.Error ); 
 
          // failure
-         if( response.Data == null ) httpContext.Fail( "Error occurred while retrieving translation. Nothing was returned.", null );
+         if( response.Data == null ) httpContext.Fail( "Error occurred while retrieving translation. Nothing was returned." );
 
          // extract text
          OnExtractTranslation( httpContext );

+ 3 - 3
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/Www/WwwEndpoint.cs

@@ -98,7 +98,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Www
 
          // prepare request
          OnCreateRequest( wwwContext );
-         if( wwwContext.RequestInfo == null ) wwwContext.Fail( "No request object was provided by the translator.", null );
+         if( wwwContext.RequestInfo == null ) wwwContext.Fail( "No request object was provided by the translator." );
 
          var request = wwwContext.RequestInfo;
          var url = request.Address;
@@ -113,11 +113,11 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Www
 
          // extract error
          string error = (string)AccessTools.Property( Constants.ClrTypes.WWW, "error" ).GetValue( www, null );
-         if( error != null ) wwwContext.Fail( "Error occurred while retrieving translation. " + error, null );
+         if( error != null ) wwwContext.Fail( "Error occurred while retrieving translation. " + error );
 
          // extract text
          var text = (string)AccessTools.Property( Constants.ClrTypes.WWW, "text" ).GetValue( www, null );
-         if( text == null ) wwwContext.Fail( "Error occurred while extracting text from response.", null ); 
+         if( text == null ) wwwContext.Fail( "Error occurred while extracting text from response." ); 
 
          wwwContext.ResponseData = text;
 

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/UI/DropdownGUI.cs

@@ -24,7 +24,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.UI
          _x = x;
          _y = y;
          _width = width;
-         _noSelection = new GUIContent( "----", "SELECT TRANSLATOR. No translator is currently selected, which means no new translations will be performed. Please select one from the dropdown." );
+         _noSelection = new GUIContent( "----", "<b>SELECT TRANSLATOR</b>\nNo translator is currently selected, which means no new translations will be performed. Please select one from the dropdown." );
 
          _options = new List<TDropdownOptionViewModel>();
          foreach( var item in options )

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

@@ -50,7 +50,7 @@
       <ItemGroup>
          <VersionNumber Include="$([System.Text.RegularExpressions.Regex]::Replace(&quot;%(Targets.Version)&quot;, &quot;^(.+?)(\.0+)$&quot;, &quot;$1&quot;))" />
       </ItemGroup>
-     <Exec Command="if $(ConfigurationName) == Release (&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.Core.dll&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.Core.xml&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.ExtProtocol.dll&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.ExtProtocol.xml&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   COPY /Y &quot;$(SolutionDir)README.md&quot; &quot;$(SolutionDir)dist\Developer\Developer\README (AutoTranslator).md&quot;&#xD;&#xA;   powershell Compress-Archive -Path '$(SolutionDir)dist\Developer\Developer' -DestinationPath '$(SolutionDir)dist\Developer\XUnity.AutoTranslator-Developer-@(VersionNumber).zip' -Force)&#xD;&#xA;)" />
+     <Exec Command="if $(ConfigurationName) == Release (&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.Core.dll&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.Core.xml&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.Core.pdb&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.ExtProtocol.dll&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.ExtProtocol.xml&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   XCOPY /Y /I &quot;$(TargetDir)XUnity.AutoTranslator.Plugin.ExtProtocol.pdb&quot; &quot;$(SolutionDir)dist\Developer\Developer\&quot;&#xD;&#xA;   COPY /Y &quot;$(SolutionDir)README.md&quot; &quot;$(SolutionDir)dist\Developer\Developer\README (AutoTranslator).md&quot;&#xD;&#xA;   powershell Compress-Archive -Path '$(SolutionDir)dist\Developer\Developer' -DestinationPath '$(SolutionDir)dist\Developer\XUnity.AutoTranslator-Developer-@(VersionNumber).zip' -Force)&#xD;&#xA;)" />
    </Target>
 
 </Project>