Ejemplo n.º 1
0
 public JliffDocument ConvertXlf20(Stream stream)
 {
     try
     {
         JliffBuilder  builder       = new JliffBuilder("en", "fr");
         Xliff20Filter xliff20Filter = new Xliff20Filter();
         xliff20Filter.XlfRootEvent          += builder.XlfRoot;
         xliff20Filter.XlfFileEvent          += builder.File;
         xliff20Filter.XlfUnitEvent          += builder.Unit;
         xliff20Filter.XlfGroupEvent         += builder.Group;
         xliff20Filter.XlfSegmentEvent       += builder.Segment;
         xliff20Filter.XlfSourceEvent        += builder.Source;
         xliff20Filter.XlfTargetEvent        += builder.Target;
         xliff20Filter.XlfIgnorableEvent     += builder.Ignorable;
         xliff20Filter.XlfPhElementEvent     += builder.PhElement;
         xliff20Filter.XlfSkeletonEvent      += builder.Skeleton;
         xliff20Filter.XlfTextEvent          += builder.Text;
         xliff20Filter.XlfSmElementEvent     += builder.SmElement;
         xliff20Filter.XlfEmElementEvent     += builder.EmElement;
         xliff20Filter.XlfScElementEvent     += builder.ScElement;
         xliff20Filter.XlfEcElementEvent     += builder.EcElement;
         xliff20Filter.ModItsLocQualityIssue += builder.LocQualityIssue;
         xliff20Filter.Filter(new StreamReader(stream, Encoding.UTF8));
         return(builder.Jliff);
     }
     catch (Exception e)
     {
         throw new InvalidDataException();
     }
 }
Ejemplo n.º 2
0
        public void EnrichedXliff()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            sb.Append(
                "<xliff xmlns=\"urn:oasis:names:tc:xliff:document:2.0\" srcLang=\"en\" trgLang=\"fr\" version=\"2.0\">");
            sb.Append("<file id=\"f1\"><unit id=\"1\"><segment id=\"s1\"><source>");
            sb.Append("<mrk id=\"freme-7\" ref=\"http://freme-project.eu/#char=3,10\" type=\"term\">Text</mrk>");
            sb.Append(
                " in <sc dataRef=\"d1\" id=\"sc1\"/><mrk id=\"freme-8\" ref=\"http://freme-project.eu/#char=16,20\" type=\"term\">");
            sb.Append("bold</mrk> <sc dataRef=\"d2\" id=\"sc2\"/>");
            sb.Append(
                "      and<ec dataRef=\"d3\" startRef=\"sc1\"/> <mrk id=\"freme-9\" ref=\"http://freme-project.eu/#char=46,53\" type=\"term\">");
            sb.Append("italics</mrk><ec dataRef=\"d4\" startRef=\"sc2\"/>.");
            sb.Append(
                "</source><target>Text in <sc dataRef=\"d1\" id=\"sc1\"/>bold <sc dataRef=\"d2\" id=\"sc2\"/>\r\n     and<ec dataRef=\"d3\" startRef=\"sc1\"/> italics<ec dataRef=\"d4\" startRef=\"sc2\"/>.\r\n     </target>");
            sb.Append("</segment></unit></file></xliff>");

            JliffBuilder  builder = new JliffBuilder("en", "fr");
            TextReader    tr      = new StringReader(sb.ToString());
            Xliff20Filter filter  = new Xliff20Filter();

            filter.XlfFileEvent      += builder.File;
            filter.XlfUnitEvent      += builder.Unit;
            filter.XlfGroupEvent     += builder.Group;
            filter.XlfSegmentEvent   += builder.Segment;
            filter.XlfSourceEvent    += builder.Source;
            filter.XlfTargetEvent    += builder.Target;
            filter.XlfIgnorableEvent += builder.Ignorable;
            filter.XlfPhElementEvent += builder.PhElement;
            filter.XlfSkeletonEvent  += builder.Skeleton;
            filter.XlfTextEvent      += builder.Text;
            filter.XlfSmElementEvent += builder.SmElement;
            filter.XlfEmElementEvent += builder.EmElement;
            filter.XlfScElementEvent += builder.ScElement;
            filter.XlfEcElementEvent += builder.EcElement;
            filter.Filter(tr);
            builder.Serialize("ModelTest.json");
            JsonSchema schema  = JsonSchema.Parse(schemaDef);
            var        obGraph = JObject.FromObject(builder.Jliff);

            Assert.IsTrue(obGraph.IsValid(schema));
            Unit unit = builder.Jliff.Files[0].Subfiles[0] as Unit;

            Assert.IsNotNull(unit);
            Segment segment = unit.Subunits[0] as Segment;

            Assert.IsNotNull(segment);
            SmElement smElement = segment.Source[11] as SmElement;

            Assert.IsNotNull(smElement);
            Assert.AreEqual("freme-9", smElement.Id);
            Assert.AreEqual("term", smElement.Type);
        }
Ejemplo n.º 3
0
        public void XlfWithModules()
        {
            JliffBuilder  bldr = new JliffBuilder("en-US", "it-IT");
            Xliff20Filter fltr = new Xliff20Filter();

            fltr.XlfRootEvent            += bldr.XlfRoot;
            fltr.XlfFileEvent            += bldr.File;
            fltr.XlfUnitEvent            += bldr.Unit;
            fltr.XlfGroupEvent           += bldr.Group;
            fltr.XlfSegmentEvent         += bldr.Segment;
            fltr.XlfSourceEvent          += bldr.Source;
            fltr.XlfTargetEvent          += bldr.Target;
            fltr.XlfIgnorableEvent       += bldr.Ignorable;
            fltr.XlfPhElementEvent       += bldr.PhElement;
            fltr.XlfSkeletonEvent        += bldr.Skeleton;
            fltr.XlfTextEvent            += bldr.Text;
            fltr.XlfSmElementEvent       += bldr.SmElement;
            fltr.XlfEmElementEvent       += bldr.EmElement;
            fltr.XlfScElementEvent       += bldr.ScElement;
            fltr.XlfEcElementEvent       += bldr.EcElement;
            fltr.XlfOriginalDataEvent    += bldr.OriginalData;
            fltr.ModItsLocQualityIssues  += bldr.LocQualityIssues;
            fltr.ModItsLocQualityIssue   += bldr.LocQualityIssue;
            fltr.ModMetadataEvent        += bldr.Metadata;
            fltr.ModMetaGroupEvent       += bldr.MetaGroup;
            fltr.ModMetaitemEvent        += bldr.Metaitem;
            fltr.ModResResourceDataEvent += bldr.ResourceData;
            fltr.ModResResourceItemEvent += bldr.ResourceItem;
            fltr.ModResSourceEvent       += bldr.ResourceSource;
            fltr.ModGlsEntryEvent        += bldr.GlossaryEntry;
            fltr.ModGlsDefinitionEvent   += bldr.Definition;
            fltr.ModGlsTermEvent         += bldr.Term;
            fltr.ModGlsTranslationEvent  += bldr.Translation;
            fltr.ModTransCandMatchEvent  += bldr.Match;
            fltr.ModCtrChangeTrackEvent  += bldr.ChangeTrack;
            fltr.ModCtrRevisionsEvent    += bldr.Revisions;
            fltr.ModCtrRevisionEvent     += bldr.Revision;
            fltr.ModCtrRevisionItemEvent += bldr.RevisionItem;
            fltr.Filter(new StreamReader(Path.Combine(XlfFiles, "Ocelot.xlf")));
            bldr.Serialize(Path.Combine(XlfFiles, "Ocelot.json"));
            JsonSchema schema  = JsonSchema.Parse(schemaDef);
            var        obGraph = JObject.FromObject(bldr.Jliff);

            Assert.IsTrue(obGraph.IsValid(schema));

            JliffDocument jd  = Converter.Deserialize(new FileInfo(Path.Combine(XlfFiles, "Ocelot.json")));
            Group         grp = jd.Files[0].Subfiles[1] as Group;
            Unit          u   = grp.Subgroups[1] as Unit;
            ChangeTrack   ct  = u.ChangeTrack;

            Assert.IsNotNull(ct);
            Assert.IsTrue(ct.Revisions.Items[1].Author.Equals("phil"));
            Assert.IsTrue(ct.Revisions.Items[1].Item.Text.StartsWith("Quando un segmento è selezionato nella Vista segmento"));
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            JliffBuilder  builder       = new JliffBuilder("en", "fr");
            Xliff20Filter xliff20Filter = new Xliff20Filter();

            xliff20Filter.XlfRootEvent          += builder.XlfRoot;
            xliff20Filter.XlfFileEvent          += builder.File;
            xliff20Filter.XlfUnitEvent          += builder.Unit;
            xliff20Filter.XlfGroupEvent         += builder.Group;
            xliff20Filter.XlfSegmentEvent       += builder.Segment;
            xliff20Filter.XlfSourceEvent        += builder.Source;
            xliff20Filter.XlfTargetEvent        += builder.Target;
            xliff20Filter.XlfIgnorableEvent     += builder.Ignorable;
            xliff20Filter.XlfPhElementEvent     += builder.PhElement;
            xliff20Filter.XlfSkeletonEvent      += builder.Skeleton;
            xliff20Filter.XlfTextEvent          += builder.Text;
            xliff20Filter.XlfSmElementEvent     += builder.SmElement;
            xliff20Filter.XlfEmElementEvent     += builder.EmElement;
            xliff20Filter.XlfScElementEvent     += builder.ScElement;
            xliff20Filter.XlfEcElementEvent     += builder.EcElement;
            xliff20Filter.ModItsLocQualityIssue += builder.LocQualityIssue;
            DirectoryInfo output = new DirectoryInfo(Directory.GetCurrentDirectory());

            for (int i = 0; i < 1; i++)
            {
                output = Directory.GetParent(output.FullName);
            }
            //xliff20Filter.Filter(new StreamReader(Path.Combine($"{output}\\Jliff.Tests\\XlfFiles", "everything-core.xlf")));
            xliff20Filter.Filter(new StreamReader(@"e:\ExtDev\DotNet\JliffGraphTools\Jliff.Tests\XlfFiles\LQE_xliff_2.0.xlf"));
            builder.Serialize("XliffToJliff.json");


            JliffBuilder  bldr          = new JliffBuilder("en", "fr");
            Xliff12Filter xliff12Filter = new Xliff12Filter();

            xliff12Filter.XlfRootEvent          += bldr.XlfRoot;
            xliff12Filter.XlfFileEvent          += bldr.File;
            xliff12Filter.XlfUnitEvent          += bldr.Unit;
            xliff12Filter.XlfGroupEvent         += bldr.Group;
            xliff12Filter.XlfSegmentEvent       += bldr.Segment;
            xliff12Filter.XlfSourceEvent        += bldr.Source;
            xliff12Filter.XlfTargetEvent        += bldr.Target;
            xliff12Filter.XlfIgnorableEvent     += bldr.Ignorable;
            xliff12Filter.XlfPhElementEvent     += bldr.PhElement;
            xliff12Filter.XlfSkeletonEvent      += bldr.Skeleton;
            xliff12Filter.XlfTextEvent          += bldr.Text;
            xliff12Filter.XlfSmElementEvent     += bldr.SmElement;
            xliff12Filter.XlfEmElementEvent     += bldr.EmElement;
            xliff12Filter.XlfScElementEvent     += bldr.ScElement;
            xliff12Filter.XlfEcElementEvent     += bldr.EcElement;
            xliff12Filter.ModItsLocQualityIssue += bldr.LocQualityIssue;
            DirectoryInfo output2 = new DirectoryInfo(Directory.GetCurrentDirectory());

            for (int i = 0; i < 1; i++)
            {
                output2 = Directory.GetParent(output2.FullName);
            }
            //xliff12Filter.Filter(new StreamReader(Path.Combine($"{output}\\Jliff.Tests\\XlfFiles", "everything-core.xlf")));
            xliff12Filter.Filter(new StreamReader(@"e:\ExtDev\DotNet\JliffGraphTools\Jliff.Tests\XlfFiles\ocelot12.xlf"));
            bldr.Serialize("Xliff12ToJliff.json");
        }