Skip to content

Commit

Permalink
Version 4.8.1
Browse files Browse the repository at this point in the history
 * MISC - Experimental Google! Translate compatibility endpoint that services requests out-of-process
 * MISC - Updated default user agents
 * MISC - Minor changes to Google! translate TKK timing logic
 * MISC - Allow translation of placeholder text with UGUI and TextMesh Pro texts
 * BUG FIX - Disallow outputting of IMGUI templated texts that are not considered translatable
  • Loading branch information
randoman committed Jan 5, 2020
1 parent a194e58 commit f60f6bc
Show file tree
Hide file tree
Showing 25 changed files with 569 additions and 25 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
### 4.8.0
### 4.8.1
* MISC - Experimental Google! Translate compatibility endpoint that services requests out-of-process
* MISC - Updated default user agents
* MISC - Minor changes to Google! translate TKK timing logic
* MISC - Allow translation of placeholder text with UGUI and TextMesh Pro texts
* BUG FIX - Disallow outputting of IMGUI templated texts that are not considered translatable

### 4.8.0
* FEATURE - Changed the way TextMesh Pro fonts can be changed. Fonts can now be loaded through external asset bundles
* CHANGE - Removed BepInEx 4.x package to remove confusion about which package to download
* BUG FIX - Fixed a bug that could cause a crash in Unity games using a very old version of the engine
Expand Down
26 changes: 24 additions & 2 deletions XUnity.AutoTranslator.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F9B38FC-4E57-4B83-AF0B-0993B8470823}"
EndProject
Expand Down Expand Up @@ -115,6 +115,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnity.ResourceRedirector.B
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnity.TextureHashGenerator", "src\XUnity.TextureHashGenerator\XUnity.TextureHashGenerator.csproj", "{B0CFE100-5BB0-4FF0-B36A-98F6FE4E3DF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleTranslateCompat", "src\Translators\GoogleTranslateCompat\GoogleTranslateCompat.csproj", "{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleTranslateCompat.ExtProtocol", "src\Translators\GoogleTranslateCompat.ExtProtocol\GoogleTranslateCompat.ExtProtocol.csproj", "{6DC48447-D7DC-45F6-B830-35A0F916C7BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -419,6 +423,22 @@ Global
{B0CFE100-5BB0-4FF0-B36A-98F6FE4E3DF0}.Release|Any CPU.Build.0 = Release|Any CPU
{B0CFE100-5BB0-4FF0-B36A-98F6FE4E3DF0}.Release|x86.ActiveCfg = Release|Any CPU
{B0CFE100-5BB0-4FF0-B36A-98F6FE4E3DF0}.Release|x86.Build.0 = Release|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Debug|x86.ActiveCfg = Debug|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Debug|x86.Build.0 = Debug|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Release|Any CPU.Build.0 = Release|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Release|x86.ActiveCfg = Release|Any CPU
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06}.Release|x86.Build.0 = Release|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Debug|x86.ActiveCfg = Debug|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Debug|x86.Build.0 = Debug|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Release|Any CPU.Build.0 = Release|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Release|x86.ActiveCfg = Release|Any CPU
{6DC48447-D7DC-45F6-B830-35A0F916C7BF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -462,6 +482,8 @@ Global
{526D9044-1C4D-4A06-BAEB-0EB135F04F6B} = {0F9B38FC-4E57-4B83-AF0B-0993B8470823}
{E5CAAB5A-4919-4AD6-9F72-3A09AFD36985} = {0F9B38FC-4E57-4B83-AF0B-0993B8470823}
{B0CFE100-5BB0-4FF0-B36A-98F6FE4E3DF0} = {0F9B38FC-4E57-4B83-AF0B-0993B8470823}
{A560E8E8-C0B1-4FC3-8CD4-C15D64BF9B06} = {7A01BA34-3B96-4910-AC70-462BA59417CB}
{6DC48447-D7DC-45F6-B830-35A0F916C7BF} = {7A01BA34-3B96-4910-AC70-462BA59417CB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EE803FED-4447-4D19-B3D6-88C56E8DFCCA}
Expand Down
3 changes: 2 additions & 1 deletion src/Translators/BingTranslate/BingTranslateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public override IEnumerator OnBeforeTranslate( IHttpTranslationContext context )
if( !_hasSetup || _translationCount % _resetAfter == 0 )
{
_resetAfter = RandomNumbers.Next( 75, 125 );
_translationCount = 0;

_hasSetup = true;

// Setup TKK and cookies
Expand Down Expand Up @@ -186,7 +188,6 @@ public IEnumerator SetupIGAndIID()
XUnityWebResponse response = null;

_cookieContainer = new CookieContainer();
_translationCount = 0;

try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Common.ExtProtocol;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using XUnity.AutoTranslator.Plugin.ExtProtocol;
Expand All @@ -17,6 +18,8 @@ public ExtProtocolHandler( IExtTranslateEndpoint endpoint )

public async Task RunAsync()
{
var untranslatedTexts = new HashSet<string>();

using( var stdout = Console.OpenStandardOutput() )
using( var writer = new StreamWriter( stdout ) )
using( var stdin = Console.OpenStandardInput() )
Expand All @@ -32,6 +35,12 @@ public async Task RunAsync()
var message = ExtProtocolConvert.Decode( receivedPayload ) as TranslationRequest;
if( message == null ) return;

// never allow the same text to be translated twice
foreach( var untranslatedText in message.UntranslatedTexts )
{
if( !untranslatedTexts.Add( untranslatedText ) ) return;
}

var context = new TranslationContext( message.UntranslatedTexts, message.SourceLanguage, message.DestinationLanguage );
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.ExtProtocol.Utilities
{
/// <summary>
/// StringBuilder extensions.
/// </summary>
public static class StringBuilderExtensions
{
/// <summary>
/// Gets a bool indicating if the current line ends in whitespace or newline.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static bool EndsWithWhitespaceOrNewline( this StringBuilder builder )
{
if( builder.Length == 0 ) return true;

var lastChar = builder[ builder.Length - 1 ];
return char.IsWhiteSpace( lastChar ) || lastChar == '\n';
}
}
}
9 changes: 8 additions & 1 deletion src/Translators/GoogleTranslate/GoogleTranslateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ internal class GoogleTranslateEndpoint : HttpEndpoint
private long m = 427761;
private long s = 1179739010;
private int _translationsPerRequest = 10;
private int _translationCount = 0;
private int _resetAfter = RandomNumbers.Next( 75, 125 );

public GoogleTranslateEndpoint()
{
Expand Down Expand Up @@ -73,8 +75,11 @@ public override void Initialize( IInitializationContext context )

public override IEnumerator OnBeforeTranslate( IHttpTranslationContext context )
{
if( !_hasSetup || AutoTranslatorState.TranslationCount % 100 == 0 )
if( !_hasSetup || _translationCount % _resetAfter == 0 )
{
_resetAfter = RandomNumbers.Next( 75, 125 );
_translationCount = 0;

_hasSetup = true;

// Setup TKK and cookies
Expand All @@ -88,6 +93,8 @@ public override IEnumerator OnBeforeTranslate( IHttpTranslationContext context )

public override void OnCreateRequest( IHttpRequestCreationContext context )
{
_translationCount++;

var allUntranslatedText = string.Join( "\n", context.UntranslatedTexts );

XUnityWebRequest request;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Common.ExtProtocol\Common.ExtProtocol.csproj" />
<ProjectReference Include="..\Http.ExtProtocol\Http.ExtProtocol.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="UnityEngine">
<HintPath>..\..\..\libs\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="if $(ConfigurationName) == Release (&#xD;&#xA; XCOPY /Y /I &quot;$(TargetDir)$(TargetName)$(TargetExt)&quot; &quot;$(SolutionDir)dist\Translators\FullNET\&quot;&#xD;&#xA;)" />
</Target>

</Project>
Loading

0 comments on commit f60f6bc

Please sign in to comment.