diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 5c31f5f42..599b36bf8 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -23,6 +23,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -235,36 +236,45 @@ namespace ArchiSteamFarm { } } - ushort defaultResourceSetCount = 0; - ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true); - if (defaultResourceSet != null) { - defaultResourceSetCount = (ushort) defaultResourceSet.Cast().Count(); - } - - if (defaultResourceSetCount == 0) { + if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("en")) { return; } - ushort currentResourceSetCount = 0; - ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false); - if (currentResourceSet != null) { - currentResourceSetCount = (ushort) currentResourceSet.Cast().Count(); + ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true); + if (defaultResourceSet == null) { + ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet)); + return; } - if (currentResourceSetCount < defaultResourceSetCount) { - // We don't want to report "en-AU" as 0.00% only because we don't have it as a dialect, if "en" is available and translated - // This typically will work only for English, as e.g. "nl-BE" doesn't fallback to "nl-NL", but "nl", and "nl" will be empty - ushort neutralResourceSetCount = 0; - ResourceSet neutralResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture.Parent, true, false); - if (neutralResourceSet != null) { - neutralResourceSetCount = (ushort) neutralResourceSet.Cast().Count(); - } + HashSet defaultStringObjects = new HashSet(defaultResourceSet.Cast()); + if (defaultStringObjects.Count == 0) { + ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects)); + return; + } - if (neutralResourceSetCount < defaultResourceSetCount) { - float translationCompleteness = currentResourceSetCount / (float) defaultResourceSetCount; - ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1"))); + ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true); + if (currentResourceSet == null) { + ASF.ArchiLogger.LogNullError(nameof(currentResourceSet)); + return; + } + + HashSet currentStringObjects = new HashSet(currentResourceSet.Cast()); + if (currentStringObjects.Count >= defaultStringObjects.Count) { + // Either we have 100% finished translation, or we're missing it entirely and using en-US + HashSet testStringObjects = new HashSet(currentStringObjects); + 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(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1"))); + } } private static async Task InitGlobalDatabaseAndServices() { diff --git a/GUI/Program.cs b/GUI/Program.cs index eb7f409b7..79c5fe342 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -141,36 +142,45 @@ namespace ArchiSteamFarm { } } - ushort defaultResourceSetCount = 0; - ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true); - if (defaultResourceSet != null) { - defaultResourceSetCount = (ushort) defaultResourceSet.Cast().Count(); - } - - if (defaultResourceSetCount == 0) { + if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("en")) { return; } - ushort currentResourceSetCount = 0; - ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false); - if (currentResourceSet != null) { - currentResourceSetCount = (ushort) currentResourceSet.Cast().Count(); + ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true); + if (defaultResourceSet == null) { + ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet)); + return; } - if (currentResourceSetCount < defaultResourceSetCount) { - // We don't want to report "en-AU" as 0.00% only because we don't have it as a dialect, if "en" is available and translated - // This typically will work only for English, as e.g. "nl-BE" doesn't fallback to "nl-NL", but "nl", and "nl" will be empty - ushort neutralResourceSetCount = 0; - ResourceSet neutralResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture.Parent, true, false); - if (neutralResourceSet != null) { - neutralResourceSetCount = (ushort) neutralResourceSet.Cast().Count(); - } + HashSet defaultStringObjects = new HashSet(defaultResourceSet.Cast()); + if (defaultStringObjects.Count == 0) { + ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects)); + return; + } - if (neutralResourceSetCount < defaultResourceSetCount) { - float translationCompleteness = currentResourceSetCount / (float) defaultResourceSetCount; - ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1"))); + ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true); + if (currentResourceSet == null) { + ASF.ArchiLogger.LogNullError(nameof(currentResourceSet)); + return; + } + + HashSet currentStringObjects = new HashSet(currentResourceSet.Cast()); + if (currentStringObjects.Count >= defaultStringObjects.Count) { + // Either we have 100% finished translation, or we're missing it entirely and using en-US + HashSet testStringObjects = new HashSet(currentStringObjects); + 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(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1"))); + } } private static async Task InitGlobalDatabaseAndServices() {