Copied to clipboard

Flag this post as spam?

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


  • David McDonnell 53 posts 251 karma points
    Mar 04, 2019 @ 15:22
    David McDonnell
    0

    Custom Grid Editor Translation Manager

    Hi I have a number of custom grid editors that I use on my Grid Content pages, these are not supported it seems out of the box with the translation manager.

    I have found some links and documentation on supporting custom grid editors but its not entirely clear.

    In the translations section of the translations.config I am configuring the following:

      <mappers>
    <grid>
        <custom>
            <config alias="listModule">
                <properties>
                    <property name="text" alias="Umbraco.Textbox" />
                    <property name="subText" alias="Umbraco.Textbox" />
                </properties>
            </config>
        </custom>
    </grid></mappers>
    

    now my custom grid editors alias is listModule, all this module does is allow an editor to create an un-ordered list with each list item having a title and sub title. So the module stores an array of title and subtitles and loops them out in the view in the markup template below

    the module outputs the following markup:

    <ul class="list-module">
            <li>
                <div class="li-mainText">Some Title Text</div>
                <div class="li-subText">Some subtitle text</div>
            </li>....
    </ul>
    

    Any ideas on how I would allow this modules list items to be brought into the translation screens?

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Mar 04, 2019 @ 16:47
    Kevin Jump
    0

    Hi David,

    translation manager is really just concerned with how the JSON is stored for your property.

    So based on your config i would expect the JSON for the property to look something like.

    { 
        "text", "some text value",
         "subText", "a sub text value"
    }
    

    but I suspect you're values are stored in an array?

    so more like

    [ 
       { "text", "first text value", "subText", "sub text" }, 
       { "text", "secondText", "subText", "subtext}
    ]
    

    the custom mapper that uses the config doesn't support arrays at the moment (not 100% sure the best way it could).

    However, you can write your own mapper which would receive the JSON values from the grid and return the TranslationValue to Translation Manager.

    this is the code for the custom value mapper : https://gist.github.com/KevinJump/a7754bb20f93b1e9934a8cbfb1bb9203

    Which is close to what you want (you wouldn't need to read things from config files and could work through the json in the format you know it is in)

  • David McDonnell 53 posts 251 karma points
    Mar 11, 2019 @ 12:22
    David McDonnell
    0

    Hi Kevin

    Thanks for the reply, I have created a copy of the custom value mapper and hardcoded in the editor alias for a test example below.

    public override string[] Editors => new[] { "listModule" };
    

    I have set a breakpoint on the first line of GetSourceValue and GetTargetValue

    but when debugging it is not hitting either of these methods.

    My Manifest for the grid editor is the following:

    {
         gridEditors:[
         {
            alias:"listModule",
            name: "List Module",
            view: "~/App_Plugins/ListModule/ListEditor.html",
            icon: "icon-bulleted-list" }
         ],
         javascript: [ "~/app_plugins/ListModule/ListController.js" ]
    }
    

    Custom Value Mapper:

     public TranslationValue GetSourceValue(string displayName,
       string propertyTypeAlias,
       object value,
       CultureInfoView culture)
       {
                if (value == null) return null;
    
               continue......
       }
    
    
    public object GetTargetValue(
     string propertyTypeAlias,
     object sourceValue,
     TranslationValue values,
     CultureInfoView sourceCulture,
     CultureInfoView targetCulture)
     {
           if (sourceValue == null) return null;
    
           continue.......
     }
    

    any ideas why this isnt hitting the breakpoint? I presume I am missing some configuration

    Cheers

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Mar 11, 2019 @ 13:07
    Kevin Jump
    100

    Hi David,

    when you have a custom editor in code Translation Manager will append. Umbraco.Grid to the alias,

    so, in this case, an Editor Alias of Umbraco.Grid.listModule should work.

    Kevin

  • David McDonnell 53 posts 251 karma points
    Mar 11, 2019 @ 14:39
    David McDonnell
    0

    Cheers Kevin, that worked perfectly

    :)

Please Sign in or register to post replies

Write your reply to:

Draft