/// <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); } }
private void AddTranslationGroupRow(XmlNode group, string pageNumber, int groupIndex) { var row = new ContentRow(); row.AddCell(InternalSpreadsheet.TextGroupLabel); row.AddCell(pageNumber); row.AddCell(groupIndex.ToString(CultureInfo.InvariantCulture)); foreach (var editable in group.SafeSelectNodes("./*[contains(@class, 'bloom-editable')]").Cast <XmlElement>()) { var lang = editable.Attributes["lang"]?.Value ?? ""; if (lang == "z" || lang == "") { continue; } var index = _spreadsheet.ColumnForLang(lang); var content = Params.RetainMarkup ? editable.InnerXml : GetContent(editable); row.SetCell(index, content); } _spreadsheet.AddRow(row); }