Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesse Andrews 191 posts 716 karma points c-trib
    Jun 25, 2019 @ 01:18
    Jesse Andrews
    0

    Questions about Custom Translation provider implementation

    I've run into a few items I'm unsure of when building out my custom translation provider.

    1. How is the CanTranslate method used?
    2. How is the GetTargetLanguages method used?
    3. 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);
    }
    

    From Service

    public StrakerService(ApplicationContext applicationContext, TranslationManagerContext translationManagerContext, string providerAlias, ILogger logger) {
        _dbContext = applicationContext.DatabaseContext;
        _providerAlias = providerAlias;
        _settings = GetSettings();
        _logger = logger;
        _jobService = translationManagerContext.JobService;
        _serializer = new StrakerSerializer(_logger);
    }
    
    ...
    
    public async Task<TranslationAttempt<TranslationJob>> Cancel(TranslationJob job) {
        return await _jobService.Cancel(job);
    }
    
  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 25, 2019 @ 08:59
    Kevin Jump
    0

    Hi Jesse,

    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);
    }
    
  • Jesse Andrews 191 posts 716 karma points c-trib
    Jun 25, 2019 @ 17:21
    Jesse Andrews
    0

    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.

    {
      "Id": 143,
      "Key": "43909b2a-f877-4c26-9128-ae338cbe8294",
      "SetKey": "d28f1a34-6452-4446-870a-9caaffe8ca53",
      "Name": "Translations Spanish 6/25/2019, 10:07:43 AM",
      "SourceCulture": {
        "LCID": 1033,
        "Name": "en-US",
        "DisplayName": "English (United States)",
        "TwoLetterISOLanguageName": "en",
        "ThreeLetterISOLanguageName": "eng",
        "ThreeLetterWindowsLanguageName": "ENU"
      },
      "TargetCulture": {
        "LCID": 10,
        "Name": "es",
        "DisplayName": "Spanish",
        "TwoLetterISOLanguageName": "es",
        "ThreeLetterISOLanguageName": "spa",
        "ThreeLetterWindowsLanguageName": "ESP"
      },
      "NodeCount": 0,
      "Nodes": [
        {
          "Id": 4265,
          "Key": "18d0461f-5512-4333-a5e4-4501008b5917",
          "SetKey": "d28f1a34-6452-4446-870a-9caaffe8ca53",
          "Culture": {
            "LCID": 10,
            "Name": "es",
            "DisplayName": "Spanish",
            "TwoLetterISOLanguageName": "es",
            "ThreeLetterISOLanguageName": "spa",
            "ThreeLetterWindowsLanguageName": "ESP"
          },
          "MasterNodeId": 8636,
          "TargetNodeId": 8637,
          "Status": "InProgress",
          "Created": "2019-06-25T10:07:49.803Z",
          "Updated": "2019-06-25T10:07:50.2Z",
          "MasterNodeName": "A Translation Test",
          "TargetNodeName": "A Translation Test",
          "MasterNodePath": null,
          "TargetNodePath": null,
          "IsDictionary": false,
          "ContentVersion": "c5eb0652-bd94-4bad-899e-c4e3bec1e7fd",
          "Groups": [
            {
              "Name": "content",
              "SortOrder": 0,
              "DisplayName": "Content",
              "Properties": [
                {
                  "Id": 7062,
                  "NodeKey": "18d0461f-5512-4333-a5e4-4501008b5917",
                  "Alias": "bodyText",
                  "Group": "Content",
                  "SortOrder": 0,
                  "Source": {
                    "DisplayName": "Body Text",
                    "EditorAlias": "Umbraco.Grid",
                    "Value": null,
                    "HtmlControl": false,
                    "Translated": false,
                    "SortOrder": 0,
                    "InnerValues": {
                      "e58128aa-3834-0e81-3a9b-ef00ed675ad7": {
                        "DisplayName": "Grid.Row",
                        "EditorAlias": "",
                        "Value": null,
                        "HtmlControl": false,
                        "Translated": false,
                        "SortOrder": 1,
                        "InnerValues": {
                          "Umbraco.Grid.rte_1": {
                            "DisplayName": "Body Text Rich text editor",
                            "EditorAlias": "Umbraco.Grid.rte",
                            "Value": null,
                            "HtmlControl": false,
                            "Translated": false,
                            "SortOrder": 2,
                            "InnerValues": {
                              "html": {
                                "DisplayName": "Body Text Rich text editor",
                                "EditorAlias": "html",
                                "Value": "<p>Translation Test</p>",
                                "HtmlControl": true,
                                "Translated": false,
                                "SortOrder": 0,
                                "InnerValues": {}
                              }
                            }
                          }
                        }
                      }
                    }
                  },
                  "Target": {
                    "DisplayName": "Body Text",
                    "EditorAlias": "Umbraco.Grid",
                    "Value": null,
                    "HtmlControl": false,
                    "Translated": false,
                    "SortOrder": 0,
                    "InnerValues": {
                      "e58128aa-3834-0e81-3a9b-ef00ed675ad7": {
                        "DisplayName": "Grid.Row",
                        "EditorAlias": "",
                        "Value": null,
                        "HtmlControl": false,
                        "Translated": false,
                        "SortOrder": 1,
                        "InnerValues": {
                          "Umbraco.Grid.rte_1": {
                            "DisplayName": "Body Text Rich text editor",
                            "EditorAlias": "Umbraco.Grid.rte",
                            "Value": null,
                            "HtmlControl": false,
                            "Translated": false,
                            "SortOrder": 2,
                            "InnerValues": {
                              "html": {
                                "DisplayName": "Body Text Rich text editor",
                                "EditorAlias": "html",
                                "Value": "<p>Translation Test</p>",
                                "HtmlControl": true,
                                "Translated": false,
                                "SortOrder": 0,
                                "InnerValues": {}
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              ]
            }
          ],
          "HasOpenSiblings": false
        }
      ],
      "Created": "2019-06-25T10:07:50.253Z",
      "Submitted": "2019-06-25T10:07:52.44Z",
      "Received": "0001-01-01T00:00:00",
      "StatusIsDirty": true,
      "Status": "Submitted",
      "ProviderKey": "de02b2cd-afc1-4d82-b27d-fe2c3cde5be9",
      "ProviderName": "Straker Translation Provider",
      "ProviderProperties": "{}",
      "StatusLocalName": null,
      "UserId": 0
    }
    

    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.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 26, 2019 @ 09:55
    Kevin Jump
    100

    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

        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.

  • Jesse Andrews 191 posts 716 karma points c-trib
    Jun 26, 2019 @ 16:39
    Jesse Andrews
    0

    Thanks Kevin. That was the issue.

Please Sign in or register to post replies

Write your reply to:

Draft