private static string Sort(string xliff)
        {
            var xliffDocument = new XlfDocument();

            xliffDocument.Load(new StringReader(xliff));

            xliffDocument.Sort();

            var writer = new StringWriter();

            xliffDocument.Save(writer);
            return(writer.ToString());
        }
Beispiel #2
0
        public override bool Execute()
        {
            var xlfDocument = new XlfDocument(XlfPath);
            Tuple<int, int, int> result = xlfDocument.UpdateFromResX(ResxPath);

            Log.LogMessage(MessageImportance.Low,
                "Update results:" +
                $"\n\t{result.Item1} resources updated" +
                $"\n\t{result.Item2} resources added" +
                $"\n\t{result.Item3} resources deleted");

            xlfDocument.Save();

            return !Log.HasLoggedErrors;
        }
Beispiel #3
0
        public override bool Execute()
        {
            var xlfDocument = new XlfDocument(XlfPath);
            var result      = xlfDocument.Update(ResxPath, "updated", "new");

            Log.LogMessage(MessageImportance.Low,
                           "Update results:" +
                           $"\n\t{result.UpdatedItems} resources updated" +
                           $"\n\t{result.AddedItems} resources added" +
                           $"\n\t{result.RemovedItems} resources deleted");

            xlfDocument.Save();

            return(!Log.HasLoggedErrors);
        }
Beispiel #4
0
        public override bool Execute()
        {
            var xlfDocument = new XlfDocument(XlfPath);
            Tuple <int, int, int> result = xlfDocument.UpdateFromResX(ResxPath);

            Log.LogMessage(MessageImportance.Low,
                           "Update results:" +
                           $"\n\t{result.Item1} resources updated" +
                           $"\n\t{result.Item2} resources added" +
                           $"\n\t{result.Item3} resources deleted");

            xlfDocument.Save();

            return(!Log.HasLoggedErrors);
        }
Beispiel #5
0
        public override bool Execute()
        {
            var xlfDocument = new XlfDocument(XlfPath);
            var result = xlfDocument.Update(ResxPath, "updated", "new");

            Log.LogMessage(MessageImportance.Low,
                "Update results:" +
                $"\n\t{result.UpdatedItems} resources updated" +
                $"\n\t{result.AddedItems} resources added" +
                $"\n\t{result.RemovedItems} resources deleted");

            xlfDocument.Save();

            return !Log.HasLoggedErrors;
        }
Beispiel #6
0
        private static void ConvertResxToXlf(string resxFile, string xlfDirectory, string originalFile)
        {
            bool   madeNeutral      = false;
            string originalFileName = Path.GetFileName(originalFile);

            if (Path.GetExtension(originalFileName) == ".resx")
            {
                // Make common case of resx original file implicit, but don't remove other extensions
                // or else a .resx and .vsct with the same name will collide.
                originalFileName = Path.GetFileNameWithoutExtension(originalFileName);
            }

            if (!Directory.Exists(xlfDirectory))
            {
                Directory.CreateDirectory(xlfDirectory);
            }

            foreach (var language in s_languages)
            {
                string xlfFile = Path.Combine(xlfDirectory, $"{originalFileName}.{language}.xlf");
                if (!File.Exists(xlfFile))
                {
                    string originalFileId = MakeOriginalFileId(originalFile);

                    File.WriteAllText(xlfFile,
                                      $@"<?xml version=""1.0"" encoding=""utf-8""?>
<xliff xmlns=""urn:oasis:names:tc:xliff:document:1.2"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" version=""1.2"" xsi:schemaLocation=""urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd"">
  <file datatype=""xml"" source-language=""en"" target-language=""{language}"" original=""{originalFileId}"">
    <body>
      <group id=""{originalFileId}"" />
    </body>
  </file>
</xliff>");
                }

                var xlfDocument = new XlfDocument(xlfFile);
                xlfDocument.Update(resxFile, updatedResourceStateString: "needs-review-translation", addedResourceStateString: "new");
                xlfDocument.Save();

                if (!madeNeutral)
                {
                    MakeNeutral(xlfFile, Path.Combine(xlfDirectory, $"{originalFileName}.xlf"));
                    madeNeutral = true;
                }
            }
        }
        private void UpdateXlfFile(XlfDocument doc, List <ResXEntry> sourceFile)
        {
            var xlfFile = doc.Files.Single();
            Dictionary <string, XlfTransUnit> existingUnits = xlfFile.TransUnits.ToDictionary(i => i.Id, i => i);
            bool modified = false;

            foreach (var source in sourceFile)
            {
                if (existingUnits.TryGetValue(source.Id, out XlfTransUnit existing))
                {
                    // Exists, see if we need to update it
                    if (source.Value != existing.Source)
                    {
                        existing.Source      = source.Value;
                        existing.TargetState = XlfTransUnit.TargetState_New;
                        modified             = true;
                    }

                    // Remove it since we processed it
                    existingUnits.Remove(source.Id);
                }
                else
                {
                    // Doesn't exist, need to create it
                    xlfFile.AddTransUnit(source.Id, source.Value, source.Value, XlfFile.AddMode.DontCheckExisting, XlfDialect.MultilingualAppToolkit);
                    existingUnits.Remove(source.Id);
                    modified = true;
                }
            }

            if (existingUnits.Count > 0)
            {
                // Need to remove no-longer-used translations
                foreach (var existing in existingUnits.Values)
                {
                    existing.Remove();
                }

                modified = true;
            }

            if (modified)
            {
                doc.Save();
            }
        }
Beispiel #8
0
        public void LoadNewInitializesNewDocumentWithCorrectContent()
        {
            var xliffDocument = new XlfDocument();

            xliffDocument.LoadNew("es");

            var writer = new StringWriter();

            xliffDocument.Save(writer);

            string expected =
                @"<xliff xmlns=""urn:oasis:names:tc:xliff:document:1.2"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" version=""1.2"" xsi:schemaLocation=""urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd"">
  <file datatype=""xml"" source-language=""en"" target-language=""es"" original=""_"">
    <body />
  </file>
</xliff>";

            Assert.Equal(expected, writer.ToString());
        }
Beispiel #9
0
        private static string Update(string xliff, string resx)
        {
            var xliffDocument = new XlfDocument();

            if (string.IsNullOrEmpty(xliff))
            {
                xliffDocument.LoadNew("fr");
            }
            else
            {
                xliffDocument.Load(new StringReader(xliff));
            }

            var resxDocument = new ResxDocument();

            resxDocument.Load(new StringReader(resx));
            xliffDocument.Update(resxDocument, "test.resx");

            var writer = new StringWriter();

            xliffDocument.Save(writer);
            return(writer.ToString());
        }