private static void ConvertSourceAndTargetToAUnis(XElement group, XElement listElement, string targetLanguage, ConversionMap item) { var id = group.Attribute("id")?.Value + item.IdSuffix; var transUnit = group.Elements(XliffUtils.TransUnit).FirstOrDefault(tu => tu.Attribute("id")?.Value == id); if (transUnit == null) { return; } var destElement = XElement.Parse($"<{item.ElementName}/>"); var source = XElement.Parse("<AUni ws='en'/>"); var target = XElement.Parse($"<AUni ws='{targetLanguage}'/>"); source.Add(transUnit.Element("source")?.Value); var xliffTarget = transUnit.Element("target"); if (XliffUtils.IsTranslated(xliffTarget)) { target.Add(xliffTarget.Value); } destElement.Add(source); destElement.Add(target); listElement.Add(destElement); }
/// <param name="item"></param> /// <param name="ws"></param> /// <param name="citElt">The source or target element containing the citations</param> private static void AddCitations(XElement item, string ws, XElement citElt) { // Convert only source elements and properly-translated target elements if (citElt?.Name != Source && !XliffUtils.IsTranslated(citElt)) { return; } foreach (var citation in citElt.Value.Split(';').Where(citation => !string.IsNullOrEmpty(citation))) { item.Add(XElement.Parse( $"<{GoldEticToXliff.CitationMap.ElementName} ws='{ws}'>{citation}</{GoldEticToXliff.CitationMap.ElementName}>")); } }
private static void ConvertSourceAndTargetToRun(XElement astrTransUnit, XElement source, XElement target, string targetLanguage) { var xliffSource = astrTransUnit.Element("source"); var xliffTarget = astrTransUnit.Element("target"); var sourceRun = XElement.Parse("<Run ws='en'/>"); var targetRun = XElement.Parse($"<Run ws='{targetLanguage}'/>"); sourceRun.Add(xliffSource?.Value); if (XliffUtils.IsTranslated(xliffTarget)) { targetRun.Add(xliffTarget?.Value); } source.Add(sourceRun); target.Add(targetRun); }
private void AddItems(XElement target, Dictionary <string, XElement> sources) { var firstSource = sources.Values.First(); var firstSourceGroups = firstSource.Elements("group").ToList(); foreach (var kvp in sources.Where(kvp => firstSourceGroups.Count != kvp.Value.Elements("group").Count())) { var groupId = firstSource.Attribute("id")?.Value; var idMessage = groupId == null ? string.Empty : $" for {groupId}"; Log.LogError($"GOLD Etic for {kvp.Key} has a different number of items than {sources.Keys.First()}{idMessage}"); } foreach (var itemGroup in firstSourceGroups) { var groupId = itemGroup.Attribute("id").Value; var allSourcesGroups = sources.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Elements("group").FirstOrDefault(elt => elt.Attribute("id").Value == groupId)); var badSourceLangs = new List <string>(); foreach (var kvp in allSourcesGroups.Where(kvp => kvp.Value == null)) { Log.LogError($"GOLD Etic for {kvp.Key} does not contain {groupId}"); badSourceLangs.Add(kvp.Key); } // For now, ignore any bad files and see how far we get with others foreach (var badSourceLang in badSourceLangs) { allSourcesGroups.Remove(badSourceLang); } // These loops would look cleaner if languages were in the outer loop, but this is how the original GOLDEtic.xml // is organized. Hasso would not be opposed to inverting them now that everything is done and tested. var groupIdLength = groupId.Length; var groupIdParts = groupId.Split('_'); var itemElt = XElement.Parse($"<item type='category' id='{groupIdParts[1]}' guid='{groupIdParts[0]}'/>"); foreach (var eltMap in GoldEticToXliff.NormalEltMaps) { var englishValue = TransUnitFor(itemGroup, groupIdLength, eltMap).Element(Source).Value; itemElt.Add(XElement.Parse($"<{eltMap.ElementName} ws='{WsEn}'>{englishValue}</{eltMap.ElementName}>")); foreach (var kvp in allSourcesGroups) { var translationElt = TransUnitFor(kvp.Value, groupIdLength, eltMap).Element(Target); if (XliffUtils.IsTranslated(translationElt)) { itemElt.Add(XElement.Parse($"<{eltMap.ElementName} ws='{kvp.Key}'>{translationElt.Value}</{eltMap.ElementName}>")); } } } AddCitations(itemElt, WsEn, TransUnitFor(itemGroup, groupIdLength, GoldEticToXliff.CitationMap).Element(Source)); foreach (var kvp in allSourcesGroups) { AddCitations(itemElt, kvp.Key, TransUnitFor(kvp.Value, groupIdLength, GoldEticToXliff.CitationMap).Element(Target)); } // convert subitems AddItems(itemElt, allSourcesGroups); target.Add(itemElt); } }