Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 1, 2024
1 parent 95de986 commit 8c60091
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
29 changes: 29 additions & 0 deletions starsky/starsky.feature.language/CustomCultureComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace starsky.feature.language;

public class CustomCultureComparer : IComparer<string>
{
private readonly List<string> _customOrder;

public CustomCultureComparer(List<string> customOrder)
{
_customOrder = customOrder;
}

public int Compare(string? x, string? y)
{
var indexX = _customOrder.IndexOf(x);
var indexY = _customOrder.IndexOf(y);

if ( indexX == -1 )
{
indexX = int.MaxValue;
}

if ( indexY == -1 )
{
indexY = int.MaxValue;
}

return indexX.CompareTo(indexY);
}
}
12 changes: 6 additions & 6 deletions starsky/starsky.feature.language/ResourceFileToJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public Class1()
var properties =
typeof(LanguageContent).GetProperties(BindingFlags.Static | BindingFlags.NonPublic);
var cultures = GetAllCultures.CulturesOfResource<LanguageContent>()
.OrderBy(p => p.Name);
.Select(p => p.Name)
.Order(new CustomCultureComparer(["en", "nl", "de"])).ToList();

var translations = new Dictionary<string, Dictionary<string, string>>();

foreach ( var property in properties )
Expand All @@ -23,13 +25,11 @@ public Class1()

var propertyTranslations = new Dictionary<string, string>();

foreach ( var culture in cultures )
foreach ( var cultureName in cultures )
{
LanguageContent.Culture = new CultureInfo(culture.Name);
LanguageContent.Culture = new CultureInfo(cultureName);
var value = property.GetValue(null) as string;
propertyTranslations[culture.Name] = value;

// Console.WriteLine($"{property.Name} ({culture}): {value}");
propertyTranslations[cultureName] = value;
}

translations[property.Name] = propertyTranslations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PackageTelemetryBackgroundServiceTest()
services.AddSingleton<IQuery, FakeIQuery>();
services.AddSingleton<IDeviceIdService, FakeIDeviceIdService>();

var serviceProvider = services.BuildServiceProvider();
var serviceProvider =
_serviceScopeFactory = serviceProvider.GetRequiredService<IServiceScopeFactory>();

var appSettings = serviceProvider.GetRequiredService<AppSettings>();
Expand Down

0 comments on commit 8c60091

Please sign in to comment.