diff --git a/bin/mssql.ResX.nupkg b/bin/mssql.ResX.nupkg new file mode 100644 index 00000000..0012be07 Binary files /dev/null and b/bin/mssql.ResX.nupkg differ diff --git a/bin/mssql.XliffParser.nupkg b/bin/mssql.XliffParser.nupkg new file mode 100644 index 00000000..dbae7fbf Binary files /dev/null and b/bin/mssql.XliffParser.nupkg differ diff --git a/build.cake b/build.cake index 595c7818..9005628b 100644 --- a/build.cake +++ b/build.cake @@ -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")); + } + } }); /// diff --git a/scripts/cake-bootstrap.ps1 b/scripts/cake-bootstrap.ps1 index 7f0bc382..a6e34175 100644 --- a/scripts/cake-bootstrap.ps1 +++ b/scripts/cake-bootstrap.ps1 @@ -89,6 +89,7 @@ if(-Not $SkipToolPackageRestore.IsPresent) Set-Location $TOOLS_DIR Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetConfig = Invoke-Expression "&`"$NUGET_EXE`" config -configfile ../nuget.config" $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install $PACKAGES_CONFIG -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" Write-Verbose -Message ($NuGetOutput | out-string) diff --git a/scripts/cake-bootstrap.sh b/scripts/cake-bootstrap.sh index abc3ed43..6d8f0664 100644 --- a/scripts/cake-bootstrap.sh +++ b/scripts/cake-bootstrap.sh @@ -48,6 +48,7 @@ fi # Restore tools from NuGet. pushd "$TOOLS_DIR" >/dev/null +mono "$NUGET_EXE" config -configfile ../nuget.config mono "$NUGET_EXE" install "$PACKAGES_CONFIG" -ExcludeVersion -OutputDirectory "$TOOLS_DIR" if [ $? -ne 0 ]; then echo "Could not restore NuGet packages." diff --git a/scripts/packages.config b/scripts/packages.config index fd0de851..10e4f480 100644 --- a/scripts/packages.config +++ b/scripts/packages.config @@ -4,4 +4,5 @@ + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/sr.Designer.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.Designer.cs similarity index 100% rename from src/Microsoft.SqlTools.ServiceLayer/sr.Designer.cs rename to src/Microsoft.SqlTools.ServiceLayer/Localization/sr.Designer.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs similarity index 99% rename from src/Microsoft.SqlTools.ServiceLayer/sr.cs rename to src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index dd310334..221bfe95 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -788,7 +788,7 @@ namespace Microsoft.SqlTools.ServiceLayer [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Keys { - static ResourceManager resourceManager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.SR", typeof(SR).GetTypeInfo().Assembly); + static ResourceManager resourceManager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(SR).GetTypeInfo().Assembly); static CultureInfo _culture = null; diff --git a/src/Microsoft.SqlTools.ServiceLayer/sr.es.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx similarity index 99% rename from src/Microsoft.SqlTools.ServiceLayer/sr.es.resx rename to src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx index b1657f70..d65a6f96 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/sr.es.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx @@ -1,4 +1,4 @@ - +