Skip to content

Commit dfbda6c

Browse files
Format code for consistency
1 parent c5b30b5 commit dfbda6c

File tree

4 files changed

+56
-45
lines changed

4 files changed

+56
-45
lines changed

WinUI3Localizer.SampleApp/App.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Serilog;
66
using System;
77
using System.IO;
8-
using System.Runtime.CompilerServices;
98
using System.Threading.Tasks;
109
using Windows.Storage;
1110

WinUI3Localizer.lutconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<LUTConfig Version="1.0">
2+
<Repository />
3+
<ParallelBuilds>true</ParallelBuilds>
4+
<ParallelTestRuns>true</ParallelTestRuns>
5+
<TestCaseTimeout>180000</TestCaseTimeout>
6+
</LUTConfig>
Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using Microsoft.Windows.ApplicationModel.Resources;
22
using System;
33
using System.Collections.Generic;
4-
using System.Diagnostics.CodeAnalysis;
54
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
85

96
namespace WinUI3Localizer;
7+
108
internal class PriResourceReader
119
{
1210
private readonly ResourceManager resourceManager;
@@ -18,29 +16,30 @@ internal PriResourceReader(ResourceManager resourceManager)
1816

1917
public IEnumerable<LanguageDictionary.Item> GetItems(string language, string subTreeName = "Resources")
2018
{
21-
if (string.IsNullOrEmpty(subTreeName) || subTreeName == "/")
19+
if (string.IsNullOrEmpty(subTreeName) is true ||
20+
subTreeName == "/")
2221
{
2322
subTreeName = "Resources";
2423
}
25-
else if (subTreeName.EndsWith('/'))
24+
else if (subTreeName.EndsWith('/') is true)
2625
{
2726
subTreeName = subTreeName[..^1];
2827
}
2928

3029
ResourceMap resourceMap = this.resourceManager.MainResourceMap.TryGetSubtree(subTreeName);
31-
if (resourceMap != null)
30+
31+
if (resourceMap is not null)
3232
{
3333
ResourceContext resourceContext = this.resourceManager.CreateResourceContext();
3434
resourceContext.QualifierValues[KnownResourceQualifierName.Language] = language;
3535

36-
return GetItemsCore(resourceMap, subTreeName, resourceContext);
36+
return PriResourceReader.GetItemsCore(resourceMap, subTreeName, resourceContext);
3737
}
3838

3939
return Enumerable.Empty<LanguageDictionary.Item>();
4040
}
4141

42-
43-
private IEnumerable<LanguageDictionary.Item> GetItemsCore(ResourceMap resourceMap, string subTreeName, ResourceContext resourceContext)
42+
private static IEnumerable<LanguageDictionary.Item> GetItemsCore(ResourceMap resourceMap, string subTreeName, ResourceContext resourceContext)
4443
{
4544
bool isResourcesSubTree = string.Equals(subTreeName, "Resources", StringComparison.OrdinalIgnoreCase);
4645
uint count = resourceMap.ResourceCount;
@@ -49,49 +48,18 @@ internal PriResourceReader(ResourceManager resourceManager)
4948
{
5049
(string key, ResourceCandidate? candidate) = resourceMap.GetValueByIndex(i, resourceContext);
5150

52-
if (candidate != null && candidate.Kind == ResourceCandidateKind.String)
51+
if (candidate is not null &&
52+
candidate.Kind is ResourceCandidateKind.String)
5353
{
5454
key = key.Replace('/', '.');
55+
5556
if (!isResourcesSubTree)
5657
{
5758
key = $"/{subTreeName}/{key}";
5859
}
59-
yield return LocalizerBuilder.CreateLanguageDictionaryItem(key, candidate.ValueAsString);
60-
}
61-
}
62-
}
63-
64-
}
65-
66-
internal class PriResourceReaderFactory
67-
{
68-
private readonly Dictionary<string, PriResourceReader> readers = new Dictionary<string, PriResourceReader>();
6960

70-
internal PriResourceReader GetPriResourceReader(string? priFile)
71-
{
72-
string? normalizedFilePath = string.Empty;
73-
74-
if (!string.IsNullOrEmpty(priFile))
75-
{
76-
normalizedFilePath = System.IO.Path.GetFullPath(priFile);
77-
}
78-
79-
if (!this.readers.TryGetValue(normalizedFilePath, out PriResourceReader? reader))
80-
{
81-
ResourceManager manager;
82-
if (string.IsNullOrEmpty(normalizedFilePath))
83-
{
84-
manager = new ResourceManager();
85-
}
86-
else
87-
{
88-
manager = new ResourceManager(normalizedFilePath);
61+
yield return LocalizerBuilder.CreateLanguageDictionaryItem(key, candidate.ValueAsString);
8962
}
90-
reader = new PriResourceReader(manager);
91-
this.readers[normalizedFilePath] = reader;
9263
}
93-
94-
return reader;
9564
}
9665
}
97-
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.Windows.ApplicationModel.Resources;
2+
using System.Collections.Generic;
3+
4+
namespace WinUI3Localizer;
5+
6+
internal class PriResourceReaderFactory
7+
{
8+
private readonly Dictionary<string, PriResourceReader> readers = new();
9+
10+
internal PriResourceReader GetPriResourceReader(string? priFile)
11+
{
12+
string normalizedFilePath = string.Empty;
13+
14+
if (string.IsNullOrEmpty(priFile) is false)
15+
{
16+
normalizedFilePath = System.IO.Path.GetFullPath(priFile);
17+
}
18+
19+
if (this.readers.TryGetValue(normalizedFilePath, out PriResourceReader? reader) is false)
20+
{
21+
ResourceManager manager;
22+
23+
if (string.IsNullOrEmpty(normalizedFilePath) is false)
24+
{
25+
manager = new ResourceManager(normalizedFilePath);
26+
}
27+
else
28+
{
29+
manager = new ResourceManager();
30+
}
31+
32+
reader = new PriResourceReader(manager);
33+
this.readers[normalizedFilePath] = reader;
34+
}
35+
36+
return reader;
37+
}
38+
}

0 commit comments

Comments
 (0)