diff --git a/idee5.Globalization.Test/QueryWithSQLiteTests.cs b/idee5.Globalization.Test/QueryWithSQLiteTests.cs
index 7912051..5bf2a25 100644
--- a/idee5.Globalization.Test/QueryWithSQLiteTests.cs
+++ b/idee5.Globalization.Test/QueryWithSQLiteTests.cs
@@ -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;
@@ -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());
+ }
}
}
\ No newline at end of file
diff --git a/idee5.Globalization.Test/idee5.Globalization.Test.csproj b/idee5.Globalization.Test/idee5.Globalization.Test.csproj
index ceb02b1..0b392d9 100644
--- a/idee5.Globalization.Test/idee5.Globalization.Test.csproj
+++ b/idee5.Globalization.Test/idee5.Globalization.Test.csproj
@@ -29,7 +29,7 @@
-
+
diff --git a/idee5.Globalization.Web/Models/ResourceViewModel.cs b/idee5.Globalization.Web/Models/ResourceViewModel.cs
index 69c27d4..43605b9 100644
--- a/idee5.Globalization.Web/Models/ResourceViewModel.cs
+++ b/idee5.Globalization.Web/Models/ResourceViewModel.cs
@@ -20,7 +20,7 @@ public string ModelId {
///
/// The language item
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; }
}
diff --git a/idee5.Globalization/Commands/CreateOrUpdateResourceKeyCommand.cs b/idee5.Globalization/Commands/CreateOrUpdateResourceKeyCommand.cs
index 05c594c..32b47d7 100644
--- a/idee5.Globalization/Commands/CreateOrUpdateResourceKeyCommand.cs
+++ b/idee5.Globalization/Commands/CreateOrUpdateResourceKeyCommand.cs
@@ -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;
///
@@ -16,7 +14,6 @@ public CreateOrUpdateResourceKeyCommand(ResourceKey original, ImmutableList
/// Translations of the .
- /// The dictionary key is the , the value is the
///
public ImmutableList Translations { get; set; }
}
diff --git a/idee5.Globalization/Models/ResourceTranslations.cs b/idee5.Globalization/Models/ResourceTranslations.cs
new file mode 100644
index 0000000..f93123b
--- /dev/null
+++ b/idee5.Globalization/Models/ResourceTranslations.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace idee5.Globalization.Models;
+///
+/// The resource translations
+///
+public record ResourceTranslations : ResourceKey {
+ public ResourceTranslations(ResourceKey original, Translation[] translations) : base(original) {
+ Translations = translations ?? throw new ArgumentNullException(nameof(translations));
+ }
+
+ ///
+ /// Translations of the .
+ ///
+ public Translation[] Translations { get; set; }
+}
diff --git a/idee5.Globalization/Queries/GetParlanceResourcesQuery.cs b/idee5.Globalization/Queries/GetParlanceResourcesQuery.cs
index 9a26678..69c4083 100644
--- a/idee5.Globalization/Queries/GetParlanceResourcesQuery.cs
+++ b/idee5.Globalization/Queries/GetParlanceResourcesQuery.cs
@@ -1,10 +1,11 @@
using idee5.Common;
+
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace idee5.Globalization.Queries;
///
-/// Query parameters for retieval of a parlance resource set
+/// Query parameters for retrieval of a parlance resource set
///
/// Id of the resource set
/// An IETF languageId tag specifying the resource sets languageId
diff --git a/idee5.Globalization/Queries/GetResourceKeyTranslationsQuery.cs b/idee5.Globalization/Queries/GetResourceKeyTranslationsQuery.cs
new file mode 100644
index 0000000..68005ca
--- /dev/null
+++ b/idee5.Globalization/Queries/GetResourceKeyTranslationsQuery.cs
@@ -0,0 +1,9 @@
+using idee5.Common;
+using idee5.Globalization.Models;
+
+namespace idee5.Globalization.Queries;
+
+///
+/// The get resource key translations query parameters
+///
+public record GetResourceKeyTranslationsQuery() : ResourceKey, IQuery;
diff --git a/idee5.Globalization/Queries/GetResourceKeyTranslationsQueryHandler.cs b/idee5.Globalization/Queries/GetResourceKeyTranslationsQueryHandler.cs
new file mode 100644
index 0000000..e8065fe
--- /dev/null
+++ b/idee5.Globalization/Queries/GetResourceKeyTranslationsQueryHandler.cs
@@ -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;
+
+///
+/// The get resource key translations query handler
+///
+public class GetResourceKeyTranslationsQueryHandler : IQueryHandlerAsync {
+ readonly IResourceQueryRepository _repository;
+
+ public GetResourceKeyTranslationsQueryHandler(IResourceQueryRepository repository) {
+ _repository = repository;
+ }
+
+ ///
+ public async Task HandleAsync(GetResourceKeyTranslationsQuery query, CancellationToken cancellationToken = default) {
+ if (query is null) {
+ throw new ArgumentNullException(nameof(query));
+ }
+ List 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);
+ }
+}
diff --git a/idee5.Globalization/Queries/GetResourceSetsByNameQueryHandler.cs b/idee5.Globalization/Queries/GetResourceSetsByNameQueryHandler.cs
index 081d9b5..446b5ef 100644
--- a/idee5.Globalization/Queries/GetResourceSetsByNameQueryHandler.cs
+++ b/idee5.Globalization/Queries/GetResourceSetsByNameQueryHandler.cs
@@ -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;
+///
+/// The get resource sets by name query handler
+///
public class GetResourceSetsByNameQueryHandler : IQueryHandlerAsync> {
private readonly IResourceQueryRepository _repository;
diff --git a/idee5.Globalization/idee5.Globalization.csproj b/idee5.Globalization/idee5.Globalization.csproj
index af27348..f3909cd 100644
--- a/idee5.Globalization/idee5.Globalization.csproj
+++ b/idee5.Globalization/idee5.Globalization.csproj
@@ -13,9 +13,9 @@
Globalization extensions. Enables database support for localization resources and parlances for industries and customers..
idee5
© idee5 2016 - 2024
- 3.5.2
+ 3.5.3
idee5, Globalization, Localization
- Update resource key with comment support
+ Get translations for resource key added
enable
Bernd Dongus
Globalization tool for parlances for industries and customers
@@ -42,7 +42,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive