mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Remove .Net Core 1.0 requirement for Loc and fix mac build (#841)
* Remove .Net Core 1.0 requirement for Loc and fix mac build Use StringResourceTool to remove .Net Core 1.0 dependency for Loc Fixed Mac build by copying the code used in internal repo for build. - This now mostly matches internal, so expect this should work OK.
This commit is contained in:
Binary file not shown.
163
build.cake
163
build.cake
@@ -554,87 +554,106 @@ Task("SetPackageVersions")
|
|||||||
Task("SRGen")
|
Task("SRGen")
|
||||||
.Does(() =>
|
.Does(() =>
|
||||||
{
|
{
|
||||||
var projects = System.IO.Directory.GetFiles(sourceFolder, "*.csproj", SearchOption.AllDirectories).ToList();
|
// save current working directory to restore at end of task
|
||||||
var locTemplateDir = System.IO.Path.Combine(sourceFolder, "../localization");
|
var taskStartedWorkingDirectory = System.IO.Directory.GetCurrentDirectory();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var projects = System.IO.Directory.GetFiles(sourceFolder, "*.csproj", SearchOption.AllDirectories).ToList();
|
||||||
|
var locTemplateDir = System.IO.Path.Combine(sourceFolder, "../localization");
|
||||||
|
|
||||||
foreach(var project in projects) {
|
foreach(var project in projects) {
|
||||||
var projectDir = System.IO.Path.GetDirectoryName(project);
|
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");
|
|
||||||
|
|
||||||
if (!System.IO.File.Exists(projectStrings))
|
// set current directory to this project so relative paths can be reliably
|
||||||
{
|
// used. This is to address an issue with quoting differences between Windows
|
||||||
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
|
// and MacOS. On MacOS the dotnet command ends up calling SRGen with quotations around
|
||||||
continue;
|
// the arguments stripped off. This causes SRGen to interpret the arg values as options
|
||||||
}
|
System.IO.Directory.SetCurrentDirectory(projectDir);
|
||||||
|
|
||||||
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.DataTools.SrGen", "lib", "netcoreapp1.0", "srgen.dll");
|
// build remaining paths relative to the project directory
|
||||||
var outputResx = System.IO.Path.Combine(localizationDir, "sr.resx");
|
var localizationDir = System.IO.Path.Combine(".", "Localization");
|
||||||
var inputXliff = System.IO.Path.Combine(localizationDir, "transXliff");
|
var projectName = (new System.IO.DirectoryInfo(projectDir)).Name;
|
||||||
var outputXlf = System.IO.Path.Combine(localizationDir, "sr.xlf");
|
var projectNameSpace = projectName + ".Localization";
|
||||||
var outputCs = System.IO.Path.Combine(localizationDir, "sr.cs");
|
var projectStrings = System.IO.Path.Combine(localizationDir, "sr.strings");
|
||||||
|
|
||||||
// Delete preexisting resx and designer files
|
if (!System.IO.File.Exists(projectStrings))
|
||||||
if (System.IO.File.Exists(outputResx))
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(outputResx);
|
|
||||||
}
|
|
||||||
if (System.IO.File.Exists(outputCs))
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(outputCs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!System.IO.Directory.Exists(inputXliff))
|
|
||||||
{
|
|
||||||
System.IO.Directory.CreateDirectory(inputXliff);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
var outputXlfFile = doc.Files.Single();
|
|
||||||
foreach (var unit in outputXlfFile.TransUnits)
|
|
||||||
{
|
|
||||||
unit.Target = unit.Source;
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
// load our language XLIFF
|
|
||||||
var xlfDoc = new XliffParser.XlfDocument(docName);
|
|
||||||
var xlfFile = xlfDoc.Files.Single();
|
|
||||||
|
|
||||||
// load a language template
|
|
||||||
var templateFileLocation = System.IO.Path.Combine(locTemplateDir, System.IO.Path.GetFileName(docName) + ".template");
|
|
||||||
var templateDoc = new XliffParser.XlfDocument(templateFileLocation);
|
|
||||||
var templateFile = templateDoc.Files.Single();
|
|
||||||
|
|
||||||
// iterate through our tranlation units and prune invalid units
|
|
||||||
foreach (var unit in xlfFile.TransUnits)
|
|
||||||
{
|
{
|
||||||
// if a unit does not have a target it is invalid
|
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
|
||||||
if (unit.Target != null) {
|
continue;
|
||||||
templateFile.AddTransUnit(unit.Id, unit.Source, unit.Target, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// export modified template to RESX
|
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.Data.Tools.StringResourceTool", "tools", "netcoreapp2.2", "any", "srgen.dll");
|
||||||
var newPath = System.IO.Path.Combine(localizationDir, System.IO.Path.GetFileName(docName));
|
var outputResx = System.IO.Path.Combine(localizationDir, "sr.resx");
|
||||||
templateDoc.SaveAsResX(newPath.Replace("xlf","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");
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!System.IO.Directory.Exists(inputXliff))
|
||||||
|
{
|
||||||
|
System.IO.Directory.CreateDirectory(inputXliff);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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}", dotnetcli);
|
||||||
|
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();
|
||||||
|
var outputXlfFile = doc.Files.Single();
|
||||||
|
foreach (var unit in outputXlfFile.TransUnits)
|
||||||
|
{
|
||||||
|
unit.Target = unit.Source;
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// load our language XLIFF
|
||||||
|
var xlfDoc = new XliffParser.XlfDocument(docName);
|
||||||
|
var xlfFile = xlfDoc.Files.Single();
|
||||||
|
|
||||||
|
// load a language template
|
||||||
|
var templateFileLocation = System.IO.Path.Combine(locTemplateDir, System.IO.Path.GetFileName(docName) + ".template");
|
||||||
|
var templateDoc = new XliffParser.XlfDocument(templateFileLocation);
|
||||||
|
var templateFile = templateDoc.Files.Single();
|
||||||
|
|
||||||
|
// iterate through our tranlation units and prune invalid units
|
||||||
|
foreach (var unit in xlfFile.TransUnits)
|
||||||
|
{
|
||||||
|
// if a unit does not have a target it is invalid
|
||||||
|
if (unit.Target != null) {
|
||||||
|
templateFile.AddTransUnit(unit.Id, unit.Source, unit.Target, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// export modified template to RESX
|
||||||
|
var newPath = System.IO.Path.Combine(localizationDir, System.IO.Path.GetFileName(docName));
|
||||||
|
templateDoc.SaveAsResX(newPath.Replace("xlf","resx"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// restore the original working directory
|
||||||
|
System.IO.Directory.SetCurrentDirectory(taskStartedWorkingDirectory);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#load "runhelpers.cake"
|
#load "runhelpers.cake"
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Cake" version="0.17.0" />
|
<package id="Cake" version="0.30.0" />
|
||||||
<package id="Newtonsoft.Json" version="8.0.3" />
|
<package id="Newtonsoft.Json" version="9.0.1" />
|
||||||
<package id="Microsoft.DataTools.SrGen" version="1.0.2" />
|
<package id="Microsoft.Data.Tools.StringResourceTool" version="1.0.0" />
|
||||||
<package id="Mono.TextTransform" version="1.0.0" />
|
<package id="Mono.TextTransform" version="1.0.0" />
|
||||||
<package id="mssql.XliffParser" version="0.5.3" />
|
<package id="mssql.XliffParser" version="0.5.3" />
|
||||||
|
<package id="mssql.ResX" version="0.2.0" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user