Questions about Custom Translation provider implementation
I've run into a few items I'm unsure of when building out my custom translation provider.
How is the CanTranslate method used?
How is the GetTargetLanguages method used?
I'm getting a StackOverflowException when I the Cancel method of the JobService api is triggered. Any idea why? It appears to be stuck in a loop, as I see a number of log entries with "[ 0] Calling Provider" that originate from Jumoo.TranslationManager.Core.Services.TranslationJobService. There are no loops in my logic for this, though I do have the logic in a service that's initialized in the constructor of the provider instead of directly inside the provider class, as I need to expose a few of the methods for use with an api. See below for relevant code.
From Provider
public StrakerTranslationProvider(TranslationManagerContext translationManagerContext, ILogger logger) {
_logger = logger;
_strakerService = new StrakerService(ApplicationContext.Current, translationManagerContext, this.Alias, logger);
}
...
public Task<TranslationAttempt<TranslationJob>> Cancel(TranslationJob job) {
return _strakerService.Cancel(job);
}
yeah sorry, about this we are working on the documentation to hopefully make this whole process easier for people
1 & 2. CanTranslate and GetTargetLanguages are not currently called by Translation Manager but the intention is that they will be used as part of the sending process to check if the target/source languages are valid for the provider.
if practical your provider should return true if the provider can translate a job from the source language into the job target language., but just not implementing them at the moment shouldn't cause any issues.
3: Looking at the code, is it the async stuff?
You should be able to change the provider to :
public async Task<TranslationAttempt<TranslationJob>> Cancel(TranslationJob job) {
return await _strakerService.Cancel(job);
}
As for #3, I tried changing it to async, but the issue persists. I suspect there is an issue with the job sent to the service, as I don't encounter this issue with the xliff provider. Below is the job data sent to the job service.
Sorry, I have come around and looked at the code in the original post again
You don't need to call _jobService.Cancel() when your provider/service gets its cancel called. That is the actual function that is calling your provider so you are stuck in a loop.
If you don't actually need to do anything to via own Service your cancel in the provider can just return success
public Task<TranslationAttempt<TranslationJob>> Cancel(TranslationJob job)
{
return Task.FromResult(TranslationAttempt<TranslationJob>.Succeed(job));
}
This will just return to TM which will cancel the job.
If you need to not let the cancel happen then return a Failed attempt and that will halt the cancellation process in Translation Manager.
Questions about Custom Translation provider implementation
I've run into a few items I'm unsure of when building out my custom translation provider.
From Provider
From Service
Hi Jesse,
yeah sorry, about this we are working on the documentation to hopefully make this whole process easier for people
1 & 2.
CanTranslate
andGetTargetLanguages
are not currently called by Translation Manager but the intention is that they will be used as part of the sending process to check if the target/source languages are valid for the provider.if practical your provider should return true if the provider can translate a job from the source language into the job target language., but just not implementing them at the moment shouldn't cause any issues.
3: Looking at the code, is it the async stuff?
You should be able to change the provider to :
Noted on #1 and #2. That makes sense.
As for #3, I tried changing it to async, but the issue persists. I suspect there is an issue with the job sent to the service, as I don't encounter this issue with the xliff provider. Below is the job data sent to the job service.
One potential issue I see is that the NodeCount is 0 when there are nodes in the Nodes property. I'm unsure why that is happening though.
Hi
Sorry, I have come around and looked at the code in the original post again
You don't need to call
_jobService.Cancel()
when your provider/service gets its cancel called. That is the actual function that is calling your provider so you are stuck in a loop.If you don't actually need to do anything to via own Service your cancel in the provider can just return success
This will just return to TM which will cancel the job.
If you need to not let the cancel happen then return a Failed attempt and that will halt the cancellation process in Translation Manager.
Thanks Kevin. That was the issue.
is working on a reply...