Skip to content

Commit

Permalink
Support language packs with duplicated entries
Browse files Browse the repository at this point in the history
  • Loading branch information
JungleDruid committed Nov 25, 2024
1 parent 36849e5 commit 9e06ba0
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 26 deletions.
2 changes: 1 addition & 1 deletion BG3LocalizationMerger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<NeutralLanguage>en</NeutralLanguage>
<Version>$(VersionPrefix)1.1.0.1</Version>
<Version>$(VersionPrefix)1.1.1.0</Version>
<SignAssembly>False</SignAssembly>
</PropertyGroup>

Expand Down
137 changes: 112 additions & 25 deletions PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,18 +773,63 @@ ref IEnumerable<string> parent
.Concat(lineSet)
.ToHashSet();

var refDict = locas.RefDoc
.Element("contentList")!
.Elements("content")
.Select(x => (x.Attribute("contentuid")!.Value, x.Value))
.Where(x => combined.Contains(x.Item1))
.ToDictionary(x => x.Item1, x => x.Item2);
var dict = locas.Doc
.Element("contentList")!
.Elements("content")
.Select(x => (x, x.Attribute("contentuid")!.Value))
.Where(x => refDict.ContainsKey(x.Value))
.ToDictionary(x => x.Value, x => x.x);
Dictionary<string, string> refDict;
try
{
refDict = locas.RefDoc
.Element("contentList")!
.Elements("content")
.Select(x => (x.Attribute("contentuid")!.Value, x.Value))
.Where(x => combined.Contains(x.Item1))
.ToDictionary(x => x.Item1, x => x.Item2);
}
catch (ArgumentException)
{
var array = locas.RefDoc
.Element("contentList")!
.Elements("content")
.Select(x => (x.Attribute("contentuid")!.Value, x.Value))
.Where(x => combined.Contains(x.Item1))
.ToArray();
refDict = [];
foreach (var item in array)
{
if (!refDict.TryAdd(item.Item1, item.Item2))
{
refDict[item.Item1] = item.Item2;
MainWindow.LogError($"Duplicated Reference Language Pack Key found: {item.Item1}.");
}
}
}

Dictionary<string, XElement> dict;
try
{
dict = locas.Doc
.Element("contentList")!
.Elements("content")
.Select(x => (x, x.Attribute("contentuid")!.Value))
.Where(x => refDict.ContainsKey(x.Value))
.ToDictionary(x => x.Value, x => x.x);
}
catch (ArgumentException)
{
var array = locas.Doc
.Element("contentList")!
.Elements("content")
.Select(x => (x, x.Attribute("contentuid")!.Value))
.Where(x => refDict.ContainsKey(x.Value))
.ToArray();
dict = [];
foreach (var item in array)
{
if (!dict.TryAdd(item.Value, item.x))
{
dict[item.Value] = item.x;
MainWindow.LogError($"Duplicated Language Pack Key found: {item.Value}.");
}
}
}

MainWindow.Log(string.Format(Strings.TotalStringMessage, combined.Count, dict.Count));

Expand Down Expand Up @@ -853,19 +898,61 @@ public async Task MergeUnconditionally(CancellationToken cancellationToken)
Locas locas = new(cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
MainWindow.Log(Strings.MergingUnconditionallyMessage);
var refDict = locas.RefDoc
.Element("contentList")!
.Elements("content")
.Select(x => (x.Attribute("contentuid")!.Value, x.Value))
.ToDictionary(x => x.Item1, x => x.Item2);
cancellationToken.ThrowIfCancellationRequested();
var dict = locas.Doc
.Element("contentList")!
.Elements("content")
.Select(x => (x, x.Attribute("contentuid")!.Value))
.Where(x => refDict.ContainsKey(x.Value))
.ToDictionary(x => x.Value, x => x.x);
cancellationToken.ThrowIfCancellationRequested();
Dictionary<string, string> refDict;
try
{
refDict = locas.RefDoc
.Element("contentList")!
.Elements("content")
.Select(x => (x.Attribute("contentuid")!.Value, x.Value))
.ToDictionary(x => x.Item1, x => x.Item2);
}
catch (ArgumentException)
{
var array = locas.RefDoc
.Element("contentList")!
.Elements("content")
.Select(x => (x.Attribute("contentuid")!.Value, x.Value))
.ToArray();
refDict = [];
foreach (var item in array)
{
if (!refDict.TryAdd(item.Item1, item.Item2))
{
refDict[item.Item1] = item.Item2;
MainWindow.LogError($"Duplicated Reference Language Pack Key found: {item.Item1}.");
}
}
}

Dictionary<string, XElement> dict;
try
{
dict = locas.Doc
.Element("contentList")!
.Elements("content")
.Select(x => (x, x.Attribute("contentuid")!.Value))
.Where(x => refDict.ContainsKey(x.Value))
.ToDictionary(x => x.Value, x => x.x);
}
catch (ArgumentException)
{
var array = locas.Doc
.Element("contentList")!
.Elements("content")
.Select(x => (x, x.Attribute("contentuid")!.Value))
.Where(x => refDict.ContainsKey(x.Value))
.ToArray();
dict = [];
foreach (var item in array)
{
if (!dict.TryAdd(item.Value, item.x))
{
dict[item.Value] = item.x;
MainWindow.LogError($"Duplicated Language Pack Key found: {item.Value}.");
}
}
}

Parallel.ForEach(
dict,
Expand Down

0 comments on commit 9e06ba0

Please sign in to comment.