diff --git a/QSB/Localization/QSBLocalization.cs b/QSB/Localization/QSBLocalization.cs index e275c5f4..ea94b74c 100644 --- a/QSB/Localization/QSBLocalization.cs +++ b/QSB/Localization/QSBLocalization.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; namespace QSB.Localization; @@ -23,12 +24,16 @@ public static class QSBLocalization foreach (var file in files) { var translation = QSBCore.Helper.Storage.Load($"Translations\\{file.Name}", false); + var filePath = Path.Combine(QSBCore.Helper.Manifest.ModFolderPath, $"Translations\\{file.Name}"); if (translation == null) { - DebugLog.ToConsole($"Error - could not load translation at {Path.Combine(QSBCore.Helper.Manifest.ModFolderPath, $"Translations\\{file.Name}")}", MessageType.Error); + DebugLog.ToConsole($"Error - could not load translation at {filePath}", MessageType.Error); + continue; } + FixMissingEntries(translation); + _translations.Add(translation); DebugLog.DebugWrite($"- Added translation for language {translation.Language}"); } @@ -45,6 +50,23 @@ public static class QSBLocalization TextTranslation.Get().OnLanguageChanged += OnLanguageChanged; } + private static void FixMissingEntries(Translation translation) + { + var publicFields = typeof(Translation).GetFields(BindingFlags.Public | BindingFlags.Instance); + + var stringFields = publicFields.Where(x => x.FieldType == typeof(string)); + + foreach (var stringField in stringFields) + { + var value = (string)stringField.GetValue(translation); + if (string.IsNullOrEmpty(value)) + { + DebugLog.DebugWrite($"Warning - Language {translation.Language} has missing field of name {stringField.Name}", MessageType.Warning); + stringField.SetValue(translation, stringField.Name); + } + } + } + private static void OnLanguageChanged() { var language = TextTranslation.Get().GetLanguage();