bbepis / XUnity.AutoTranslator

MIT License
2.01k stars 293 forks source link

YoudaoTranslateEndpoint Implementation and Some Issues(multiple endpoints) #470

Open wyh3130024630 opened 10 months ago

wyh3130024630 commented 10 months ago

Hi, I implemented the YoudaoTranslateEndpoint. Due to my limited coding skills, it took a lot effort. So I hope more people can find it. And here are some issues. I forked your whole project and worked on the implementation and testing based on it. However, when I use OnBeforeTranslate, an error System.Security.SecurityException: ECall method must be packaged into the System module occurs when running TranslatorTest, and it tests successfully when I remove OnBeforeTranslate.
However, even with OnBeforeTranslate, YoudaoTranslateEndpoint can work fine in Unity games.

public override IEnumerator OnBeforeTranslate( IHttpTranslationContext context )
{
   var realtimeSinceStartup = TimeHelper.realtimeSinceStartup;
   var timeSinceLast = realtimeSinceStartup - _lastRequestTimestamp;
   if( timeSinceLast < _delay )
   {
      var delay = _delay - timeSinceLast;
      var instruction = CoroutineHelper.CreateWaitForSecondsRealtime( delay );
      if( instruction != null )
         yield return instruction;
      else
      {
         float start = realtimeSinceStartup;
         var end = start + delay;
         while( realtimeSinceStartup < end )
            yield return null;
      }
   }
   _lastRequestTimestamp = TimeHelper.realtimeSinceStartup;
}

It might because I'm not proficient in using git. In general, I'm a mess when it comes to things related to the overall solution. I can't even individually git-commit the YoudaoTranslate project into my repository; I can only put the entire folder in. Additionally, how can I translate using multiple endpoints? Combining multiple translators makes it easier to understand the meaning of the original text.Although I can use alt+1 to view, I cannot save simultaneously to _AutoGeneratedTranslations.txt. And it's really inconvenient to look at that window while playing a fullscreen game.

Adding quotation marks to a sentence can lead to different results. Generally, it may cause the meaning to be less accurate. However, there is a desire for the translated result to include quotation marks to distinguish between dialogue and narration.