Exemple #1
0
        public static new PropertyContainer FromXliff(TranslationContainer xliffUnit)
        {
            var unit = xliffUnit as Unit;

            //TODO: Add test for this condition
            if (unit.Resources.Count > 1)
            {
                throw new InvalidOperationException("Error on unit " + unit.SelectorPath + ": Cannot operate on multiple segments. Make sure previous steps of the import have merged all segments into one.");
            }
            var segment = unit.Resources[0] as Segment;

            //TODO: Add test for this condition
            if (segment.Target == null || segment.Target.Text == null || segment.Target.Text.Count == 0)
            {
                throw new InvalidOperationException("Unit " + unit.SelectorPath + " doesn't have a target: cannot import.");
            }

            //TODO: Add test for this condition
            if (segment.Target.Text.Count > 1)
            {
                throw new InvalidOperationException("Error on unit " + unit.SelectorPath + ": Cannot operate on target with multiple elements. Make sure previous steps have converted all inline markup into a CData section");
            }

            string textValue = string.Empty;
            var    text      = segment.Target.Text[0] as PlainText;

            if (text != null)
            {
                textValue = text.Text;
            }

            var html = segment.Target.Text[0] as CDataTag;

            if (html != null)
            {
                textValue = html.Text;
            }

            if (!String.IsNullOrWhiteSpace(textValue))
            {
                var property = new Property(unit.Name, textValue);
                if (unit.Metadata != null)
                {
                    property.Attributes = AttributeList.FromXliffMetadata(unit.Metadata);
                }
                return(property);
            }


            //TODO: Add test for this condition
            return(null);
        }
Exemple #2
0
        public static Document FromXliff(File file)
        {
            var document = new Document();

            document.SourceIdentifier = file.Original;
            if (file.Metadata != null)
            {
                document.Attributes = AttributeList.FromXliffMetadata(file.Metadata);
            }

            foreach (var container in file.Containers)
            {
                var propertyContainer = PropertyContainer.FromXliff(container);
                if (propertyContainer != null)
                {
                    document.Containers.Add(propertyContainer);
                }
            }

            return(document);
        }
Exemple #3
0
        public static new PropertyContainer FromXliff(TranslationContainer xliffGroup)
        {
            var group         = xliffGroup as Group;
            var propertyGroup = new PropertyGroup(xliffGroup.Name);

            if (group.Metadata != null)
            {
                propertyGroup.Attributes = AttributeList.FromXliffMetadata(group.Metadata);
            }

            foreach (var container in group.Containers)
            {
                var property = PropertyContainer.FromXliff(container);
                if (property != null)
                {
                    propertyGroup.Containers.Add(property);
                }
            }

            return(propertyGroup);
        }
Exemple #4
0
 public ContentElement()
 {
     Attributes = new AttributeList();
 }