Beispiel #1
0
        private static void ConvertToMultiRunString(XElement group, XElement listElement, string targetLanguage, ConversionMap item)
        {
            var id       = group.Attribute("id")?.Value + item.IdSuffix;
            var subGroup = group.Elements("group").FirstOrDefault(g => g.Attribute("id") != null && g.Attribute("id").Value == id);

            if (subGroup == null)
            {
                return;
            }
            var elements = subGroup.Elements(XliffUtils.TransUnit).Where(tu => tu.Attribute("id")?.Value.StartsWith(id) ?? false);

            // ReSharper disable PossibleMultipleEnumeration
            if (elements.Any())
            {
                var element = XElement.Parse($"<{item.ElementName}/>");
                var source  = XElement.Parse("<AStr ws='en'/>");
                var target  = XElement.Parse($"<AStr ws='{targetLanguage}'/>");
                element.Add(source);
                element.Add(target);
                foreach (var transUnit in elements)
                {
                    ConvertSourceAndTargetToRun(transUnit, source, target, targetLanguage);
                }
                listElement.Add(element);
            }
            // ReSharper restore PossibleMultipleEnumeration
        }
Beispiel #2
0
        private static void ConvertAUniToXliff(XElement list, XElement group, string baseId, ConversionMap item, string targetLang)
        {
            var sourceElem = list.Element(item.ElementName);
            var source     = sourceElem?.Elements("AUni").First().Value;

            if (string.IsNullOrWhiteSpace(source))
            {
                return;
            }
            var transUnit = XElement.Parse(string.Format(XliffUtils.TransUnitTemplate, baseId + item.IdSuffix, SecurityElement.Escape(source)));

            if (targetLang != null)
            {
                var target = sourceElem.XPathSelectElement($"AUni[@ws='{targetLang}']")?.Value;
                if (!string.IsNullOrWhiteSpace(target))
                {
                    transUnit.Add(XElement.Parse(string.Format(XliffUtils.FinalTargetTemplate, SecurityElement.Escape(target))));
                }
            }
            group.Add(transUnit);
        }
Beispiel #3
0
        private static void ConvertAStrToXliff(XElement owner, XElement ownerGroup, string possId, ConversionMap item, string targetLang)
        {
            var itemNode = owner.Element(item.ElementName);
            var source   = AStrValue(itemNode?.Element("AStr"));

            if (string.IsNullOrWhiteSpace(source))             // nothing to translate
            {
                return;
            }
            var target = targetLang == null ? null : AStrValue(itemNode?.XPathSelectElement($"AStr[@ws='{targetLang}']"));

            // 2020.02: Yes, conflating all runs into a single trans-unit loses some information, but we have only one string in our lists
            // with multiple runs, and it is a royal pain to translate. In fact, no previous translators have bothered preserving run breaks.
            // The run is in a subgroup all by itself because we started by preserving runs, and we didn't feel like removing the extra group.
            var groupId   = possId + item.IdSuffix;
            var groupNode = XElement.Parse(string.Format(XliffUtils.EmptyGroup, groupId));
            var transUnit = XElement.Parse(string.Format(XliffUtils.TransUnitTemplate, groupId + "_0", SecurityElement.Escape(source)));

            if (!string.IsNullOrWhiteSpace(target))
            {
                transUnit.Add(XElement.Parse(string.Format(XliffUtils.FinalTargetTemplate, SecurityElement.Escape(target))));
            }
            groupNode.Add(transUnit);
            ownerGroup.Add(groupNode);
        }
Beispiel #4
0
 private static XElement TransUnitFor(XElement itemGroup, int idBaseLength, ConversionMap eltMap)
 {
     return(itemGroup.Elements("trans-unit").First(e => e.Attribute("id").Value.Substring(idBaseLength) == eltMap.IdSuffix));
 }