public static string PostProcess(string text, TextPostProcessing postProcessing) { if ((postProcessing & TextPostProcessing.ReplaceMacronWithCircumflex) != 0) { text = ConvertMacronToCircumflex(text); } if ((postProcessing & TextPostProcessing.RemoveAllDiacritics) != 0) { text = RemoveAllDiacritics(text); } if ((postProcessing & TextPostProcessing.ReplaceMacronWithCircumflex) != 0) { text = RemoveNApostrophe(text); } return(text); }
public static string PostProcess(string text, TextPostProcessing postProcessing) { if ((postProcessing & TextPostProcessing.ReplaceHtmlEntities) != 0) { text = WebUtility.HtmlDecode(text); } if ((postProcessing & TextPostProcessing.ReplaceMacronWithCircumflex) != 0) { text = ConvertMacronToCircumflex(text); } if ((postProcessing & TextPostProcessing.RemoveAllDiacritics) != 0) { text = RemoveAllDiacritics(text); } if ((postProcessing & TextPostProcessing.RemoveApostrophes) != 0) { text = RemoveNApostrophe(text); } if ((postProcessing & TextPostProcessing.ReplaceWideCharacters) != 0) { text = ReplaceWideCharacters(text); } return(text); }
public static void Configure() { try { var fi = new FileInfo(typeof(TranslationManager).Assembly.Location); var di = fi.Directory; TranslatorsPath = Path.Combine(di.FullName, TranslatorsFolder); try { ApplicationName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName); } catch (Exception e) { XuaLogger.AutoTranslator.Warn(e, "An error occurred while obtaining the path to the executable. {GameExeName} variable in configuration files will not work correctly."); ApplicationName = string.Empty; } ServiceEndpoint = PluginEnvironment.Current.Preferences.GetOrDefault("Service", "Endpoint", KnownTranslateEndpointNames.GoogleTranslate); Language = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "Language", DefaultLanguage)); FromLanguage = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "FromLanguage", DefaultFromLanguage)); TranslationDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "Directory", Path.Combine("Translation", Path.Combine("{Lang}", "Text"))); OutputFile = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "OutputFile", Path.Combine("Translation", Path.Combine("{Lang}", Path.Combine("Text", "_AutoGeneratedTranslations.txt")))); SubstitutionFile = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "SubstitutionFile", Path.Combine("Translation", Path.Combine("{Lang}", Path.Combine("Text", "_Substitutions.txt")))); PreprocessorsFile = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "PreprocessorsFile", Path.Combine("Translation", Path.Combine("{Lang}", Path.Combine("Text", "_Preprocessors.txt")))); EnableIMGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableIMGUI", false); EnableUGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableUGUI", true); EnableNGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableNGUI", true); EnableTextMeshPro = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMeshPro", true); EnableTextMesh = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMesh", false); EnableFairyGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableFairyGUI", true); MaxCharactersPerTranslation = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxCharactersPerTranslation", 200); IgnoreWhitespaceInDialogue = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInDialogue", true); IgnoreWhitespaceInNGUI = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInNGUI", true); MinDialogueChars = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MinDialogueChars", 20); ForceSplitTextAfterCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceSplitTextAfterCharacters", 0); CopyToClipboard = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CopyToClipboard", false); MaxClipboardCopyCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxClipboardCopyCharacters", 1000); EnableUIResizing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableUIResizing", true); EnableBatching = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableBatching", true); UseStaticTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "UseStaticTranslations", true); OverrideFont = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFont", string.Empty); OverrideFontTextMeshPro = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFontTextMeshPro", string.Empty); ResizeUILineSpacingScale = PluginEnvironment.Current.Preferences.GetOrDefault <float?>("Behaviour", "ResizeUILineSpacingScale", null); ForceUIResizing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceUIResizing", false); IgnoreTextStartingWith = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreTextStartingWith", "\\u180e;") ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => JsonHelper.Unescape(x)).ToArray() ?? new string[0]; TextGetterCompatibilityMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TextGetterCompatibilityMode", false); GameLogTextPaths = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GameLogTextPaths", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); GameLogTextPaths.RemoveWhere(x => !x.StartsWith("/")); // clean up to ensure no 'empty' entries RomajiPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes); TranslationPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex); CacheRegexPatternResults = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexPatternResults", false); CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexLookups", false); CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheWhitespaceDifferences", false); GenerateStaticSubstitutionTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GenerateStaticSubstitutionTranslations", false); GeneratePartialTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GeneratePartialTranslations", false); EnableTranslationScoping = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTranslationScoping", false); EnableSilentMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableSilentMode", true); BlacklistedIMGUIPlugins = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "BlacklistedIMGUIPlugins", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .Where(x => !string.IsNullOrEmpty(x)) .ToHashSet(StringComparer.OrdinalIgnoreCase) ?? new HashSet <string>(StringComparer.OrdinalIgnoreCase); EnableTextPathLogging = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTextPathLogging", false); OutputUntranslatableText = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OutputUntranslatableText", false); IgnoreVirtualTextSetterCallingRules = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreVirtualTextSetterCallingRules", false); MaxTextParserRecursion = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxTextParserRecursion", 1); HtmlEntityPreprocessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "HtmlEntityPreprocessing", true); HandleRichText = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "HandleRichText", true); EnableTranslationHelper = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTranslationHelper", false); ForceMonoModHooks = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceMonoModHooks", false); InitializeHarmonyDetourBridge = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "InitializeHarmonyDetourBridge", !Features.SupportsReflectionEmit && PluginEnvironment.Current.AllowDefaultInitializeHarmonyDetourBridge); TextureDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureDirectory", Path.Combine("Translation", Path.Combine("{Lang}", "Texture"))); TexturesPath = Path.Combine(PluginEnvironment.Current.TranslationPath, Settings.TextureDirectory).Parameterize(); EnableTextureTranslation = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureTranslation", Directory.Exists(TexturesPath)); EnableTextureDumping = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureDumping", false); EnableTextureToggling = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureToggling", false); EnableTextureScanOnSceneLoad = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureScanOnSceneLoad", false); EnableSpriteRendererHooking = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteRendererHooking", false); LoadUnmodifiedTextures = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "LoadUnmodifiedTextures", false); DetectDuplicateTextureNames = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DetectDuplicateTextureNames", false); DuplicateTextureNames = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DuplicateTextureNames", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); EnableLegacyTextureLoading = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableLegacyTextureLoading", false); TextureHashGenerationStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName); CacheTexturesInMemory = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "CacheTexturesInMemory", true); EnableSpriteHooking = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteHooking", false); PreferredStoragePath = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "PreferredStoragePath", Path.Combine("Translation", Path.Combine("{Lang}", "RedirectedResources"))); EnableTextAssetRedirector = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableTextAssetRedirector", false); LogAllLoadedResources = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "LogAllLoadedResources", false); EnableDumping = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableDumping", false); CacheMetadataForAllFiles = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "CacheMetadataForAllFiles", true); if (CacheMetadataForAllFiles && EnableDumping) { XuaLogger.AutoTranslator.Warn("'EnableDumping' and 'CacheMetadataForAllFiles' cannot be enabled at the same time. Disabling 'CacheMetadataForAllFiles'..."); CacheMetadataForAllFiles = false; } // FIXME: UseCorrectDirectorySeparators() is called on entire path because redirected resource path lookups has the same changes (requires v. 5.x.x) RedirectedResourcesPath = Path.Combine(PluginEnvironment.Current.TranslationPath, PreferredStoragePath).UseCorrectDirectorySeparators().Parameterize(); if (MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation) { PluginEnvironment.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].Value = MaxMaxCharactersPerTranslation.ToString(CultureInfo.InvariantCulture); MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation; } UserAgent = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "UserAgent", string.Empty); DisableCertificateValidation = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "DisableCertificateValidation", true); Width = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Width", 400.0f); Height = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Height", 100.0f); EnabledTranslators = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "EnabledTranslators", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); EnableConsole = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableConsole", false); EnableMigrations = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Enable", true); MigrationsTag = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Tag", string.Empty); AutoTranslationsFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, OutputFile.UseCorrectDirectorySeparators()).Parameterize(); SubstitutionFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, SubstitutionFile.UseCorrectDirectorySeparators()).Parameterize(); PreprocessorsFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, PreprocessorsFile.UseCorrectDirectorySeparators()).Parameterize(); TranslationsPath = Path.Combine(PluginEnvironment.Current.TranslationPath, Settings.TranslationDirectory.UseCorrectDirectorySeparators()).Parameterize(); FromLanguageUsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(FromLanguage); ToLanguageUsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(Language); if (EnableTranslationScoping && !Features.SupportsSceneManager) { EnableTranslationScoping = false; XuaLogger.AutoTranslator.Warn("Disabling translation scoping because the SceneManager API is not supported in this version of Unity."); } if (EnableMigrations) { Migrate(); } // update tag MigrationsTag = PluginEnvironment.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version; Save(); } catch (Exception e) { XuaLogger.AutoTranslator.Error(e, "An error occurred during configuration. Shutting plugin down."); IsShutdown = true; } }
public static void Configure() { try { ApplicationName = Path.GetFileNameWithoutExtension(ApplicationInformation.StartupPath); ServiceEndpoint = PluginEnvironment.Current.Preferences.GetOrDefault("Service", "Endpoint", KnownTranslateEndpointNames.GoogleTranslate); Language = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "Language", DefaultLanguage)); FromLanguage = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "FromLanguage", DefaultFromLanguage)); TranslationDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "Directory", "Translation"); OutputFile = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "OutputFile", @"Translation\_AutoGeneratedTranslations.{lang}.txt"); SubstitutionFile = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "SubstitutionFile", @"Translation\_Substitutions.{lang}.txt"); EnableIMGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableIMGUI", false); EnableUGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableUGUI", true); EnableNGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableNGUI", true); EnableTextMeshPro = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMeshPro", true); EnableTextMesh = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMesh", false); AllowPluginHookOverride = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "AllowPluginHookOverride", true); MaxCharactersPerTranslation = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxCharactersPerTranslation", 200); IgnoreWhitespaceInDialogue = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInDialogue", true); IgnoreWhitespaceInNGUI = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInNGUI", true); MinDialogueChars = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MinDialogueChars", 20); ForceSplitTextAfterCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceSplitTextAfterCharacters", 0); CopyToClipboard = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CopyToClipboard", false); MaxClipboardCopyCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxClipboardCopyCharacters", 1000); EnableUIResizing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableUIResizing", true); EnableBatching = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableBatching", true); UseStaticTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "UseStaticTranslations", true); OverrideFont = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFont", string.Empty); OverrideFontTextMeshPro = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFontTextMeshPro", string.Empty); ResizeUILineSpacingScale = PluginEnvironment.Current.Preferences.GetOrDefault <float?>("Behaviour", "ResizeUILineSpacingScale", null); ForceUIResizing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceUIResizing", false); IgnoreTextStartingWith = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreTextStartingWith", "\\u180e;") ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => JsonHelper.Unescape(x)).ToArray() ?? new string[0]; TextGetterCompatibilityMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TextGetterCompatibilityMode", false); GameLogTextPaths = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GameLogTextPaths", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); GameLogTextPaths.RemoveWhere(x => !x.StartsWith("/")); // clean up to ensure no 'empty' entries RomajiPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes); TranslationPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex); ForceMonoModHooks = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceMonoModHooks", false); CacheRegexPatternResults = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexPatternResults", false); CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexLookups", false); CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheWhitespaceDifferences", false); GenerateStaticSubstitutionTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GenerateStaticSubstitutionTranslations", false); GeneratePartialTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GeneratePartialTranslations", false); EnableTranslationScoping = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTranslationScoping", false); EnableSilentMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableSilentMode", false); BlacklistedIMGUIPlugins = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "BlacklistedIMGUIPlugins", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .Where(x => !string.IsNullOrEmpty(x)) .ToHashSet(StringComparer.OrdinalIgnoreCase) ?? new HashSet <string>(StringComparer.OrdinalIgnoreCase); EnableTextPathLogging = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTextPathLogging", false); TextureDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureDirectory", @"Translation\Texture"); EnableTextureTranslation = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureTranslation", false); EnableTextureDumping = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureDumping", false); EnableTextureToggling = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureToggling", false); EnableTextureScanOnSceneLoad = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureScanOnSceneLoad", false); EnableSpriteRendererHooking = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteRendererHooking", false); LoadUnmodifiedTextures = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "LoadUnmodifiedTextures", false); DetectDuplicateTextureNames = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DetectDuplicateTextureNames", false); DuplicateTextureNames = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DuplicateTextureNames", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); EnableLegacyTextureLoading = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableLegacyTextureLoading", false); TextureHashGenerationStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName); PreferredStoragePath = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "PreferredStoragePath", @"RedirectedResources"); EnableTextAssetRedirector = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableTextAssetRedirector", false); LogAllLoadedResources = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "LogAllLoadedResources", false); EnableDumping = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableDumping", false); RedirectedResourcesPath = Path.Combine(PluginEnvironment.Current.TranslationPath, PreferredStoragePath).Replace("/", "\\").Parameterize(); if (MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation) { PluginEnvironment.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].Value = MaxMaxCharactersPerTranslation.ToString(CultureInfo.InvariantCulture); MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation; } UserAgent = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "UserAgent", string.Empty); DisableCertificateValidation = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "DisableCertificateValidation", GetInitialDisableCertificateChecks()); Width = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Width", 400.0f); Height = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Height", 100.0f); EnabledTranslators = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "EnabledTranslators", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); EnableConsole = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableConsole", false); EnableMigrations = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Enable", true); MigrationsTag = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Tag", string.Empty); AutoTranslationsFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, OutputFile.Replace("{lang}", Language)).Replace("/", "\\").Parameterize(); SubstitutionFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, SubstitutionFile.Replace("{lang}", Language)).Replace("/", "\\").Parameterize(); FromLanguageUsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(FromLanguage); ToLanguageUsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(Language); if (EnableTranslationScoping && !Features.SupportsSceneManager) { EnableTranslationScoping = false; XuaLogger.AutoTranslator.Warn("Disabling translation scoping because the SceneManager API is not supported in this version of Unity."); } //// workaround to handle text translation toggling in KK //if( ApplicationName != null ) //{ // var n = ApplicationName.ToLower(); // if( n == "koikatu" || n == "koikatsu" ) // { // RequiresToggleFix = true; // } //} if (EnableMigrations) { Migrate(); } // update tag MigrationsTag = PluginEnvironment.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version; Save(); } catch (Exception e) { XuaLogger.AutoTranslator.Error(e, "An error occurred during configuration. Shutting plugin down."); IsShutdown = true; } }
public static void Configure() { try { ApplicationName = Path.GetFileNameWithoutExtension(ApplicationInformation.StartupPath); ServiceEndpoint = PluginEnvironment.Current.Preferences.GetOrDefault("Service", "Endpoint", KnownTranslateEndpointNames.GoogleTranslate); Language = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "Language", DefaultLanguage)); FromLanguage = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "FromLanguage", DefaultFromLanguage)); TranslationDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "Directory", "Translation"); OutputFile = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "OutputFile", @"Translation\_AutoGeneratedTranslations.{lang}.txt"); EnableIMGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableIMGUI", false); EnableUGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableUGUI", true); EnableNGUI = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableNGUI", true); EnableTextMeshPro = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMeshPro", true); AllowPluginHookOverride = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "AllowPluginHookOverride", true); Delay = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "Delay", 0f); MaxCharactersPerTranslation = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxCharactersPerTranslation", 200); IgnoreWhitespaceInDialogue = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInDialogue", true); IgnoreWhitespaceInNGUI = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInNGUI", true); MinDialogueChars = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MinDialogueChars", 20); ForceSplitTextAfterCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceSplitTextAfterCharacters", 0); CopyToClipboard = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CopyToClipboard", false); MaxClipboardCopyCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxClipboardCopyCharacters", 1000); EnableUIResizing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableUIResizing", true); EnableBatching = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableBatching", true); UseStaticTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "UseStaticTranslations", true); OverrideFont = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFont", string.Empty); ResizeUILineSpacingScale = PluginEnvironment.Current.Preferences.GetOrDefault <float?>("Behaviour", "ResizeUILineSpacingScale", null); ForceUIResizing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceUIResizing", false); IgnoreTextStartingWith = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreTextStartingWith", "\\u180e;") ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => JsonHelper.Unescape(x)).ToArray() ?? new string[0]; TextGetterCompatibilityMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TextGetterCompatibilityMode", false); GameLogTextPaths = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GameLogTextPaths", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); GameLogTextPaths.RemoveWhere(x => !x.StartsWith("/")); // clean up to ensure no 'empty' entries WhitespaceRemovalStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "WhitespaceRemovalStrategy", WhitespaceHandlingStrategy.TrimPerNewline); RomajiPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes); TranslationPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex); EnableExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableExperimentalHooks", false); ForceExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceExperimentalHooks", false); CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexLookups", false); CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheWhitespaceDifferences", true); TextureDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureDirectory", @"Translation\Texture"); EnableTextureTranslation = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureTranslation", false); EnableTextureDumping = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureDumping", false); EnableTextureToggling = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureToggling", false); EnableTextureScanOnSceneLoad = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureScanOnSceneLoad", false); EnableSpriteRendererHooking = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteRendererHooking", false); LoadUnmodifiedTextures = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "LoadUnmodifiedTextures", false); DetectDuplicateTextureNames = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DetectDuplicateTextureNames", false); DuplicateTextureNames = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DuplicateTextureNames", string.Empty) ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>(); TextureHashGenerationStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName); if (MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation) { PluginEnvironment.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].Value = MaxMaxCharactersPerTranslation.ToString(CultureInfo.InvariantCulture); MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation; } UserAgent = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "UserAgent", string.Empty); DisableCertificateValidation = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "DisableCertificateValidation", GetInitialDisableCertificateChecks()); EnablePrintHierarchy = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnablePrintHierarchy", false); EnableConsole = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableConsole", false); EnableDebugLogs = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableLog", false); EnableMigrations = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Enable", true); MigrationsTag = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Tag", string.Empty); AutoTranslationsFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, OutputFile.Replace("{lang}", Language)).Replace("/", "\\").Parameterize(); UsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(FromLanguage); if (EnableMigrations) { Migrate(); } // update tag MigrationsTag = PluginEnvironment.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version; Save(); } catch (Exception e) { XuaLogger.Current.Error(e, "An error occurred during configuration. Shutting plugin down."); IsShutdown = true; } }