diff --git a/WinUI3Localizer.SampleApp/App.xaml.cs b/WinUI3Localizer.SampleApp/App.xaml.cs
index c8a5550..0cdc8da 100644
--- a/WinUI3Localizer.SampleApp/App.xaml.cs
+++ b/WinUI3Localizer.SampleApp/App.xaml.cs
@@ -5,7 +5,6 @@
using Serilog;
using System;
using System.IO;
-using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Windows.Storage;
diff --git a/WinUI3Localizer.lutconfig b/WinUI3Localizer.lutconfig
new file mode 100644
index 0000000..596a860
--- /dev/null
+++ b/WinUI3Localizer.lutconfig
@@ -0,0 +1,6 @@
+
+
+ true
+ true
+ 180000
+
\ No newline at end of file
diff --git a/WinUI3Localizer/PriResourceReader.cs b/WinUI3Localizer/PriResourceReader.cs
index 3d6b8eb..45d20aa 100644
--- a/WinUI3Localizer/PriResourceReader.cs
+++ b/WinUI3Localizer/PriResourceReader.cs
@@ -1,12 +1,10 @@
using Microsoft.Windows.ApplicationModel.Resources;
using System;
using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace WinUI3Localizer;
+
internal class PriResourceReader
{
private readonly ResourceManager resourceManager;
@@ -18,29 +16,30 @@ internal PriResourceReader(ResourceManager resourceManager)
public IEnumerable GetItems(string language, string subTreeName = "Resources")
{
- if (string.IsNullOrEmpty(subTreeName) || subTreeName == "/")
+ if (string.IsNullOrEmpty(subTreeName) is true ||
+ subTreeName == "/")
{
subTreeName = "Resources";
}
- else if (subTreeName.EndsWith('/'))
+ else if (subTreeName.EndsWith('/') is true)
{
subTreeName = subTreeName[..^1];
}
ResourceMap resourceMap = this.resourceManager.MainResourceMap.TryGetSubtree(subTreeName);
- if (resourceMap != null)
+
+ if (resourceMap is not null)
{
ResourceContext resourceContext = this.resourceManager.CreateResourceContext();
resourceContext.QualifierValues[KnownResourceQualifierName.Language] = language;
- return GetItemsCore(resourceMap, subTreeName, resourceContext);
+ return PriResourceReader.GetItemsCore(resourceMap, subTreeName, resourceContext);
}
return Enumerable.Empty();
}
-
- private IEnumerable GetItemsCore(ResourceMap resourceMap, string subTreeName, ResourceContext resourceContext)
+ private static IEnumerable GetItemsCore(ResourceMap resourceMap, string subTreeName, ResourceContext resourceContext)
{
bool isResourcesSubTree = string.Equals(subTreeName, "Resources", StringComparison.OrdinalIgnoreCase);
uint count = resourceMap.ResourceCount;
@@ -49,49 +48,18 @@ internal PriResourceReader(ResourceManager resourceManager)
{
(string key, ResourceCandidate? candidate) = resourceMap.GetValueByIndex(i, resourceContext);
- if (candidate != null && candidate.Kind == ResourceCandidateKind.String)
+ if (candidate is not null &&
+ candidate.Kind is ResourceCandidateKind.String)
{
key = key.Replace('/', '.');
+
if (!isResourcesSubTree)
{
key = $"/{subTreeName}/{key}";
}
- yield return LocalizerBuilder.CreateLanguageDictionaryItem(key, candidate.ValueAsString);
- }
- }
- }
-
-}
-
-internal class PriResourceReaderFactory
-{
- private readonly Dictionary readers = new Dictionary();
- internal PriResourceReader GetPriResourceReader(string? priFile)
- {
- string? normalizedFilePath = string.Empty;
-
- if (!string.IsNullOrEmpty(priFile))
- {
- normalizedFilePath = System.IO.Path.GetFullPath(priFile);
- }
-
- if (!this.readers.TryGetValue(normalizedFilePath, out PriResourceReader? reader))
- {
- ResourceManager manager;
- if (string.IsNullOrEmpty(normalizedFilePath))
- {
- manager = new ResourceManager();
- }
- else
- {
- manager = new ResourceManager(normalizedFilePath);
+ yield return LocalizerBuilder.CreateLanguageDictionaryItem(key, candidate.ValueAsString);
}
- reader = new PriResourceReader(manager);
- this.readers[normalizedFilePath] = reader;
}
-
- return reader;
}
}
-
diff --git a/WinUI3Localizer/PriResourceReaderFactory.cs b/WinUI3Localizer/PriResourceReaderFactory.cs
new file mode 100644
index 0000000..fd390fb
--- /dev/null
+++ b/WinUI3Localizer/PriResourceReaderFactory.cs
@@ -0,0 +1,38 @@
+using Microsoft.Windows.ApplicationModel.Resources;
+using System.Collections.Generic;
+
+namespace WinUI3Localizer;
+
+internal class PriResourceReaderFactory
+{
+ private readonly Dictionary readers = new();
+
+ internal PriResourceReader GetPriResourceReader(string? priFile)
+ {
+ string normalizedFilePath = string.Empty;
+
+ if (string.IsNullOrEmpty(priFile) is false)
+ {
+ normalizedFilePath = System.IO.Path.GetFullPath(priFile);
+ }
+
+ if (this.readers.TryGetValue(normalizedFilePath, out PriResourceReader? reader) is false)
+ {
+ ResourceManager manager;
+
+ if (string.IsNullOrEmpty(normalizedFilePath) is false)
+ {
+ manager = new ResourceManager(normalizedFilePath);
+ }
+ else
+ {
+ manager = new ResourceManager();
+ }
+
+ reader = new PriResourceReader(manager);
+ this.readers[normalizedFilePath] = reader;
+ }
+
+ return reader;
+ }
+}
diff --git a/WinUI3Localizer/WinUI3Localizer.csproj b/WinUI3Localizer/WinUI3Localizer.csproj
index ea833d1..9f79113 100644
--- a/WinUI3Localizer/WinUI3Localizer.csproj
+++ b/WinUI3Localizer/WinUI3Localizer.csproj
@@ -17,7 +17,7 @@
- You/users can add new languages even after deployment
- Use standard Resources.resw
- 2.1.0
+ 2.2.0
winui3;winappsdk;localization;localize;language;multilanguage
https://github.com/AndrewKeepCoding/WinUI3Localizer
https://github.com/AndrewKeepCoding/WinUI3Localizer
@@ -27,7 +27,7 @@
snupkg
WinUI3Localizer
WinUI3Localizer
- Copyright (c) Andrew KeepCoding 2023
+ Copyright (c) Andrew KeepCoding 2024
Andrew KeepCoding
README.md
winui.png