Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed May 20, 2024
1 parent 47b1b39 commit 33cb482
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/Lepo.i18n/LocalizationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,16 @@ CultureInfo culture
CultureInfo culture
)
{
CultureInfo cultureToRestore = Thread.CurrentThread.CurrentCulture;

Check failure on line 159 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

Check failure on line 159 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

Check failure on line 159 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

// NOTE: Fix net framework satellite assembly loading
try
{
// NOTE: Fix net framework satellite assembly loading
Thread.CurrentThread.CurrentCulture = culture;

Check failure on line 164 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

Check failure on line 164 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

Check failure on line 164 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context
Thread.CurrentThread.CurrentUICulture = culture;

Check failure on line 165 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

Check failure on line 165 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

ResourceManager resourceManager = new(baseName, assembly);

ResourceSet? resourceSet = resourceManager.GetResourceSet(culture, true, true);

if (resourceSet is null)
Expand All @@ -175,11 +180,17 @@ CultureInfo culture

builder.AddLocalization(new LocalizationSet(baseName, culture, localizations));

Thread.CurrentThread.CurrentCulture = cultureToRestore;

Check failure on line 183 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context
Thread.CurrentThread.CurrentUICulture = cultureToRestore;

Check failure on line 184 in src/Lepo.i18n/LocalizationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / deploy

The name 'Thread' does not exist in the current context

return builder;
}
catch (MissingManifestResourceException ex)
{
throw new LocalizationBuilderException("Failed to register translation resources.", ex);
throw new LocalizationBuilderException(
$"Failed to register translation resources for \"{culture}\".",
ex
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

global using System;
global using System.Collections.Generic;
global using System.Globalization;
global using System.Reflection;
global using FluentAssertions;
global using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<IsTrimmable>false</IsTrimmable>
</PropertyGroup>


<ItemGroup>
<None Remove="Resources\Translations-pl-PL.yaml" />
<None Remove="Resources\Translations-en-US.yaml" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Translations-pl-PL.yaml" />
<EmbeddedResource Include="Resources\Translations-en-US.yaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

namespace Lepo.i18n.DependencyInjection.UnitTests.Resources;

public class Test;
public partial class Test;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Comment
Test: 'Test in english'
main.languages: Languages
main.hello: "Hello world"

namespace.test:
main.languages: Languages in namespace.test #yet another comment
main.hello: 'Hello world in namespace.test'

# Some comment
other.namespace:
main.languages: Languages in other.namespace #yet another comment
main.hello: 'Hello world in other.namespace'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Comment
Test: 'Test po polsku'
main.languages: Języki
main.hello: "Witaj świecie"

namespace.test:
main.languages: Języki w namespace.test #yet another comment
main.hello: 'Witaj świecie w namespace.test'

# Some comment
other.namespace:
main.languages: Języki w other.namespace #yet another comment
main.hello: 'Witaj świecie w other.namespace'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors.
// All Rights Reserved.

using Lepo.i18n.DependencyInjection.UnitTests.Resources;
using Lepo.i18n.Yaml;

namespace Lepo.i18n.DependencyInjection.UnitTests;

Expand All @@ -18,8 +18,14 @@ public void FromResource_ShouldAddLocalizations_WhenResourceSetIsNotNull()

_ = services.AddStringLocalizer(b =>
{
_ = b.FromResource<Test>("pl-PL");
_ = b.FromResource<Test>("en-US");
_ = b.FromYaml(
"Lepo.i18n.DependencyInjection.UnitTests.Resources.Translations-pl-PL.yaml",
new CultureInfo("pl-PL")
);
_ = b.FromYaml(
"Lepo.i18n.DependencyInjection.UnitTests.Resources.Translations-en-US.yaml",
new CultureInfo("en-US")
);
});

ServiceProvider serviceProvider = services.BuildServiceProvider();
Expand Down

0 comments on commit 33cb482

Please sign in to comment.