Skip to content

Commit

Permalink
Get translations for resource key added
Browse files Browse the repository at this point in the history
  • Loading branch information
bdongus committed Apr 18, 2024
1 parent a7678cd commit 6c1b481
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 10 deletions.
28 changes: 28 additions & 0 deletions idee5.Globalization.Test/QueryWithSQLiteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using idee5.Globalization.Queries;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -109,5 +110,32 @@ public async Task CanFindResourceSetInResourceKeys() {
// Assert
Assert.AreEqual(4, result.Count);
}

[TestMethod]
public async Task CanGetTranslations() {
// Arrange
var qh = new GetResourceKeyTranslationsQueryHandler(resourceUnitOfWork.ResourceRepository);

// Act
var query = new GetResourceKeyTranslationsQuery() { ResourceSet = Constants.CommonTerms, Id = "Maybe"};
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual(4, result.Translations.Count());
}

[TestMethod]
public async Task GetsEmptyTranslationsForMissingResourceKey() {
// Arrange
var qh = new GetResourceKeyTranslationsQueryHandler(resourceUnitOfWork.ResourceRepository);

// Act
var query = new GetResourceKeyTranslationsQuery() { ResourceSet = "Empty", Id = "Maybe"};
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual("Empty", result.ResourceSet);
Assert.AreEqual(0, result.Translations.Count());
}
}
}
2 changes: 1 addition & 1 deletion idee5.Globalization.Test/idee5.Globalization.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="idee5.Common.Data" version="2.2.0" />
<PackageReference Include="idee5.Common.Data" version="2.3.0" />
<PackageReference Include="MELT" Version="0.9.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion idee5.Globalization.Web/Models/ResourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public string ModelId {
/// </summary>
/// <value>The language item</value>
public LanguageViewModel LanguageItem {
get { return _languageItem != null ? _languageItem : Language == null ? null : new LanguageViewModel(Language, new System.Globalization.CultureInfo(Language).NativeName); }
get { return _languageItem ?? (Language == null ? null : new LanguageViewModel(Language, new System.Globalization.CultureInfo(Language).NativeName)); }
set { _languageItem = value; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using idee5.Globalization.Models;

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;

namespace idee5.Globalization.Commands;
/// <summary>
Expand All @@ -16,7 +14,6 @@ public CreateOrUpdateResourceKeyCommand(ResourceKey original, ImmutableList<Tran

/// <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 17 in idee5.Globalization/Commands/CreateOrUpdateResourceKeyCommand.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 ImmutableList<Translation> Translations { get; set; }

Check warning on line 18 in idee5.Globalization/Commands/CreateOrUpdateResourceKeyCommand.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'
}
16 changes: 16 additions & 0 deletions idee5.Globalization/Models/ResourceTranslations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace idee5.Globalization.Models;
/// <summary>
/// The resource translations
/// </summary>
public record ResourceTranslations : ResourceKey {
public ResourceTranslations(ResourceKey original, Translation[] translations) : base(original) {
Translations = translations ?? throw new ArgumentNullException(nameof(translations));
}

/// <summary>
/// Translations of the <see cref="ResourceKey">.
/// </summary>

Check warning on line 14 in idee5.Globalization/Models/ResourceTranslations.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 Translation[] Translations { get; set; }

Check warning on line 15 in idee5.Globalization/Models/ResourceTranslations.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'
}
3 changes: 2 additions & 1 deletion idee5.Globalization/Queries/GetParlanceResourcesQuery.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using idee5.Common;

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace idee5.Globalization.Queries;
/// <summary>
/// Query parameters for retieval of a parlance resource set
/// Query parameters for retrieval of a parlance resource set
/// </summary>
/// <param name="ResourceSet"> Id of the resource set </param>
/// <param name="LanguageId"> An IETF languageId tag specifying the resource sets languageId </param>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using idee5.Common;
using idee5.Globalization.Models;

namespace idee5.Globalization.Queries;

/// <summary>
/// The get resource key translations query parameters
/// </summary>
public record GetResourceKeyTranslationsQuery() : ResourceKey, IQuery<ResourceTranslations>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using idee5.Common;
using idee5.Globalization.Models;
using idee5.Globalization.Repositories;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace idee5.Globalization.Queries;

/// <summary>
/// The get resource key translations query handler
/// </summary>
public class GetResourceKeyTranslationsQueryHandler : IQueryHandlerAsync<GetResourceKeyTranslationsQuery, ResourceTranslations> {
readonly IResourceQueryRepository _repository;

public GetResourceKeyTranslationsQueryHandler(IResourceQueryRepository repository) {
_repository = repository;
}

/// <inheritdoc/>
public async Task<ResourceTranslations> HandleAsync(GetResourceKeyTranslationsQuery query, CancellationToken cancellationToken = default) {
if (query is null) {
throw new ArgumentNullException(nameof(query));
}
List<Resource> res = await _repository.GetAsync(Specifications.OfResourceKey(query)).ConfigureAwait(false);
Translation[] t = res.Select(r => new Translation(r.Language ?? "", r.Value, r.Comment)).ToArray();
return new(query, t);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using idee5.Common;
using idee5.Globalization.Repositories;

namespace idee5.Globalization.Queries;
/// <summary>
/// The get resource sets by name query handler
/// </summary>
public class GetResourceSetsByNameQueryHandler : IQueryHandlerAsync<GetResourceSetsByNameQuery, IList<string>> {
private readonly IResourceQueryRepository _repository;

Expand Down
6 changes: 3 additions & 3 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.2</Version>
<Version>3.5.3</Version>
<PackageTags>idee5, Globalization, Localization</PackageTags>
<PackageReleaseNotes>Update resource key with comment support</PackageReleaseNotes>
<PackageReleaseNotes>Get translations for resource key added</PackageReleaseNotes>
<Nullable>enable</Nullable>
<Authors>Bernd Dongus</Authors>
<Title>Globalization tool for parlances for industries and customers</Title>
Expand All @@ -42,7 +42,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="idee5.Common" Version="4.0.0" />
<PackageReference Include="idee5.Common.Data" Version="2.2.0" />
<PackageReference Include="idee5.Common.Data" Version="2.3.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 6c1b481

Please sign in to comment.