Task: RESX and XLIFF transformations (#237)

* organizing files and adding to cake script

* temp gitignore change

* custom nuget packages

* reapplying git ignore

* fixing indents

* more weird indents

* fixing spacing in strings file

* updating xlf
This commit is contained in:
Raymond Martin
2017-02-15 12:11:37 -08:00
committed by GitHub
parent ab225efe98
commit 22eafbe597
13 changed files with 588 additions and 32 deletions

View File

@@ -1,4 +1,6 @@
#addin "Newtonsoft.Json"
#addin "mssql.ResX"
#addin "mssql.XliffParser"
#load "scripts/runhelpers.cake"
#load "scripts/archiving.cake"
@@ -9,7 +11,8 @@ using System.ComponentModel;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Cake.Common.IO
using Cake.Common.IO;
using XliffParser;
// Basic arguments
var target = Argument("target", "Default");
@@ -510,39 +513,58 @@ Task("SetPackageVersions")
Task("SRGen")
.Does(() =>
{
var projects = System.IO.Directory.GetFiles(sourceFolder, "project.json", SearchOption.AllDirectories).ToList();
foreach(var project in projects) {
var projectDir = System.IO.Path.GetDirectoryName(project);
var projectName = (new System.IO.DirectoryInfo(projectDir)).Name;
var projectStrings = System.IO.Path.Combine(projectDir, "sr.strings");
var projects = System.IO.Directory.GetFiles(sourceFolder, "project.json", SearchOption.AllDirectories).ToList();
if (!System.IO.File.Exists(projectStrings))
{
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
continue;
}
foreach(var project in projects) {
var projectDir = System.IO.Path.GetDirectoryName(project);
var localizationDir = System.IO.Path.Combine(projectDir, "Localization");
var projectName = (new System.IO.DirectoryInfo(projectDir)).Name;
var projectNameSpace = projectName + ".Localization";
var projectStrings = System.IO.Path.Combine(localizationDir, "sr.strings");
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.DataTools.SrGen", "lib", "netcoreapp1.0", "srgen.dll");
var outputResx = System.IO.Path.Combine(projectDir, "sr.resx");
var outputCs = System.IO.Path.Combine(projectDir, "sr.cs");
if (!System.IO.File.Exists(projectStrings))
{
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
continue;
}
// Delete preexisting resx and designer files
if (System.IO.File.Exists(outputResx))
{
System.IO.File.Delete(outputResx);
}
if (System.IO.File.Exists(outputCs))
{
System.IO.File.Delete(outputCs);
}
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.DataTools.SrGen", "lib", "netcoreapp1.0", "srgen.dll");
var outputResx = System.IO.Path.Combine(localizationDir, "sr.resx");
var inputXliff = System.IO.Path.Combine(localizationDir, "transXliff");
var outputXlf = System.IO.Path.Combine(localizationDir, "sr.xlf");
var outputCs = System.IO.Path.Combine(localizationDir, "sr.cs");
// Run SRGen
var dotnetArgs = string.Format("{0} -or \"{1}\" -oc \"{2}\" -ns \"{3}\" -an \"{4}\" -cn SR -l CS -dnx \"{5}\"",
srgenPath, outputResx, outputCs, projectName, projectName, projectStrings);
Information("{0}", dotnetArgs);
Run(dotnetcli, dotnetArgs)
.ExceptionOnError("Failed to run SRGen.");
}
// Delete preexisting resx and designer files
if (System.IO.File.Exists(outputResx))
{
System.IO.File.Delete(outputResx);
}
if (System.IO.File.Exists(outputCs))
{
System.IO.File.Delete(outputCs);
}
// Run SRGen
var dotnetArgs = string.Format("{0} -or \"{1}\" -oc \"{2}\" -ns \"{3}\" -an \"{4}\" -cn SR -l CS -dnx \"{5}\"",
srgenPath, outputResx, outputCs, projectName, projectNameSpace, projectStrings);
Information("{0}", dotnetArgs);
Run(dotnetcli, dotnetArgs)
.ExceptionOnError("Failed to run SRGen.");
// Update XLF file from new Resx file
var doc = new XliffParser.XlfDocument(outputXlf);
doc.UpdateFromSource();
doc.Save();
// Update ResX files from new xliff files
var xlfDocNames = System.IO.Directory.GetFiles(inputXliff, "*.xlf", SearchOption.AllDirectories).ToList();
foreach(var docName in xlfDocNames)
{
var xlfDoc = new XliffParser.XlfDocument(docName);
var newPath = System.IO.Path.Combine(localizationDir, System.IO.Path.GetFileName(docName));
xlfDoc.SaveAsResX(newPath.Replace("xlf","resx"));
}
}
});
/// <summary>