private static void MakeElementWithLanguageForOneGroup(XmlElement groupElement, string isoCode)
{
if (groupElement.GetAttribute("class").Contains("STOP"))
{
Console.Write("stop");
}
XmlNodeList editableChildrenOfTheGroup =
groupElement.SafeSelectNodes("*[self::textarea or contains(@class,'bloom-editable')]");
var elementsAlreadyInThisLanguage = from XmlElement x in editableChildrenOfTheGroup
where x.GetAttribute("lang") == isoCode
select x;
if (elementsAlreadyInThisLanguage.Any())
//don't mess with this set, it already has a vernacular (this will happen when we're editing a shellbook, not just using it to make a vernacular edition)
return;
if (groupElement.SafeSelectNodes("ancestor-or-self::*[contains(@class,'bloom-translationGroup')]").Count == 0)
return;
var prototype = editableChildrenOfTheGroup[0] as XmlElement;
XmlElement newElementInThisLanguage;
if (prototype == null) //this was an empty translation-group (unusual, but we can cope)
{
newElementInThisLanguage = groupElement.OwnerDocument.CreateElement("div");
newElementInThisLanguage.SetAttribute("class", "bloom-editable");
newElementInThisLanguage.SetAttribute("contenteditable", "true");
if (groupElement.HasAttribute("data-placeholder"))
{
newElementInThisLanguage.SetAttribute("data-placeholder", groupElement.GetAttribute("data-placeholder"));
}
groupElement.AppendChild(newElementInThisLanguage);
}
else //this is the normal situation, where we're just copying the first element
{
//what we want to do is copy everything in the element, except that which is specific to a language.
//so classes on the element, non-text children (like images), etc. should be copied
newElementInThisLanguage = (XmlElement) prototype.ParentNode.InsertAfter(prototype.Clone(), prototype);
//if there is an id, get rid of it, because we don't want 2 elements with the same id
newElementInThisLanguage.RemoveAttribute("id");
//OK, now any text in there will belong to the prototype language, so remove it, while retaining everything else
StripOutText(newElementInThisLanguage);
}
newElementInThisLanguage.SetAttribute("lang", isoCode);
}