/// <summary>
        ///  get the translation of the block (falls through to nested content)
        /// </summary>
        private TranslationValue GetBlockValue(string displayName, JToken block, CultureInfoView culture)
        {
            if (block == null)
            {
                return(null);
            }
            if (block is JObject jBlock)
            {
                if (!jBlock.ContainsKey("content"))
                {
                    return(null);
                }
                var content = jBlock.Value <JArray>("content");

                return(ValueMapperFactory.GetMapperSource(
                           Constants.PropertyEditors.Aliases.NestedContent,
                           displayName,
                           content,
                           culture));
            }

            return(null);
        }
        private static JToken GetBlockTranslation(JToken value, TranslationValue translationValue, CultureInfoView sourceCulture, CultureInfoView targetCulture)
        {
            if (value is JObject jValue)
            {
                if (jValue.ContainsKey("content"))
                {
                    var content = jValue.Value <JArray>("content");

                    var result = (string)ValueMapperFactory.GetMapperTarget(
                        Constants.PropertyEditors.Aliases.NestedContent,
                        content,
                        translationValue,
                        sourceCulture,
                        targetCulture);

                    if (result != null)
                    {
                        value["content"] = JToken.Parse(result);
                    }
                }
            }

            return(value);
        }
        public TranslationValue GetSourceValue(string displayName, string propertyTypeAlias, object value, CultureInfoView culture)
        {
            var jsonValue = GetJson(value);

            if (jsonValue == null)
            {
                return(null);
            }

            // we support v2 of the object.
            if (!jsonValue.ContainsKey("version") || jsonValue.Value <int>("version") != 2)
            {
                return(null);
            }

            // set up a translation value, as the parent for header & blocks
            var translation = new TranslationValue(displayName, propertyTypeAlias);

            if (jsonValue.ContainsKey("header"))
            {
                // get the header
                var headerValue = GetBlockValue("header", jsonValue["header"], culture);
                if (headerValue != null)
                {
                    translation.InnerValues.Add("header", headerValue);
                }
            }

            if (jsonValue.ContainsKey("blocks"))
            {
                // get the blocks.
                var blocks = jsonValue.Value <JArray>("blocks");
                for (int b = 0; b < blocks.Count; b++)
                {
                    var blockValue = GetBlockValue($"block [{b}]", blocks[b], culture);
                    if (blockValue != null)
                    {
                        var blockKey = blocks[b].Value <string>("id");
                        translation.InnerValues.Add(blockKey, blockValue);
                    }
                }
            }

            return(translation);
        }
        /// <summary>
        ///  get the translated value, back into an object we can put in umbraco
        /// </summary>
        public object GetTargetValue(string propertyTypeAlias, object sourceValue, TranslationValue values, CultureInfoView sourceCulture, CultureInfoView targetCulture)
        {
            var jsonValue = GetJson(sourceValue);

            if (jsonValue == null)
            {
                return(sourceValue);
            }

            if (jsonValue.ContainsKey("header"))
            {
                var headerValue = values.GetInnerValue("header");
                if (headerValue != null)
                {
                    var translatedValue = GetBlockTranslation(jsonValue["header"], headerValue, sourceCulture, targetCulture);
                    if (translatedValue != null)
                    {
                        jsonValue["header"] = translatedValue;
                    }
                }
            }

            if (jsonValue.ContainsKey("blocks"))
            {
                // get the blocks.
                var blocks = jsonValue.Value <JArray>("blocks");
                for (int b = 0; b < blocks.Count; b++)
                {
                    var blockKey   = blocks[b].Value <string>("id");
                    var blockValue = values.GetInnerValue(blockKey);
                    if (blockValue != null)
                    {
                        var translatedBlock = GetBlockTranslation(blocks[b], blockValue, sourceCulture, targetCulture);
                        if (translatedBlock != null)
                        {
                            blocks[b] = translatedBlock;
                        }
                    }
                }
            }

            return(JsonConvert.SerializeObject(jsonValue, Formatting.Indented));
        }