mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-06 01:00:16 +00:00
fix missing fields in translations
This commit is contained in:
parent
7dcca83c85
commit
180bca1804
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace QSB.Localization;
|
namespace QSB.Localization;
|
||||||
|
|
||||||
@ -23,12 +24,16 @@ public static class QSBLocalization
|
|||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
var translation = QSBCore.Helper.Storage.Load<Translation>($"Translations\\{file.Name}", false);
|
var translation = QSBCore.Helper.Storage.Load<Translation>($"Translations\\{file.Name}", false);
|
||||||
|
var filePath = Path.Combine(QSBCore.Helper.Manifest.ModFolderPath, $"Translations\\{file.Name}");
|
||||||
|
|
||||||
if (translation == null)
|
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);
|
_translations.Add(translation);
|
||||||
DebugLog.DebugWrite($"- Added translation for language {translation.Language}");
|
DebugLog.DebugWrite($"- Added translation for language {translation.Language}");
|
||||||
}
|
}
|
||||||
@ -45,6 +50,23 @@ public static class QSBLocalization
|
|||||||
TextTranslation.Get().OnLanguageChanged += OnLanguageChanged;
|
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()
|
private static void OnLanguageChanged()
|
||||||
{
|
{
|
||||||
var language = TextTranslation.Get().GetLanguage();
|
var language = TextTranslation.Get().GetLanguage();
|
||||||
|
Loading…
Reference in New Issue
Block a user