Repository navigation
refactor(translation): implement eFormApi.BasePn's ITranslationService (needs BasePn 10.0.37) - #8110
Merged
Merged
Conversation
microting/eform-backendconfiguration-plugin#1384) The translation interface moves to eFormApi.BasePn 10.0.37 so plugins can translate server-side; the host keeps the implementation and the options, so the API key never leaves the host. - TranslationService implements the BasePn interface, reads the key from IOptions<GoogleTranslateOptions> and exposes IsConfigured; the translation-possible endpoint uses it. Without a key it fails without calling Google. - As the interface promises, a network failure, timeout or unreadable response becomes an unsuccessful result instead of an exception. - One static HttpClient (10 s timeout, pooled connections recycled every 5 min) instead of a client per call; the service is now a singleton. - Bumps Microting.eFormApi.BasePn to 10.0.37. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-service-from-basepn
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (5)
Returning raw exception messages to the API caller and writing them to stdout can leak sensitive… · New This test name asserts the call fails without calling Google, but it doesn’t actually assert ‘no… · New Because this service is registered as a singleton and cachesoptions.Value.ApiKeyat construction… · NewFormUrlEncodedContentisIDisposable; currently it’s created inline and never disposed. Create… · New This PR will faildotnet restore/CI untilMicroting.eFormApi.BasePnv10.0.37 is published to… · New
What changed in this PR
Refactors the host’s translation implementation to adopt Microting.eFormApi.BasePn’s ITranslationService so plugins can perform server-side translations while keeping Google Translate configuration in the host.
Changes:
- Upgrades
Microting.eFormApi.BasePnto10.0.37and switches DI to register translation as a singleton. - Updates
TranslationServiceto implement BasePn’s translation interface, moving API key handling into options with a sharedHttpClientand non-throwing failures. - Updates controller + tests to match the new interface/constructor and removes the host-local translation abstraction.
| File | Description |
|---|---|
| eFormAPI/eFormAPI.Web/eFormAPI.Web.csproj | Bumps BasePn dependency to the version that contains the moved translation interface. |
| eFormAPI/eFormAPI.Web/Startup.cs | Registers the translation service as a singleton against BasePn’s ITranslationService. |
| eFormAPI/eFormAPI.Web/Services/TranslationService.cs | Implements BasePn translation interface; adds options-based API key handling, shared HttpClient, and exception-to-failure mapping. |
| eFormAPI/eFormAPI.Web/Controllers/TranslationController.cs | Removes API key parameter passing and relies on ITranslationService.IsConfigured. |
| eFormAPI/eFormAPI.Web/Abstractions/ITranslationService.cs | Removes the host’s translation interface in favor of BasePn’s interface. |
| eFormAPI/eFormAPI.Web.Tests/TranslationServiceTests.cs | Adds unit tests for IsConfigured behavior and no-key failure behavior. |
| eFormAPI/eFormAPI.Web.Integration.Tests/Services/TranslationServiceTests.cs | Updates integration test construction for the new options-based service constructor. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+61
to
+65
| catch (Exception e) when (e is HttpRequestException or TaskCanceledException or JsonException) | ||
| { | ||
| Console.WriteLine($"Translate error: {e.Message}"); | ||
| return new OperationDataResult<string>(false, $"Translate failed: {e.Message}"); | ||
| } |
Comment on lines
+32
to
+39
| public async Task TranslateText_WithoutApiKey_IsNotConfigured_AndFailsWithoutCallingGoogle(string apiKey) | ||
| { | ||
| var service = new TranslationService(Options.Create(new GoogleTranslateOptions { ApiKey = apiKey })); | ||
|
|
||
| Assert.That(service.IsConfigured, Is.False); | ||
| var result = await service.TranslateText("Tank 4", "da", "en-US"); | ||
| Assert.That(result.Success, Is.False); | ||
| } |
Comment on lines
+30
to
+32
| private readonly string _apiKey = options.Value.ApiKey; | ||
|
|
||
| public bool IsConfigured => !string.IsNullOrEmpty(_apiKey); |
| // network failure or the timeout never fails the caller's save. | ||
| try | ||
| { | ||
| using var response = await Client.PostAsync(apiUrl, new FormUrlEncodedContent(form)); |
| <PackageReference Include="Microting.eForm" Version="10.0.41" /> | ||
| <PackageReference Include="Microting.EformAngularFrontendBase" Version="10.0.40" /> | ||
| <PackageReference Include="Microting.eFormApi.BasePn" Version="10.0.36" /> | ||
| <PackageReference Include="Microting.eFormApi.BasePn" Version="10.0.37" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
The host switches to the translation interface that moved to eFormApi.BasePn, so plugins can translate server-side (microting/eform-backendconfiguration-plugin#1384, v2 of #1324). The implementation,
GoogleTranslateOptionsand the API key stay in the host.TranslationServicenow implementsMicroting.eFormApi.BasePn.Abstractions.Translation.ITranslationService:IOptions<GoogleTranslateOptions>, andIsConfiguredreports whether a key is set.FAKE_TRANSLATE_E2Ehook is unchanged.HttpRequestException), a timeout (TaskCanceledException) or an unreadable response (JsonException) becomes an unsuccessful result.HttpClient(10 s timeout,PooledConnectionLifetime5 min) replaces a new client per call. The service is registered as a singleton.TranslationController:translation-possiblenow readsIsConfigured. The host's ownAbstractions/ITranslationService.csis removed.Microting.eFormApi.BasePnfrom 10.0.36 to 10.0.37.Tests
eFormAPI.Web.Tests/TranslationServiceTests: two new tests. Without a key the service is not configured and fails without a network call. With a key,IsConfiguredis true.Not verified
Refs microting/eform-backendconfiguration-plugin#1384
🤖 Generated with Claude Code