public static void UpdateContentLanguageClasses(XmlNode elementOrDom, CollectionSettings settings,
string vernacularIso, string contentLanguageIso2, string contentLanguageIso3)
{
var multilingualClass = "bloom-monolingual";
var contentLanguages = new Dictionary<string, string>();
contentLanguages.Add(vernacularIso, "bloom-content1");
if (!String.IsNullOrEmpty(contentLanguageIso2) && vernacularIso != contentLanguageIso2)
{
multilingualClass = "bloom-bilingual";
contentLanguages.Add(contentLanguageIso2, "bloom-content2");
}
if (!String.IsNullOrEmpty(contentLanguageIso3) && vernacularIso != contentLanguageIso3 &&
contentLanguageIso2 != contentLanguageIso3)
{
multilingualClass = "bloom-trilingual";
contentLanguages.Add(contentLanguageIso3, "bloom-content3");
Debug.Assert(!String.IsNullOrEmpty(contentLanguageIso2), "shouldn't have a content3 lang with no content2 lang");
}
//Stick a class in the page div telling the stylesheet how many languages we are displaying (only makes sense for content pages, in Jan 2012).
foreach (
XmlElement pageDiv in
elementOrDom.SafeSelectNodes(
"descendant-or-self::div[contains(@class,'bloom-page') and not(contains(@class,'bloom-frontMatter')) and not(contains(@class,'bloom-backMatter'))]")
)
{
HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-monolingual");
HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-bilingual");
HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-trilingual");
HtmlDom.AddClassIfMissing(pageDiv, multilingualClass);
}
// This is the "code" part of the visibility system: https://goo.gl/EgnSJo
foreach (XmlElement group in elementOrDom.SafeSelectNodes(".//*[contains(@class,'bloom-translationGroup')]"))
{
var dataDefaultLanguages = HtmlDom.GetAttributeValue(group, "data-default-languages").Split(new char[] { ',', ' ' },
StringSplitOptions.RemoveEmptyEntries);
//nb: we don't necessarily care that a div is editable or not
foreach (XmlElement e in @group.SafeSelectNodes(".//textarea | .//div"))
{
HtmlDom.RemoveClassesBeginingWith(e, "bloom-content");
var lang = e.GetAttribute("lang");
//These bloom-content* classes are used by some stylesheet rules, primarily to boost the font-size of some languages.
//Enhance: this is too complex; the semantics of these overlap with each other and with bloom-visibility-code-on, and with data-language-order.
//It would be better to have non-overlapping things; 1 for order, 1 for visibility, one for the lang's role in this collection.
string orderClass;
if (contentLanguages.TryGetValue(lang, out orderClass))
{
HtmlDom.AddClass(e, orderClass); //bloom-content1, bloom-content2, bloom-content3
}
//Enhance: it's even more likely that we can get rid of these by replacing them with bloom-content2, bloom-content3
if (lang == settings.Language2Iso639Code)
{
HtmlDom.AddClass(e, "bloom-contentNational1");
}
if (lang == settings.Language3Iso639Code)
{
HtmlDom.AddClass(e, "bloom-contentNational2");
}
HtmlDom.RemoveClassesBeginingWith(e, "bloom-visibility-code");
if (ShouldNormallyShowEditable(lang, dataDefaultLanguages, contentLanguageIso2, contentLanguageIso3, settings))
{
HtmlDom.AddClass(e, "bloom-visibility-code-on");
}
UpdateRightToLeftSetting(settings, e, lang);
}
}
}