From eb876aa4d150a63f261e8a5299b09b42c92cf7fd Mon Sep 17 00:00:00 2001 From: Archi Date: Sun, 24 Oct 2021 18:40:26 +0200 Subject: [PATCH] Warn about incomplete translation also in our plugin --- .../SteamTokenDumperPlugin.cs | 2 +- ArchiSteamFarm/Core/Utilities.cs | 63 +++++++++++++++++++ ArchiSteamFarm/Program.cs | 55 +--------------- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index b70271f6b..1b497c0fb 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -205,7 +205,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { public IReadOnlyCollection? OnBotSteamHandlersInit(Bot bot) => null; - public override void OnLoaded() { } + public override void OnLoaded() => Utilities.WarnAboutIncompleteTranslation(Strings.ResourceManager); public void OnPICSChanges(uint currentChangeNumber, IReadOnlyDictionary appChanges, IReadOnlyDictionary packageChanges) { if (currentChangeNumber == 0) { diff --git a/ArchiSteamFarm/Core/Utilities.cs b/ArchiSteamFarm/Core/Utilities.cs index e0b28f647..974b909da 100644 --- a/ArchiSteamFarm/Core/Utilities.cs +++ b/ArchiSteamFarm/Core/Utilities.cs @@ -23,16 +23,20 @@ using JustArchiNET.Madness; #endif using System; +using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; +using System.Globalization; using System.IO; using System.Linq; using System.Net; +using System.Resources; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using AngleSharp.Dom; using AngleSharp.XPath; +using ArchiSteamFarm.Localization; using ArchiSteamFarm.Storage; using Humanizer; using Humanizer.Localisation; @@ -357,5 +361,64 @@ namespace ArchiSteamFarm.Core { return (result.Score < 4, string.IsNullOrEmpty(feedback.Warning) ? feedback.Suggestions.FirstOrDefault() : feedback.Warning); } + + internal static void WarnAboutIncompleteTranslation(ResourceManager resourceManager) { + if (resourceManager == null) { + throw new ArgumentNullException(nameof(resourceManager)); + } + + // Skip translation progress for English and invariant (such as "C") cultures + switch (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName) { + case "en": + case "iv": + case "qps": + return; + } + + // We can't dispose this resource set, as we can't be sure if it isn't used somewhere else, rely on GC in this case + ResourceSet? defaultResourceSet = resourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true); + + if (defaultResourceSet == null) { + ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet)); + + return; + } + + HashSet defaultStringObjects = defaultResourceSet.Cast().ToHashSet(); + + if (defaultStringObjects.Count == 0) { + ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects)); + + return; + } + + // We can't dispose this resource set, as we can't be sure if it isn't used somewhere else, rely on GC in this case + ResourceSet? currentResourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); + + if (currentResourceSet == null) { + ASF.ArchiLogger.LogNullError(nameof(currentResourceSet)); + + return; + } + + HashSet currentStringObjects = currentResourceSet.Cast().ToHashSet(); + + if (currentStringObjects.Count >= defaultStringObjects.Count) { + // Either we have 100% finished translation, or we're missing it entirely and using en-US + HashSet testStringObjects = currentStringObjects.ToHashSet(); + testStringObjects.ExceptWith(defaultStringObjects); + + // If we got 0 as final result, this is the missing language + // Otherwise it's just a small amount of strings that happen to be the same + if (testStringObjects.Count == 0) { + currentStringObjects = testStringObjects; + } + } + + if (currentStringObjects.Count < defaultStringObjects.Count) { + float translationCompleteness = currentStringObjects.Count / (float) defaultStringObjects.Count; + ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.TranslationIncomplete, $"{CultureInfo.CurrentUICulture.Name} ({CultureInfo.CurrentUICulture.EnglishName})", translationCompleteness.ToString("P1", CultureInfo.CurrentCulture))); + } + } } } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 995239f91..67cd05d14 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -20,14 +20,12 @@ // limitations under the License. using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; -using System.Resources; using System.Text; using System.Threading.Tasks; using ArchiSteamFarm.Core; @@ -293,58 +291,7 @@ namespace ArchiSteamFarm { ASF.GlobalConfig = globalConfig; - // Skip translation progress for English and invariant (such as "C") cultures - switch (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName) { - case "en": - case "iv": - case "qps": - return true; - } - - // We can't dispose this resource set, as we can't be sure if it isn't used somewhere else, rely on GC in this case - ResourceSet? defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true); - - if (defaultResourceSet == null) { - ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet)); - - return true; - } - - HashSet defaultStringObjects = defaultResourceSet.Cast().ToHashSet(); - - if (defaultStringObjects.Count == 0) { - ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects)); - - return true; - } - - // We can't dispose this resource set, as we can't be sure if it isn't used somewhere else, rely on GC in this case - ResourceSet? currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); - - if (currentResourceSet == null) { - ASF.ArchiLogger.LogNullError(nameof(currentResourceSet)); - - return true; - } - - HashSet currentStringObjects = currentResourceSet.Cast().ToHashSet(); - - if (currentStringObjects.Count >= defaultStringObjects.Count) { - // Either we have 100% finished translation, or we're missing it entirely and using en-US - HashSet testStringObjects = currentStringObjects.ToHashSet(); - testStringObjects.ExceptWith(defaultStringObjects); - - // If we got 0 as final result, this is the missing language - // Otherwise it's just a small amount of strings that happen to be the same - if (testStringObjects.Count == 0) { - currentStringObjects = testStringObjects; - } - } - - if (currentStringObjects.Count < defaultStringObjects.Count) { - float translationCompleteness = currentStringObjects.Count / (float) defaultStringObjects.Count; - ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.TranslationIncomplete, $"{CultureInfo.CurrentUICulture.Name} ({CultureInfo.CurrentUICulture.EnglishName})", translationCompleteness.ToString("P1", CultureInfo.CurrentCulture))); - } + Utilities.WarnAboutIncompleteTranslation(Strings.ResourceManager); return true; }