Skip to content

Commit

Permalink
3.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bdongus committed Apr 10, 2024
1 parent 209c576 commit 7ce2987
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
16 changes: 6 additions & 10 deletions idee5.Globalization.Test/UpdateResourceKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public async Task CanCreateUpdateAndDeleteTranslation() {
// Arrange
var handler = new UpdateResourceKeyCommandHandler(resourceUnitOfWork, new NullLogger<UpdateResourceKeyCommandHandler>());
var rk = new ResourceKey() { ResourceSet = _resourceSet, Id ="DeRemove" };
var translations = new Dictionary<string, string> {
{ "en-GB", "lsmf" },
{ "it", "xyz" }
};
var command = new UpdateResourceKeyCommand(rk, translations.ToImmutableDictionary());

var translations = ImmutableList.Create(new Translation("en-GB", "lsmf"), new Translation("it", "xyz", "abc"));
var command = new UpdateResourceKeyCommand(rk, translations);

// Act
await handler.HandleAsync(command, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -49,6 +47,7 @@ public async Task CanCreateUpdateAndDeleteTranslation() {
Assert.AreEqual(2, rsc.Count);
Assert.AreEqual("lsmf", rsc.SingleOrDefault(r => r.Language == "en-GB")?.Value);
Assert.AreEqual("xyz", rsc.SingleOrDefault(r => r.Language == "it")?.Value);
Assert.AreEqual("abc", rsc.SingleOrDefault(r => r.Language == "it")?.Comment);
}

[TestMethod]
Expand All @@ -58,11 +57,8 @@ public async Task CanCreateLogs() {
var logger = loggerFactory.CreateLogger<UpdateResourceKeyCommandHandler>();
var handler = new UpdateResourceKeyCommandHandler(resourceUnitOfWork, logger);
var rk = new ResourceKey() { ResourceSet = _resourceSet, Id ="LogTest" };
var translations = new Dictionary<string, string> {
{ "en-GB", "lsmf" },
{ "it", "xyz" }
};
var command = new UpdateResourceKeyCommand(rk, translations.ToImmutableDictionary());
var translations = ImmutableList.Create(new Translation("en-GB", "lsmf"), new Translation("it", "xyz"));
var command = new UpdateResourceKeyCommand(rk, translations);

// Act
await handler.HandleAsync(command, CancellationToken.None).ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions idee5.Globalization/Commands/UpdateResourceKeyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace idee5.Globalization.Commands;
/// The update resource key command
/// </summary>
public record UpdateResourceKeyCommand : ResourceKey {
public UpdateResourceKeyCommand(ResourceKey original, ImmutableDictionary<string, string> translations) : base(original) {
public UpdateResourceKeyCommand(ResourceKey original, ImmutableList<Translation> translations) : base(original) {

Check warning on line 13 in idee5.Globalization/Commands/UpdateResourceKeyCommand.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'UpdateResourceKeyCommand.UpdateResourceKeyCommand(ResourceKey, ImmutableList<Translation>)'
Translations = translations ?? throw new ArgumentNullException(nameof(translations));
}

/// <summary>
/// Translations of the <see cref="ResourceKey">.
/// The dictionary key is the <see cref="Resource.Language"/>, the value is the <see cref="Resource.Value"/>
/// </summary>

Check warning on line 20 in idee5.Globalization/Commands/UpdateResourceKeyCommand.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'see'.'
public ImmutableDictionary<string, string> Translations { get; set; }
public ImmutableList<Translation> Translations { get; set; }

Check warning on line 21 in idee5.Globalization/Commands/UpdateResourceKeyCommand.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public async Task HandleAsync(UpdateResourceKeyCommand command, CancellationToke
};
// first remove all missing translations
_logger.RemovingTranslations();
await _unitOfWork.ResourceRepository.RemoveAsync(Specifications.OfResourceKey(baseResource) & !Specifications.TranslatedTo(command.Translations.Keys), cancellationToken).ConfigureAwait(false);
await _unitOfWork.ResourceRepository.RemoveAsync(Specifications.OfResourceKey(baseResource) & !Specifications.TranslatedTo(command.Translations.Select(t => t.Language)), cancellationToken).ConfigureAwait(false);

// then update or add the given translations
foreach (var translation in command.Translations) {
Resource rsc = baseResource with { Language = translation.Key, Value = translation.Value };
Resource rsc = baseResource with { Language = translation.Language, Value = translation.Value, Comment = translation.Comment };
_logger.CreateOrUpdateResource(rsc);
await _unitOfWork.ResourceRepository.UpdateOrAddAsync(rsc, cancellationToken).ConfigureAwait(false);
}
Expand Down
9 changes: 9 additions & 0 deletions idee5.Globalization/Models/Translation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace idee5.Globalization.Models;

/// <summary>
/// The translation
/// </summary>
/// <param name="Language">Language id according to BCP 47 http://tools.ietf.org/html/bcp47</param>
/// <param name="Value">Value of the resource for the specified culture and parlance</param>
/// <param name="Comment">Additional information. Mostly used to create semantic context to simplify translations</param>
public record Translation(string Language, string Value, string? Comment = null);
4 changes: 2 additions & 2 deletions idee5.Globalization/idee5.Globalization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<Description>Globalization extensions. Enables database support for localization resources and parlances for industries and customers..</Description>
<Company>idee5</Company>
<Copyright>© idee5 2016 - 2024</Copyright>
<Version>3.5.0</Version>
<Version>3.5.1</Version>
<PackageTags>idee5, Globalization, Localization</PackageTags>
<PackageReleaseNotes>Update resource key added</PackageReleaseNotes>
<PackageReleaseNotes>Update resource key with comment support</PackageReleaseNotes>
<Nullable>enable</Nullable>
<Authors>Bernd Dongus</Authors>
<Title>Globalization tool for parlances for industries and customers</Title>
Expand Down

0 comments on commit 7ce2987

Please sign in to comment.