Skip to content

Commit

Permalink
NumLanguage bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Jan 14, 2024
1 parent 254a02d commit e31caf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Mutagen.Bethesda.Core.UnitTests/Strings/TranslatedStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ public override TranslatedString Create(params KeyValuePair<Language, string>[]
[Collection("TranslatedString")]
public class TranslatedString_ByLookup : ATranslatedStringTests
{
[Fact]
public void NumLanguagesReturnsMany()
{
TranslatedString.DefaultLanguage = Language.English;
ITranslatedString str = Create(
new KeyValuePair<Language, string>(Language.English, EnglishString),
new KeyValuePair<Language, string>(Language.French, FrenchString));
str.NumLanguages.Should().Be(2);
}

public class ManualStringsLookup : IStringsFolderLookup
{
private readonly StringsSource _source;
Expand Down
11 changes: 9 additions & 2 deletions Mutagen.Bethesda.Core/Strings/TranslatedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ public string? String
set => Set(TargetLanguage, value);
}

public int NumLanguages => _localization?.Count ?? 1;
public int NumLanguages
{
get
{
ResolveAllStringSources();
return _localization?.Count ?? 1;
}
}

private static TranslatedString _empty = new(Language.English, string.Empty);
public static ITranslatedStringGetter Empty => _empty;
Expand Down Expand Up @@ -273,7 +280,7 @@ internal void ResolveAllStringSources()
}
else
{
_localization[lang] = null;
_localization.Remove(lang);
}
}
StringsLookup = null;
Expand Down

0 comments on commit e31caf0

Please sign in to comment.