/// <summary>
        /// This is where all the excitement happens. We update the specified group
        /// with the data from the spreadsheet row.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="group"></param>
        private void PutRowInGroup(ContentRow row, XmlElement group)
        {
            var sheetLanguages = _sheet.Languages;

            foreach (var lang in sheetLanguages)
            {
                var colIndex = _sheet.GetRequiredColumnForLang(lang);
                var content  = row.GetCell(colIndex).Content;
                var editable = HtmlDom.GetEditableChildInLang(group, lang);
                if (editable == null)
                {
                    if (IsEmptyCell(content))
                    {
                        continue;                         // Review: or make an empty one?
                    }
                    editable = TranslationGroupManager.MakeElementWithLanguageForOneGroup(group, lang);
                }

                if (IsEmptyCell(content))
                {
                    editable.ParentNode.RemoveChild(editable);
                }
                else
                {
                    editable.InnerXml = content;
                }
            }

            if (RemoveOtherLanguages)
            {
                HtmlDom.RemoveOtherLanguages(@group, sheetLanguages);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This is where all the excitement happens. We update the specified group
        /// with the data from the spreadsheet row.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="group"></param>
        private void PutRowInGroup(ContentRow row, XmlElement group)
        {
            var sheetLanguages = _sheet.Languages;

            foreach (var lang in sheetLanguages)
            {
                var colIndex = _sheet.ColumnForLang(lang);
                var content  = row.GetCell(colIndex).Content;
                var editable = HtmlDom.GetEditableChildInLang(group, lang);
                if (editable == null)
                {
                    if (string.IsNullOrEmpty(content))
                    {
                        continue;                                          // Review: or make an empty one?
                    }
                    var temp = HtmlDom.GetEditableChildInLang(group, "z"); // standard template element
                    if (temp == null)
                    {
                        temp = HtmlDom.GetEditableChildInLang(group, null);                         // use any available template
                    }
                    if (temp == null)
                    {
                        // Enhance: Eventually we should be able to come up with some sort of default here.
                        // Since this is a rather simple temporary expedient I haven't unit tested it.
                        _warnings.Add(
                            $"Could not import group {_groupOnPageIndex} ({content}) on page {HtmlDom.NumberOfPage(_currentPage)} because it has no bloom-editable children to use as templates.");
                        return;
                    }

                    editable = temp.Clone() as XmlElement;
                    editable.SetAttribute("lang", lang);
                    group.AppendChild(editable);
                }

                if (HasMarkup(content))
                {
                    try
                    {
                        editable.InnerXml = content;
                    }
                    catch (XmlException)
                    {
                        // It wasn't XML after all? Just somehow had a wedge? Keep the whole lot as text.
                        SetContentAsText(editable, content);
                    }
                }
                else
                {
                    SetContentAsText(editable, content);
                }
            }

            if (RemoveOtherLanguages)
            {
                HtmlDom.RemoveOtherLanguages(@group, sheetLanguages);
            }
        }