Translation Manager with Connector → Translating B...
# help-with-umbraco
w
Hi everyone, We have been using the Translation Manager package (by Jumoo) in Umbraco for a while and the client has now asked us to perform a PoC on using a connector to automate the actual translations of content to another language. We decided to go with the available extension from Jumoo to add the Google Translation API as a connector. Setting everything up with an API key et al went smoothly and we created a new Translation Set to use this and translate English content to French. After creating the job and viewing the results everything seems great! All content is translated to French, including anything in Block List items (nested multiple levels deep). However, after approving and publishing the results of the job and inspecting the page(s) translated, it appears that only the root level content is actually translated to French. All content inside of Block List items is still in English. Does anyone know how to tackle this problem? It's strange as even after publishing, viewing the job from the "Translation" tab of the node is still showing perfectly translated content. Thanks in advance for any help, tips or advice! 🙏🏽
k
Hi, that certainly should work 😞 - what version of Umbraco / Translation Manager do you have installed,and i will do some tests and double check things
w
Hi Kevin! Thanks for taking the time to respond. In the meanwhile I think I have found the culprit... a colleague developer remembered that he added an extension class to
BlockListMapper
in order to fix a bug that was occurring with BlockList items getting mixed up after using Translation Manager (causing e.g. French content to show up on the English website -- so both ways instead of only source → target).
If I comment out that class, Block List items are correcty translated, published and visible in Umbraco and on the website! 🎉 However, this would allow the above bug to re-occur, so I'll have to take a look at how the extension class can be adjusted to not prevent Block List items from translating to the target language.
k
Hmmm odd, if you want to send me details of that bug feel free, I've not seen that happen on anything we've tested but i don't mind taking a look
w
Sorry for the delay -- the issue occurs in Umbraco 8 (specifically, 8.18.1) with Translation Manager 9.1.6 What happens is that when content is translated with the Translation Manager, the GUIDs associated with 'linked' content such as Block List items and Nested Content items also get copied across to the target website, resulting in duplicate GUIDs. Umbraco then caches this content using the GUID, which results in content from another language showing up elsewhere.
We fixed that by extending
BlockListMapper
to force it to create a new GUID for these items during translation. But apparently that is now preventing the actual translation via the Connector (Google Translation API) from being applied, so we need to adjust that code.
k
ahh yeah that sounds familiar - I think that was fixed in the v10+ version (we make a new guid, based on the old one + the culture - so it doesn't change within the language but is consistant across translations) i will take a look and see if its something that was / can be put back into the v8 one
w
Oh, that would be amazing! 😮 Let me know how that goes! Would be nice not to have to extend the code to fix it, introducing risk of other potential issues
In order to fix the issue which occurs due to our
BlockListValueMapper
extension class I'm attempting to use the code from a GitHub Gist of yours @Kevin Jump . However, I can't seem to discern where
ValueMapperFactory
can be loaded/accessed from? https://gist.github.com/KevinJump/a7754bb20f93b1e9934a8cbfb1bb9203
Specifically for this line in the
GetTargetValue()
method:
var value = (string)ValueMapperFactory.GetMapperTarget(...)
Oh, it appears that the method is now in
ValueMapperCollection
(used dotPeek)? Don't seem to be able to access it from my class though
k
I think that's a V2 example I will have a quick look for a V8/10 one
Short answer is dependency injection
we might be able to put this into a v8 release in the new year, the v10+ branch is based of this code base, but some fundimental updates where done for blockgrid, and a couple of other things, so its not a straight drop in. But in theory it only needs the
UpdateLayout
method at the end to fix the guid issue.
w
Thanks a bunch Kevin, I'm going to check this out in a little bit!
Sorry to bother you again @Kevin Jump . The above example helped me to complete my class without any issues. However I need to apply this same logic to the Nested Content data type properties also and am having trouble figuring out how to use the
TranslationValue
variable in the
GetTargetValue()
method to parse the inner values in the way they are expected to be. The JSON is different than that of Block List and I've been fiddling around for an hour or so but thought perhaps asking you could be quicker?
I can't really select by property name because in
sourceValue
this is (e.g.) "menuItemDC", whereas in the
TranslationValue
object it is "menuItemDC_1", which doesn't seem very reliable that it will always be appended by "_1".
Oh, I realised that the appended underscore followed by a number relates to the order of the nested content item. So I guess I need to write a few recursive
foreach
loops to match the values in
sourceValue
and
values
to one another, but I'm struggling to wrap my head around how to structure this exactly.
k
Hi, (not really near a computer for long today) - but if its changing the guid values like in the blocks, you don't needto itterate over the translated values, rather fix it post once you have the final JSON value in GetTargetValue ? (as the gist above). You could inherit from the existing NestedContentMapper, overwrite the GetTargetValue method ? call the base GetTargetValue then manipuldate the returned JSON to update the keys ?
note i haven't tested this !!!
Copy code
cs

    public class IdChangingNestedContentMapper : NestedContentMapper
    {
        public IdChangingNestedContentMapper(IContentService contentService, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILogger<NestedContentMapper> logger, Lazy<ValueMapperCollection> valueMappers) 
            : base(contentService, dataTypeService, contentTypeService, logger, valueMappers)
        {
        }

        public new object GetTargetValue(string propertyEditorAlias, object sourceValue, TranslationValue value, CultureInfoView sourceCulture, CultureInfoView targetCulture)
        {

            var result = base.GetTargetValue(propertyEditorAlias, sourceValue, value, sourceCulture, targetCulture);

            // do work here ? 

            return result;
        }
    }
w
No problem, we are near the holidays after all
We indeed have a class which extends on
NestedContentMapper
which was for fixing the GUID bug I spoke to you about earlier this week, we have three in total (Block List, Nested Content and a 'catch-all' one for miscellaneous 'regular' data types which weren't being copied across in the job for some reason (e.g., Mediapicker, Tags, DateTime). So I was trying to adjust our existing Nested Content mapper extension class but was mostly accomplishing giving myself a headache, lol.
Good idea to call the base logic and then adjust the result, hopefully it is a less tangled web!!
3 Views