|
@@ -253,7 +253,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
if( TranslationManager.CurrentEndpoint != endpoint )
|
|
|
{
|
|
|
TranslationManager.CurrentEndpoint = endpoint;
|
|
|
-
|
|
|
+
|
|
|
if( TranslationManager.CurrentEndpoint != null )
|
|
|
{
|
|
|
if( !Settings.IsShutdown )
|
|
@@ -371,12 +371,12 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
TextureCache.LoadTranslationFiles();
|
|
|
}
|
|
|
|
|
|
- private void CreateTranslationJobFor( TranslationEndpointManager endpoint, object ui, TranslationKey key, TranslationResult translationResult, ParserTranslationContext context )
|
|
|
+ private void CreateTranslationJobFor( TranslationEndpointManager endpoint, object ui, UntranslatedText key, TranslationResult translationResult, ParserTranslationContext context )
|
|
|
{
|
|
|
var added = endpoint.EnqueueTranslation( ui, key, translationResult, context );
|
|
|
if( added && translationResult == null )
|
|
|
{
|
|
|
- SpamChecker.PerformChecks( key.GetDictionaryLookupKey() );
|
|
|
+ SpamChecker.PerformChecks( key.TrimmedText );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -429,14 +429,14 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void QueueNewUntranslatedForClipboard( TranslationKey key )
|
|
|
+ private void QueueNewUntranslatedForClipboard( UntranslatedText key )
|
|
|
{
|
|
|
if( Settings.CopyToClipboard && Features.SupportsClipboard )
|
|
|
{
|
|
|
- if( !_textsToCopyToClipboard.Contains( key.RelevantText ) )
|
|
|
+ if( !_textsToCopyToClipboard.Contains( key.TrimmedText ) )
|
|
|
{
|
|
|
- _textsToCopyToClipboard.Add( key.RelevantText );
|
|
|
- _textsToCopyToClipboardOrdered.Add( key.RelevantText );
|
|
|
+ _textsToCopyToClipboard.Add( key.TrimmedText );
|
|
|
+ _textsToCopyToClipboardOrdered.Add( key.TrimmedText );
|
|
|
|
|
|
_clipboardUpdated = Time.realtimeSinceStartup;
|
|
|
}
|
|
@@ -585,7 +585,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
|
|
|
// NGUI only behaves if you set the text after the resize behaviour
|
|
|
ui.SetText( text );
|
|
|
-
|
|
|
+
|
|
|
info?.ResetScrollIn( ui );
|
|
|
|
|
|
if( TranslationAggregatorWindow != null && info != null && !ui.IsSpammingComponent() )
|
|
@@ -935,18 +935,21 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
private string TranslateImmediate( object ui, string text, TextTranslationInfo info, bool ignoreComponentState )
|
|
|
{
|
|
|
// Get the trimmed text
|
|
|
- text = ( text ?? ui.GetText() ).TrimIfConfigured();
|
|
|
+ string originalText = text;
|
|
|
+
|
|
|
+ text = text ?? ui.GetText();
|
|
|
|
|
|
if( !string.IsNullOrEmpty( text ) && TextCache.IsTranslatable( text ) && ShouldTranslateTextComponent( ui, ignoreComponentState ) && !IsCurrentlySetting( info ) )
|
|
|
{
|
|
|
- info?.Reset( text );
|
|
|
+ info?.Reset( originalText );
|
|
|
|
|
|
//var textKey = new TranslationKey( ui, text, !ui.SupportsStabilization(), false );
|
|
|
- var textKey = new TranslationKey( ui, text, ui.IsSpammingComponent(), false );
|
|
|
+ var isSpammer = ui.IsSpammingComponent();
|
|
|
+ var textKey = GetCacheKey( ui, text, isSpammer, false );
|
|
|
|
|
|
// if we already have translation loaded in our _translatios dictionary, simply load it and set text
|
|
|
string translation;
|
|
|
- if( TextCache.TryGetTranslation( textKey, out translation ) )
|
|
|
+ if( TextCache.TryGetTranslation( textKey, false, out translation ) )
|
|
|
{
|
|
|
if( !string.IsNullOrEmpty( translation ) )
|
|
|
{
|
|
@@ -985,16 +988,10 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
{
|
|
|
var result = new TranslationResult();
|
|
|
|
|
|
- if( context == null )
|
|
|
- {
|
|
|
- // Get the trimmed text
|
|
|
- text = text.TrimIfConfigured();
|
|
|
- }
|
|
|
-
|
|
|
// Ensure that we actually want to translate this text and its owning UI element.
|
|
|
if( !string.IsNullOrEmpty( text ) && endpoint.IsTranslatable( text ) && IsBelowMaxLength( text ) )
|
|
|
{
|
|
|
- var textKey = new TranslationKey( null, text, false, context != null );
|
|
|
+ var textKey = GetCacheKey( null, text, false, context != null );
|
|
|
|
|
|
// if we already have translation loaded in our _translatios dictionary, simply load it and set text
|
|
|
string translation;
|
|
@@ -1065,7 +1062,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
if( !string.IsNullOrEmpty( untranslatedTextPart ) && endpoint.IsTranslatable( untranslatedTextPart ) && IsBelowMaxLength( untranslatedTextPart ) )
|
|
|
{
|
|
|
string partTranslation;
|
|
|
- if( endpoint.TryGetTranslation( untranslatedTextPart, out partTranslation ) )
|
|
|
+ if( endpoint.TryGetTranslation( new UntranslatedText( untranslatedTextPart, false, false ), out partTranslation ) )
|
|
|
{
|
|
|
translations.Add( variableName, partTranslation );
|
|
|
}
|
|
@@ -1103,11 +1100,6 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
|
|
|
// make sure text exists
|
|
|
var originalText = text;
|
|
|
- if( context == null )
|
|
|
- {
|
|
|
- // Get the trimmed text
|
|
|
- text = text.TrimIfConfigured();
|
|
|
- }
|
|
|
|
|
|
// Ensure that we actually want to translate this text and its owning UI element.
|
|
|
if( !string.IsNullOrEmpty( text ) && TextCache.IsTranslatable( text ) && ShouldTranslateTextComponent( ui, ignoreComponentState ) && !IsCurrentlySetting( info ) )
|
|
@@ -1116,12 +1108,11 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
var isSpammer = ui.IsSpammingComponent();
|
|
|
if( isSpammer && !IsBelowMaxLength( text ) ) return null; // avoid templating long strings every frame for IMGUI, important!
|
|
|
|
|
|
- //var textKey = new TranslationKey( ui, text, !supportsStabilization, context != null );
|
|
|
- var textKey = new TranslationKey( ui, text, isSpammer, context != null );
|
|
|
+ var textKey = GetCacheKey( ui, text, isSpammer, context != null );
|
|
|
|
|
|
// if we already have translation loaded in our _translatios dictionary, simply load it and set text
|
|
|
string translation;
|
|
|
- if( TextCache.TryGetTranslation( textKey, out translation ) )
|
|
|
+ if( TextCache.TryGetTranslation( textKey, !isSpammer, out translation ) )
|
|
|
{
|
|
|
if( context == null && !isSpammer )
|
|
|
{
|
|
@@ -1206,18 +1197,17 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
_ongoingOperations.Remove( ui );
|
|
|
|
|
|
originalText = stabilizedText;
|
|
|
- stabilizedText = stabilizedText.TrimIfConfigured();
|
|
|
|
|
|
if( !string.IsNullOrEmpty( stabilizedText ) && TextCache.IsTranslatable( stabilizedText ) )
|
|
|
{
|
|
|
- var stabilizedTextKey = new TranslationKey( ui, stabilizedText, false );
|
|
|
+ var stabilizedTextKey = GetCacheKey( ui, stabilizedText, false, false );
|
|
|
|
|
|
QueueNewUntranslatedForClipboard( stabilizedTextKey );
|
|
|
|
|
|
info?.Reset( originalText );
|
|
|
|
|
|
// once the text has stabilized, attempt to look it up
|
|
|
- if( TextCache.TryGetTranslation( stabilizedTextKey, out translation ) )
|
|
|
+ if( TextCache.TryGetTranslation( stabilizedTextKey, true, out translation ) )
|
|
|
{
|
|
|
if( !string.IsNullOrEmpty( translation ) )
|
|
|
{
|
|
@@ -1311,7 +1301,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
// once the text has stabilized, attempt to look it up
|
|
|
if( !Settings.IsShutdown && !endpoint.HasFailedDueToConsecutiveErrors )
|
|
|
{
|
|
|
- if( !TextCache.TryGetTranslation( textKey, out translation ) )
|
|
|
+ if( !TextCache.TryGetTranslation( textKey, true, out translation ) )
|
|
|
{
|
|
|
CreateTranslationJobFor( endpoint, ui, textKey, null, context );
|
|
|
}
|
|
@@ -1319,7 +1309,6 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
}
|
|
|
} ) );
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1339,7 +1328,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
if( !string.IsNullOrEmpty( untranslatedTextPart ) && TextCache.IsTranslatable( untranslatedTextPart ) && IsBelowMaxLength( untranslatedTextPart ) )
|
|
|
{
|
|
|
string partTranslation;
|
|
|
- if( TextCache.TryGetTranslation( untranslatedTextPart, out partTranslation ) )
|
|
|
+ if( TextCache.TryGetTranslation( new UntranslatedText( untranslatedTextPart, false, false ), false, out partTranslation ) )
|
|
|
{
|
|
|
translations.Add( variableName, partTranslation );
|
|
|
}
|
|
@@ -1406,9 +1395,9 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
/// for global text, where the component cannot tell us if the text
|
|
|
/// has changed itself.
|
|
|
/// </summary>
|
|
|
- private IEnumerator WaitForTextStablization( TranslationKey textKey, float delay, Action onTextStabilized, Action onFailed = null )
|
|
|
+ private IEnumerator WaitForTextStablization( UntranslatedText textKey, float delay, Action onTextStabilized, Action onFailed = null )
|
|
|
{
|
|
|
- var text = textKey.GetDictionaryLookupKey();
|
|
|
+ var text = textKey.TrimmedText;
|
|
|
|
|
|
if( !_immediatelyTranslating.Contains( text ) )
|
|
|
{
|
|
@@ -1510,7 +1499,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
{
|
|
|
ConnectionTrackingWebClient.CheckServicePoints();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if( Input.anyKey )
|
|
|
{
|
|
|
var isAltPressed = Input.GetKey( KeyCode.LeftAlt ) || Input.GetKey( KeyCode.RightAlt );
|
|
@@ -1676,7 +1665,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
{
|
|
|
if( job.SaveResultGlobally )
|
|
|
{
|
|
|
- TextCache.AddTranslationToCache( job.Key, job.TranslatedText );
|
|
|
+ TextCache.AddTranslationToCache( job.Key.TranslatableText, job.TranslatedText );
|
|
|
}
|
|
|
|
|
|
job.Endpoint.AddTranslationToCache( job.Key, job.TranslatedText );
|
|
@@ -1699,7 +1688,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
// update the original text, but only if it has not been chaanged already for some reason (could be other translator plugin or game itself)
|
|
|
try
|
|
|
{
|
|
|
- var text = component.GetText().TrimIfConfigured();
|
|
|
+ var text = component.GetText();
|
|
|
if( text == job.Key.OriginalText )
|
|
|
{
|
|
|
var info = component.GetOrCreateTextTranslationInfo();
|
|
@@ -1723,7 +1712,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var text = context.Component.GetText().TrimIfConfigured();
|
|
|
+ var text = context.Component.GetText();
|
|
|
var result = context.Result;
|
|
|
Dictionary<string, string> translations = new Dictionary<string, string>();
|
|
|
|
|
@@ -1787,6 +1776,14 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static UntranslatedText GetCacheKey( object ui, string originalText, bool templatizeByNumbers, bool neverRemoveWhitespace )
|
|
|
+ {
|
|
|
+ var removeInternalWhitespace = !neverRemoveWhitespace
|
|
|
+ && ( ( Settings.IgnoreWhitespaceInDialogue && originalText.Length > Settings.MinDialogueChars ) || ( Settings.IgnoreWhitespaceInNGUI && ui.IsNGUI() ) );
|
|
|
+
|
|
|
+ return new UntranslatedText( originalText, templatizeByNumbers, removeInternalWhitespace );
|
|
|
+ }
|
|
|
+
|
|
|
private void ReloadTranslations()
|
|
|
{
|
|
|
LoadTranslations();
|
|
@@ -1802,10 +1799,11 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
if( component.gameObject?.activeSelf ?? false )
|
|
|
{
|
|
|
var tti = kvp.Value as TextTranslationInfo;
|
|
|
- if( tti != null && !string.IsNullOrEmpty( tti.OriginalText ) )
|
|
|
+ var originalText = tti.OriginalText;
|
|
|
+ if( tti != null && !string.IsNullOrEmpty( originalText ) )
|
|
|
{
|
|
|
- var key = new TranslationKey( kvp.Key, tti.OriginalText, false );
|
|
|
- if( TextCache.TryGetTranslation( key, out string translatedText ) && !string.IsNullOrEmpty( translatedText ) )
|
|
|
+ var key = GetCacheKey( kvp.Key, originalText, false, false );
|
|
|
+ if( TextCache.TryGetTranslation( key, true, out string translatedText ) && !string.IsNullOrEmpty( translatedText ) )
|
|
|
{
|
|
|
SetTranslatedText( kvp.Key, translatedText, tti ); // no need to untemplatize the translated text
|
|
|
}
|
|
@@ -2056,7 +2054,23 @@ namespace XUnity.AutoTranslator.Plugin.Core
|
|
|
if( obj != null )
|
|
|
{
|
|
|
var layer = LayerMask.LayerToName( obj.layer );
|
|
|
- var components = string.Join( ", ", obj.GetComponents<Component>().Select( x => x?.GetType()?.Name ).Where( x => x != null ).ToArray() );
|
|
|
+ var components = string.Join( ", ", obj.GetComponents<Component>().Select( x =>
|
|
|
+ {
|
|
|
+ string output = null;
|
|
|
+ var type = x?.GetType();
|
|
|
+ if( type != null )
|
|
|
+ {
|
|
|
+ output = type.Name;
|
|
|
+
|
|
|
+ var text = x.GetText();
|
|
|
+ if( !string.IsNullOrEmpty( text ) )
|
|
|
+ {
|
|
|
+ output += " (" + text + ")";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return output;
|
|
|
+ } ).Where( x => x != null ).ToArray() );
|
|
|
var line = string.Format( "{0,-50} {1,100}",
|
|
|
identation + obj.name + " [" + layer + "]",
|
|
|
components );
|