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
    Feb 25, 2019 @ 22:00
    Jesse Andrews
    0

    Translations for property that stores its data as an array aren't applied correctly

    I have a custom property that stores its data as json. I wrote a mapper for it and that's working, but I'm running into issues with handing its value off to the NestedContentMapper, since it appears to expect its inner mappers to return strings, as I get the following error.

    2019-02-25 13:09:35,014 [P8868/D23/T23] ERROR Jumoo.TranslationManager.Core.Controllers.TranslationJobApiController - Unhandled controller exception occurred
    System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[FlexibleLinkV2.Models.FlexibleLinkModel]' to type 'System.String'.
       at Jumoo.TranslationManager.Core.ValueMappers.NestedContentMapper.GetTargetValue(String propertyEditorAlias, Object sourceValue, TranslationValue value, CultureInfoView sourceCulture, CultureInfoView targetCulture)
       at Jumoo.TranslationManager.Core.ValueMappers.LeBlenderValueMapper.GetTargetValue(String propertyTypeAlias, Object sourceValue, TranslationValue values, CultureInfoView sourceCulture, CultureInfoView targetCulture)
       at Jumoo.TranslationManager.Core.ValueMappers.GridValueMapper.GetTargetValue(String propertyEditorAlias, Object sourceValue, TranslationValue value, CultureInfoView sourceCulture, CultureInfoView targetCulture)
       at Jumoo.TranslationManager.Core.Services.TranslationValueService.SetPropertyValue(IContent item, String alias, String sourceValue, TranslationValue value, CultureInfoView sourceCulture, CultureInfoView targetCulture)
       at Jumoo.TranslationManager.Core.Services.TranslationNodeService.SetContentValuesFromTranslation(TranslationNode node, CultureInfoView sourceCulture)
       at Jumoo.TranslationManager.Core.Services.TranslationJobService.ProgressJob(TranslationJob job, IEnumerable`1 nodes, Boolean publish, Boolean ApproveJob, Boolean checkProgress)
       at Jumoo.TranslationManager.Core.Services.TranslationJobService.ProgressJob(TranslationJob job, IEnumerable`1 nodeIds, Boolean publish, Boolean ApproveJob, Boolean checkProgress)
       at Jumoo.TranslationManager.Core.Controllers.TranslationJobApiController.Approve(Int32 id, ApproveOptions options)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
    

    The data returned by the mapper I wrote is in the form:

    [
      {
        "id": 1234,
        "label": "A Label",
        "type": "internal"
      }
    ]
    

    but it's stored as

    "[\r\n  {\r\n    \"Id\": 1234,\r\n    \"Label\": \"A Label\",\r\n    \"Type\": \"internal\"\r\n  }\r\n]"
    

    in umbraco.config if I serialize the data to avoid the error.

    Can you add a check to NestedContentMapper to avoid the earlier error and ensure that the unescaped data is returned? If it still encodes it after that, the issue could be that the nested content is nested inside a leblender control.

  • Jesse Andrews 191 posts 716 karma points c-trib
    Feb 25, 2019 @ 22:37
    Jesse Andrews
    100

    Turns out things weren't working because of a serialization issue, since the property names were stored in PascalCase instead of CamelCase. This prevented angular from picking up on the data. Umbraco parses the text correctly.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 26, 2019 @ 09:10
    Kevin Jump
    0

    Hi Jesse,

    Glad you sorted it. - but just a note to say how it works in case it helps.

    The idea behind the translation values and inner values is that they only contain the text needed to be translated - and the other elements and settings - are kept on the content nodes. so as such if you have a custom object that has the following items :

    [
      {
        "id": 1234,
        "label": "A Label",
        "type": "internal"
      }
    ]
    

    in translation manager, this would be represented by (assuming type is text)

    TranslationValue (your custom value) - Inner Values - Translation Value (Label) ["A Label"] - Translation Value (Type) ["Internal"]

    So the item passed back to Nested Content Mapper would be the translation value (custom value).

    you can see this: in our sample code here: https://gist.github.com/KevinJump/a7754bb20f93b1e9934a8cbfb1bb9203

    When it comes to serializing this back - it would be the custom mappers responsibility to return the JSON that would go into the content element - (there is an added complication on how JSON is stored inside leblender inside nested content - but for most of the time should work)

    As an aside - if your custom object is storing json and doing nothing to fancy you can configure that mapper using the custom mapper config.

    <custom>
            <config alias="YourCustomType">
              <properties>
                <property name="label" alias="Umbraco.Textbox" />
                <property name="target" alias="Umbraco.Textbox" />
              </properties>
            </config>
          </custom>
    
  • Jesse Andrews 191 posts 716 karma points c-trib
    Feb 26, 2019 @ 19:03
    Jesse Andrews
    0

    Yeah I had tried that at one point, but the control I was working on at the time didn't work with this, as it had a grid control nested inside it, so I hadn't pursued this approach further. I'll keep it in mind though, as you are right that it should work for the control I shared with you.

Please Sign in or register to post replies

Write your reply to:

Draft