Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localized text defaults to English on null, modinfo name defaults to … #244

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions ModManager_Classes/Models/ModMetadata/LocalizedModinfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@ public LocalizedModinfoFactory(
_textManager = textManager;
}

public LocalizedModinfo GetLocalizedModinfo(Modinfo m)
public LocalizedModinfo GetLocalizedModinfo(Modinfo m, string folderName)
{
var localized = new LocalizedModinfo()
var localized = new LocalizedModinfo
{
Category = m.Category is not null ? _textManager.CreateLocalizedText(m.Category) : new SimpleText(""),
ModName = m.ModName is not null ? _textManager.CreateLocalizedText(m.ModName) : new SimpleText(""),
Description = m?.Description is not null ? _textManager.CreateLocalizedText(m.Description) : null,
KnownIssues = m?.KnownIssues is not null ? m.KnownIssues?.Where(x => x is not null).Select(x => _textManager.CreateLocalizedText(x)).ToArray() : null
Category = _textManager.CreateLocalizedText(m.Category, ""),
ModName = _textManager.CreateLocalizedText(m.ModName, folderName),
Description = _textManager.CreateLocalizedText(m.Description, null),
KnownIssues = m.KnownIssues?.Select(x => _textManager.CreateLocalizedText(x, null)).OfType<IText>().ToArray(),
Version = m.Version,
ModID = m.ModID,
IncompatibleIds = m.IncompatibleIds,
DeprecateIds = m.DeprecateIds,
ModDependencies = m.ModDependencies,
DLCDependencies = m.DLCDependencies,
CreatorName = m.CreatorName,
CreatorContact = m.CreatorContact,
Image = m.Image,
LoadAfterIds = m.LoadAfterIds
};

localized.Version = m?.Version;
localized.ModID = m?.ModID;
localized.IncompatibleIds = m?.IncompatibleIds;
localized.DeprecateIds = m?.DeprecateIds;
localized.ModDependencies = m?.ModDependencies;
localized.DLCDependencies = m?.DLCDependencies;
localized.CreatorName = m?.CreatorName;
localized.CreatorContact = m?.CreatorContact;
localized.Image = m?.Image;
localized.LoadAfterIds = m?.LoadAfterIds;

return localized;
}

Expand Down
2 changes: 1 addition & 1 deletion ModManager_Classes/Models/Mods/ModFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ModFactory(
bool hasModinfo = ModinfoLoader.TryLoadFromFile(Path.Combine(modFolderPath, "modinfo.json"), out var modinfo);

var localizedModinfo = hasModinfo ?
_localizedModinfoFactory.GetLocalizedModinfo(modinfo!)
_localizedModinfoFactory.GetLocalizedModinfo(modinfo!, folderName)
: _localizedModinfoFactory.GetDummyModinfo(folderName);

var mod = new Mod(
Expand Down
2 changes: 1 addition & 1 deletion ModManager_Classes/Texts/ITextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public interface ITextManager
void ChangeLanguage(ApplicationLanguage lang);
void UpdateTexts();
void LoadLanguageFile(String Sourcefile);
LocalizedText CreateLocalizedText(Localized localized);
LocalizedText CreateLocalizedText(Localized? localized, string? defaultText);
}
}
31 changes: 17 additions & 14 deletions ModManager_Classes/Texts/TextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,24 @@ public void LoadLanguageFile(String Sourcefile)

}

public LocalizedText CreateLocalizedText(Localized localized)
public LocalizedText CreateLocalizedText(Localized? localized, string? defaultText)
{
var newText = new LocalizedText();

if (localized.Chinese is String) newText.Chinese = localized.Chinese;
if (localized.English is String) newText.English = localized.English;
if (localized.French is String) newText.French = localized.French;
if (localized.German is String) newText.German = localized.German;
if (localized.Italian is String) newText.Italian = localized.Italian;
if (localized.Japanese is String) newText.Japanese = localized.Japanese;
if (localized.Korean is String) newText.Korean = localized.Korean;
if (localized.Polish is String) newText.Polish = localized.Polish;
if (localized.Russian is String) newText.Russian = localized.Russian;
if (localized.Spanish is String) newText.Spanish = localized.Spanish;
if (localized.Taiwanese is String) newText.Taiwanese = localized.Taiwanese;
string? english = localized?.English ?? defaultText;

var newText = new LocalizedText
{
Chinese = localized?.Chinese ?? english,
English = english,
French = localized?.French ?? english,
German = localized?.German ?? english,
Italian = localized?.Italian ?? english,
Japanese = localized?.Japanese ?? english,
Korean = localized?.Korean ?? english,
Polish = localized?.Polish ?? english,
Russian = localized?.Russian ?? english,
Spanish = localized?.Spanish ?? english,
Taiwanese = localized?.Taiwanese ?? english
};

newText.Update(ApplicationLanguage);
AddAnonymousText(newText);
Expand Down