Skip to content

Commit

Permalink
Version 4.11.2
Browse files Browse the repository at this point in the history
 * MISC - Add toggle to enable/disable translation aggregator UI
 * MISC - Enable copy translations / original text to clipboard from translation aggregator UI
 * MISC - Enable "auto" source language for google, bing and papago translate
 * BUG FIX - Fixed some startup errors that occurred while initializing the plugin if the Resource Redirector was not present
  • Loading branch information
randoman committed May 16, 2020
1 parent 48a719d commit b679a20
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### 4.11.2
* MISC - Add toggle to enable/disable translation aggregator UI
* MISC - Enable copy translations / original text to clipboard from translation aggregator UI
* MISC - Enable "auto" source language for google, bing and papago translate
* BUG FIX - Fixed some startup errors that occurred while initializing the plugin if the Resource Redirector was not present
* BUG FIX - Fixed a bug in BaiduTranslate to allow it to use japanese (ja) as input/output language

### 4.11.1
* MISC - Added support for named and optional groups in splitter and standard regexes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Endpoint=GoogleTranslate ;Endpoint to use. Can be ["GoogleTranslate", "G

[General]
Language=en ;The language to translate into
FromLanguage=ja ;The original language of the game
FromLanguage=ja ;The original language of the game. "auto" is also supported for some endpoints, but it is generally not recommended

[Files]
Directory=Translation\{Lang}\Text ;Directory to search for cached translation files. Can use placeholder: {GameExeName}, {Lang}
Expand Down
4 changes: 2 additions & 2 deletions src/Translators/BaiduTranslate/BaiduTranslateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private string FixLanguage( string lang )
case "zh-Hans":
case "zh-CN":
return "zh";
case "ja":
return "jp";
//case "ja":
// return "jp";
default:
return lang;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Translators/BingTranslate/BingTranslateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class BingTranslateEndpoint : HttpEndpoint
{
private static readonly HashSet<string> SupportedLanguages = new HashSet<string>
{
"af","ar","bn","bs","bg","yue","ca","zh-Hans","zh-Hant","hr","cs","da","nl","en","et","fj","fil","fi","fr","de","el","ht","he","hi","mww","hu","is","id","it","ja","sw","tlh","tlh-Qaak","ko","lv","lt","mg","ms","mt","nb","fa","pl","pt","otq","ro","ru","sm","sr-Cyrl","sr-Latn","sk","sl","es","sv","ty","ta","te","th","to","tr","uk","ur","vi","cy","yua"
"auto","af","ar","bn","bs","bg","yue","ca","zh-Hans","zh-Hant","hr","cs","da","nl","en","et","fj","fil","fi","fr","de","el","ht","he","hi","mww","hu","is","id","it","ja","sw","tlh","tlh-Qaak","ko","lv","lt","mg","ms","mt","nb","fa","pl","pt","otq","ro","ru","sm","sr-Cyrl","sr-Latn","sk","sl","es","sv","ty","ta","te","th","to","tr","uk","ur","vi","cy","yua"
};

private static readonly string HttpsServicePointTemplateUrl = "https://www.bing.com/ttranslatev3?isVertical=1&&IG={0}&IID={1}.{2}"; // "https://www.bing.com/ttranslate?&category=&IG={0}&IID={1}.{2}";
Expand Down Expand Up @@ -72,6 +72,8 @@ private string FixLanguage( string lang )
return "zh-Hans";
case "zh-TW":
return "zh-Hant";
case "auto":
return "auto-detect";
default:
return lang;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Translators/GoogleTranslate/GoogleTranslateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class GoogleTranslateEndpoint : HttpEndpoint
{
private static readonly HashSet<string> SupportedLanguages = new HashSet<string>
{
"romaji","af","sq","am","ar","hy","az","eu","be","bn","bs","bg","ca","ceb","zh-CN","zh-TW","co","hr","cs","da","nl","en","eo","et","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","he","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","my","ne","no","ny","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","su","sw","sv","tl","tg","ta","te","th","tr","uk","ur","uz","vi","cy","xh","yi","yo","zu"
"auto","romaji","af","sq","am","ar","hy","az","eu","be","bn","bs","bg","ca","ceb","zh-CN","zh-TW","co","hr","cs","da","nl","en","eo","et","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","he","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","my","ne","no","ny","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","su","sw","sv","tl","tg","ta","te","th","tr","uk","ur","uz","vi","cy","xh","yi","yo","zu"
};

//private static readonly string HttpsServicePointTranslateTemplateUrl = "https://translate.googleapis.com/translate_a/single?client=webapp&sl={0}&tl={1}&dt=t&dt=at&tk={2}&q={3}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task SetupTKK()
var request = CreateWebSiteRequest();
response = await client.SendAsync( request );
}
catch( Exception e )
catch( Exception )
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class GoogleTranslateCompatEndpoint : ExtProtocolEndpoint
{
private static readonly HashSet<string> SupportedLanguages = new HashSet<string>
{
"af","sq","am","ar","hy","az","eu","be","bn","bs","bg","ca","ceb","zh-CN","zh-TW","co","hr","cs","da","nl","en","eo","et","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","he","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","my","ne","no","ny","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","su","sw","sv","tl","tg","ta","te","th","tr","uk","ur","uz","vi","cy","xh","yi","yo","zu"
"auto","af","sq","am","ar","hy","az","eu","be","bn","bs","bg","ca","ceb","zh-CN","zh-TW","co","hr","cs","da","nl","en","eo","et","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","he","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","my","ne","no","ny","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","su","sw","sv","tl","tg","ta","te","th","tr","uk","ur","uz","vi","cy","xh","yi","yo","zu"
};

public override string Id => "GoogleTranslateCompat";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class LanguageHelper
{ "zh", ContainsChineseSymbols },
{ "ko", ContainsKoreanSymbols },
{ "en", ContainsStandardLatinSymbols },
{ "auto", text => true },
};

private static readonly HashSet<string> LanguagesNotUsingWhitespaceBetweenWords = new HashSet<string>
Expand Down
5 changes: 5 additions & 0 deletions src/XUnity.Common/Utilities/CecilFastReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

namespace XUnity.Common.Utilities
{
/// <summary>
/// Mostly based on:
/// * https://github.com/MonoMod/MonoMod/blob/master/MonoMod.Utils/FastReflectionHelper.cs
/// * https://github.com/pardeike/Harmony/blob/master/Harmony/Extras/FastAccess.cs
/// </summary>
internal static class CecilFastReflectionHelper
{
private static readonly Type[] _DynamicMethodDelegateArgs = { typeof( object ), typeof( object[] ) };
Expand Down
24 changes: 24 additions & 0 deletions src/XUnity.Common/Utilities/CustomFastReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@

namespace XUnity.Common.Utilities
{
/// <summary>
/// WARNING: Pubternal API (internal). Do not use. May change during any update.
/// </summary>
public static class CustomFastReflectionHelper
{
private static readonly Dictionary<FastReflectionDelegateKey, FastReflectionDelegate> _MethodCache = new Dictionary<FastReflectionDelegateKey, FastReflectionDelegate>();

/// <summary>
/// WARNING: Pubternal API (internal). Do not use. May change during any update.
/// </summary>
/// <param name="method"></param>
/// <param name="directBoxValueAccess"></param>
/// <param name="forceNonVirtCall"></param>
/// <returns></returns>
public static FastReflectionDelegate CreateFastDelegate( this MethodBase method, bool directBoxValueAccess = true, bool forceNonVirtCall = false )
{
var key = new FastReflectionDelegateKey( method, directBoxValueAccess, forceNonVirtCall );
Expand All @@ -34,6 +44,13 @@ public static FastReflectionDelegate CreateFastDelegate( this MethodBase method,
return dmd;
}

/// <summary>
/// WARNING: Pubternal API (internal). Do not use. May change during any update.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="F"></typeparam>
/// <param name="fieldInfo"></param>
/// <returns></returns>
public static Func<T, F> CreateFastFieldGetter<T, F>( FieldInfo fieldInfo )
{
if( ClrTypes.DynamicMethodDefinition != null )
Expand All @@ -46,6 +63,13 @@ public static Func<T, F> CreateFastFieldGetter<T, F>( FieldInfo fieldInfo )
}
}

/// <summary>
/// WARNING: Pubternal API (internal). Do not use. May change during any update.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="F"></typeparam>
/// <param name="fieldInfo"></param>
/// <returns></returns>
public static Action<T, F> CreateFastFieldSetter<T, F>( FieldInfo fieldInfo )
{
if( ClrTypes.DynamicMethodDefinition != null )
Expand Down
6 changes: 6 additions & 0 deletions src/XUnity.Common/Utilities/FastReflectionDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@

namespace XUnity.Common.Utilities
{
/// <summary>
/// WARNING: Pubternal API (internal). Do not use. May change during any update.
/// </summary>
/// <param name="target"></param>
/// <param name="args"></param>
/// <returns></returns>
public delegate object FastReflectionDelegate( object target, params object[] args );
}
36 changes: 7 additions & 29 deletions src/XUnity.Common/Utilities/ReflectionEmitFastReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace XUnity.Common.Utilities
{
/// <summary>
/// Mostly based on:
/// * https://github.com/MonoMod/MonoMod/blob/master/MonoMod.Utils/FastReflectionHelper.cs
/// * https://github.com/pardeike/Harmony/blob/master/Harmony/Extras/FastAccess.cs
/// </summary>
internal static class ReflectionEmitFastReflectionHelper
{
private static readonly Type[] _DynamicMethodDelegateArgs = { typeof( object ), typeof( object[] ) };
Expand All @@ -21,13 +26,6 @@ public static FastReflectionDelegate CreateFastDelegate( MethodBase method, bool
if( method.DeclaringType.IsValueType )
{
il.Emit( OpCodes.Unbox_Any, method.DeclaringType );
il.Emit( OpCodes.Stloc_0 );
var builder = il.DeclareLocal( method.DeclaringType );
il.Emit( OpCodes.Ldloca_S, builder );
}
else
{
il.Emit( OpCodes.Castclass, method.DeclaringType );
}
}

Expand Down Expand Up @@ -143,17 +141,7 @@ public static Func<T, F> CreateFastFieldGetter<T, F>( FieldInfo fieldInfo )
if( !fieldInfo.IsStatic )
{
il.Emit( OpCodes.Ldarg_0 );
if( fieldInfo.DeclaringType.IsValueType )
{
il.Emit( OpCodes.Unbox_Any, fieldInfo.DeclaringType );
il.Emit( OpCodes.Stloc_0 );
var builder = il.DeclareLocal( fieldInfo.DeclaringType );
il.Emit( OpCodes.Ldloca_S, builder );
}
else
{
il.Emit( OpCodes.Castclass, fieldInfo.DeclaringType );
}
il.Emit( OpCodes.Castclass, fieldInfo.DeclaringType );
}

il.Emit( fieldInfo.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, fieldInfo );
Expand All @@ -180,17 +168,7 @@ public static Action<T, F> CreateFastFieldSetter<T, F>( FieldInfo fieldInfo )
if( !fieldInfo.IsStatic )
{
il.Emit( OpCodes.Ldarg_0 );
if( fieldInfo.DeclaringType.IsValueType )
{
il.Emit( OpCodes.Unbox_Any, fieldInfo.DeclaringType );
il.Emit( OpCodes.Stloc_0 );
var builder = il.DeclareLocal( fieldInfo.DeclaringType );
il.Emit( OpCodes.Ldloca_S, builder );
}
else
{
il.Emit( OpCodes.Castclass, fieldInfo.DeclaringType );
}
il.Emit( OpCodes.Castclass, fieldInfo.DeclaringType );
}

il.Emit( OpCodes.Ldarg_1 );
Expand Down

0 comments on commit b679a20

Please sign in to comment.