public JliffBuilder(string srcLang, string trgLang)
        {
            CreateMaps();

            jliff = new JliffDocument(srcLang, trgLang);
            stack.Push(jliff);
        }
        public static string Serialize(JliffDocument model)
        {
            var set = new JsonSerializerSettings();

            set.ContractResolver     = new CamelCasePropertyNamesContractResolver();
            set.Formatting           = Formatting.Indented;
            set.NullValueHandling    = NullValueHandling.Ignore;
            set.DefaultValueHandling = DefaultValueHandling.Ignore;
            set.Converters.Add(new ISubfileConverter());
            set.Converters.Add(new ISubunitConverter());
            set.Converters.Add(new IElementConverter());
            set.Converters.Add(new IMetadataConverter());

            var output = JsonConvert.SerializeObject(model, set);

            return(output);
        }
Exemple #3
0
        public void Core()
        {
            var f = new List <JlGraph.IElement>();


            JlGraph.JliffDocument jliff = new JlGraph.JliffDocument("en", "fr",
                                                                    new JlGraph.File("f1",
                                                                                     new JlGraph.Unit("tu1",
                                                                                                      new JlGraph.Segment(
                                                                                                          new JlGraph.TextElement("Sample segment."),
                                                                                                          new JlGraph.TextElement("Exemple de segment.")
                                                                                                          ),
                                                                                                      new JlGraph.Ignorable(
                                                                                                          new JlGraph.TextElement("")
                                                                                                          ),
                                                                                                      new JlGraph.Segment(
                                                                                                          new JlGraph.TextElement("Segment's content."),
                                                                                                          new JlGraph.TextElement("Contenu du segment.")
                                                                                                          )
                                                                                                      ),
                                                                                     new JlGraph.Group("g1",
                                                                                                       new JlGraph.Unit("tu3",
                                                                                                                        new JlGraph.Segment(
                                                                                                                            new JlGraph.TextElement("Bolded text"),
                                                                                                                            new JlGraph.TextElement("")
                                                                                                                            )
                                                                                                                        ),
                                                                                                       new JlGraph.Unit("tu3end",
                                                                                                                        new JlGraph.Segment(
                                                                                                                            new JlGraph.TextElement("Extra stuff")
                                                                                                                            )
                                                                                                                        ),
                                                                                                       new JlGraph.Unit("tu2")
                                                                                                       )
                                                                                     )
                                                                    );

            JlGraph.Group g1 = jliff.Files[0].Subfiles[1] as JlGraph.Group;
            if (g1 != null)
            {
                g1.CanResegment = "yes";
            }

            JlGraph.Unit tu2 = g1.Subgroups[2] as JlGraph.Unit;
            if (tu2 != null)
            {
                tu2.OriginalData.Add("d1", "[b [#$tu3]   ]");
                tu2.OriginalData.Add("d2", "[/b [#t3end]   ]");
                tu2.OriginalData.Add("d3", "[rtl-data   ]");
            }

            JlGraph.Segment         s1       = new JlGraph.Segment("s1");
            List <JlGraph.IElement> s1Source = new List <JlGraph.IElement>();

            tu2.Subunits.Add(s1);
            s1.Source = s1Source;

            var dllPath    = Assembly.GetAssembly(typeof(ModelTests)).Location;
            var dllName    = Assembly.GetAssembly(typeof(ModelTests)).GetName().Name;
            var outputPath = dllPath.Replace(dllName + ".dll", "");


            JlGraph.Converter.Serialize(Path.Combine(outputPath, "everything-core.json"), jliff);

            JsonSchema schema  = JsonSchema.Parse(schemaDef);
            var        obGraph = JObject.FromObject(jliff);

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