Localization tool pre init verssion
This commit is contained in:
Родитель
43e3017196
Коммит
7067c41650
|
@ -256,3 +256,4 @@ paket-files/
|
|||
.idea/
|
||||
*.sln.iml
|
||||
templates/_composition/_shared/Page.Chart.SampleDataService/Services/SampleDataService_postaction.cs
|
||||
/myModel.vsdx
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.13
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Localization", "tools\Localization\Localization.csproj", "{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Analyze|Any CPU = Analyze|Any CPU
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Analyze|Any CPU.ActiveCfg = Analyze|Any CPU
|
||||
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Analyze|Any CPU.Build.0 = Analyze|Any CPU
|
||||
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
internal delegate void OnCommand(ToolCommandInfo commandInfo);
|
||||
|
||||
internal class ToolCommandHandler
|
||||
{
|
||||
private const string splitPattern = @"(""[a-zA-Z0-9\s_@:.;\-^!#$%&+={}\(\)\[\]\\\/]*?"")|([a-zA-Z0-9]+)";
|
||||
private Dictionary<string, List<OnCommand>> handlers;
|
||||
|
||||
internal void Listen()
|
||||
{
|
||||
ToolCommandInfo commandInfo;
|
||||
string commandLine;
|
||||
string[] commandParts;
|
||||
while (1 == 1)
|
||||
{
|
||||
Console.Write(">> ");
|
||||
commandLine = Console.ReadLine().Trim();
|
||||
MatchCollection matches = Regex.Matches(commandLine, splitPattern);
|
||||
commandParts = new string[matches.Count];
|
||||
int i = 0;
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
commandParts[i++] = match.Value.Trim("\"".ToCharArray());
|
||||
}
|
||||
if (commandParts.Length > 0)
|
||||
{
|
||||
string[] arguments = commandParts.Length > 1 ? new string[commandParts.Length - 1] : new string[] { };
|
||||
if (commandParts.Length > 1)
|
||||
Array.ConstrainedCopy(commandParts, 1, arguments, 0, arguments.Length);
|
||||
commandInfo = new ToolCommandInfo(commandParts[0].Trim().ToLower(), arguments);
|
||||
if (commandInfo.Command == "exit")
|
||||
break;
|
||||
if (this.handlers != null && this.handlers.ContainsKey(commandInfo.Command) && this.handlers[commandInfo.Command].Count > 0)
|
||||
{
|
||||
foreach (OnCommand handler in this.handlers[commandInfo.Command])
|
||||
{
|
||||
try
|
||||
{
|
||||
handler.Invoke(commandInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error executing command {commandInfo.Command.ToUpper()}:");
|
||||
Console.Error.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Command unknown. Type HELP for help.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void SubscribeOnCommand(string command, OnCommand handler)
|
||||
{
|
||||
command = command.ToLower();
|
||||
if (this.handlers == null)
|
||||
this.handlers = new Dictionary<string, List<OnCommand>>();
|
||||
if (!this.handlers.ContainsKey(command))
|
||||
this.handlers.Add(command, new List<OnCommand>());
|
||||
this.handlers[command].Add(handler);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
internal class ToolCommandInfo
|
||||
{
|
||||
internal string Command { get; private set; }
|
||||
internal string[] Arguments { get; private set; }
|
||||
internal ToolCommandInfo(string command, string[] arguments)
|
||||
{
|
||||
this.Command = command;
|
||||
this.Arguments = arguments;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Localization</RootNamespace>
|
||||
<AssemblyName>Localization</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Analyze|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Analyze\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="ClientInterface\ToolCommandHandler.cs" />
|
||||
<Compile Include="Logic\LocalizableItemsExtractor.cs" />
|
||||
<Compile Include="Logic\LocalizationTool.cs" />
|
||||
<Compile Include="Logic\XmlUtility.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Logic\ProjectTemplateGenerator.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ClientInterface\ToolCommandInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\StyleCop.json">
|
||||
<Link>StyleCop.json</Link>
|
||||
</None>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
|
||||
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
internal class LocalizableItemsExtractor
|
||||
{
|
||||
private DirectoryInfo sourceDir;
|
||||
private DirectoryInfo destinationDir;
|
||||
private const string projectTemplateFileNamePattern = "CSharp.UWP.VS2017.Solution.vstemplate";
|
||||
private const string projectTemplateDirNamePattern = "CSharp.UWP.2017.{0}.Solution";
|
||||
private const string projectTemplateRootDirPath = "ProjectTemplates";
|
||||
|
||||
internal LocalizableItemsExtractor(string sourceDirPath, string destinationDirPath)
|
||||
{
|
||||
this.sourceDir = new DirectoryInfo(sourceDirPath);
|
||||
if (!this.sourceDir.Exists)
|
||||
throw new DirectoryNotFoundException($"Source directory \"{sourceDirPath}\" not found.");
|
||||
this.destinationDir = new DirectoryInfo(destinationDirPath);
|
||||
if (!this.destinationDir.Exists)
|
||||
this.destinationDir.Create();
|
||||
}
|
||||
|
||||
internal bool ExtractProjectTemplate(string culture)
|
||||
{
|
||||
DirectoryInfo templateDesDirectory = new DirectoryInfo(Path.Combine(this.destinationDir.FullName, projectTemplateRootDirPath, string.Format(projectTemplateDirNamePattern, culture)));
|
||||
if (templateDesDirectory.Exists)
|
||||
return false;
|
||||
templateDesDirectory.Create();
|
||||
DirectoryInfo templateSrcDirectory = new DirectoryInfo(Path.Combine(this.sourceDir.FullName, projectTemplateRootDirPath, string.Format(projectTemplateDirNamePattern, culture)));
|
||||
if (!templateSrcDirectory.Exists)
|
||||
throw new DirectoryNotFoundException($"Source directory \"{templateSrcDirectory.FullName}\" not found.");
|
||||
FileInfo file = new FileInfo(Path.Combine(templateSrcDirectory.FullName, projectTemplateFileNamePattern));
|
||||
if (!file.Exists)
|
||||
throw new FileNotFoundException($"File \"{file.FullName}\" not found.");
|
||||
file.CopyTo(Path.Combine(templateDesDirectory.FullName, projectTemplateFileNamePattern));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
// ******************************************************************
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||
// ******************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
internal class LocalizationTool
|
||||
{
|
||||
public LocalizationTool()
|
||||
{
|
||||
}
|
||||
|
||||
public void GenerateProjectTemplatesHandler(ToolCommandInfo commandInfo)
|
||||
{
|
||||
if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
|
||||
{
|
||||
throw new Exception("Error executing command. Too few arguments.");
|
||||
}
|
||||
string sourceDirectory = commandInfo.Arguments[0];
|
||||
string destinationDirectory = commandInfo.Arguments[1];
|
||||
List<string> cultures = new List<string>(commandInfo.Arguments[2].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
|
||||
ProjectTemplateGenerator projectTemplateGenerator = new ProjectTemplateGenerator(sourceDirectory, destinationDirectory);
|
||||
foreach (string culture in cultures)
|
||||
{
|
||||
projectTemplateGenerator.GenerateProjectTemplate(culture);
|
||||
}
|
||||
}
|
||||
|
||||
public void ExtractLocalizableItems(ToolCommandInfo commandInfo)
|
||||
{
|
||||
if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
|
||||
{
|
||||
throw new Exception("Error executing command. Too few arguments.");
|
||||
}
|
||||
string sourceDirectory = commandInfo.Arguments[0];
|
||||
string destinationDirectory = commandInfo.Arguments[1];
|
||||
List<string> cultures = new List<string>(commandInfo.Arguments[2].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
|
||||
LocalizableItemsExtractor extractor = new LocalizableItemsExtractor(sourceDirectory, destinationDirectory);
|
||||
foreach (string culture in cultures)
|
||||
{
|
||||
extractor.ExtractProjectTemplate(culture);
|
||||
}
|
||||
// CSharp.UWP.2017.{culture}.Solution/CSharp.UWP.VS2017.Solution.vstemplate
|
||||
// TemplateEngine Json
|
||||
// TemplateEngine Md
|
||||
// Wts Json
|
||||
// Wts Md
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
// ******************************************************************
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||
// ******************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
internal class ProjectTemplateGenerator
|
||||
{
|
||||
private DirectoryInfo sourceDir;
|
||||
private DirectoryInfo destinationDir;
|
||||
private const string sourceDirNamePattern = "CSharp.UWP.2017.Solution";
|
||||
private const string sourceFileNamePattern = "CSharp.UWP.VS2017.Solution";
|
||||
private const string destinationDirNamePattern = "CSharp.UWP.2017.{0}.Solution";
|
||||
private const string destinationFileNamePattern = "CSharp.UWP.VS2017.{0}.Solution";
|
||||
|
||||
internal ProjectTemplateGenerator(string sourceDirPath, string destinationDirPath)
|
||||
{
|
||||
this.sourceDir = new DirectoryInfo(sourceDirPath);
|
||||
if (!this.sourceDir.Exists)
|
||||
throw new DirectoryNotFoundException($"Source directory \"{sourceDirPath}\" not found.");
|
||||
if (this.sourceDir.Name.ToLower() != sourceDirNamePattern.ToLower())
|
||||
throw new Exception($"Source directory \"{this.sourceDir.Name}\" is not valid. Directory name should be \"{sourceDirNamePattern}\".");
|
||||
this.destinationDir = new DirectoryInfo(destinationDirPath);
|
||||
if (!this.destinationDir.Exists)
|
||||
this.destinationDir.Create();
|
||||
}
|
||||
|
||||
internal bool GenerateProjectTemplate(string culture)
|
||||
{
|
||||
DirectoryInfo templateDirectory = new DirectoryInfo(Path.Combine(this.destinationDir.FullName, string.Format(destinationDirNamePattern, culture)));
|
||||
if (templateDirectory.Exists)
|
||||
return false;
|
||||
templateDirectory.Create();
|
||||
this.CopyDirectory(this.sourceDir, templateDirectory);
|
||||
this.LocalizeCsprojFile(culture, templateDirectory);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LocalizeCsprojFile(string culture, DirectoryInfo templateDirectory)
|
||||
{
|
||||
string csprojFilePath = Path.Combine(templateDirectory.FullName, sourceFileNamePattern + ".csproj");
|
||||
FileInfo csprojFile = new FileInfo(csprojFilePath);
|
||||
if (!csprojFile.Exists)
|
||||
throw new FileNotFoundException($"File \"{csprojFilePath}\" not found.");
|
||||
XmlDocument xmlProjFile = XmlUtility.LoadXmlFile(csprojFilePath);
|
||||
XmlNode node = XmlUtility.GetNode(xmlProjFile, "CodeAnalysisRuleSet");
|
||||
XmlUtility.InsertNewNodeAfter(node, "CreateVsixContainer", "False");
|
||||
XmlUtility.InsertNewNodeAfter(node, "CopyVsixExtensionFiles", "False");
|
||||
XmlUtility.SetNodeText(xmlProjFile, "ProjectGuid", Guid.NewGuid().ToString("B"));
|
||||
XmlUtility.AppendNewChildNode(xmlProjFile, "VSTemplate", "Culture", new CultureInfo(culture).LCID.ToString());
|
||||
xmlProjFile.Save(Path.Combine(templateDirectory.FullName, string.Format(destinationFileNamePattern, culture) + ".csproj"));
|
||||
csprojFile.Delete();
|
||||
}
|
||||
|
||||
private void CopyDirectory(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory)
|
||||
{
|
||||
foreach (FileInfo file in sourceDirectory.GetFiles())
|
||||
{
|
||||
file.CopyTo(Path.Combine(destinationDirectory.FullName, file.Name));
|
||||
}
|
||||
DirectoryInfo tmpDir;
|
||||
foreach (DirectoryInfo directory in sourceDirectory.GetDirectories())
|
||||
{
|
||||
tmpDir = new DirectoryInfo(Path.Combine(destinationDirectory.FullName, directory.Name));
|
||||
if (!tmpDir.Exists)
|
||||
tmpDir.Create();
|
||||
this.CopyDirectory(directory, tmpDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
internal static class XmlUtility
|
||||
{
|
||||
internal static XmlDocument LoadXmlFile(string filePath)
|
||||
{
|
||||
XmlDocument xmlFile = new XmlDocument();
|
||||
xmlFile.Load(filePath);
|
||||
return xmlFile;
|
||||
}
|
||||
|
||||
internal static XmlNode GetNode(XmlDocument xmlFile, string nodeName)
|
||||
{
|
||||
XmlNodeList nodes = xmlFile.GetElementsByTagName(nodeName);
|
||||
if (nodes == null || nodes.Count == 0)
|
||||
throw new Exception($"Node \"{nodeName}\" not found in XmlDocument.");
|
||||
if (nodes.Count > 1)
|
||||
throw new Exception($"There were more than one \"{nodeName}\" node XmlDocument.");
|
||||
return nodes[0];
|
||||
}
|
||||
|
||||
internal static void SetNodeText(XmlDocument xmlFile, string nodeName, string nodeText)
|
||||
{
|
||||
XmlNode node = GetNode(xmlFile, nodeName);
|
||||
node.InnerText = nodeText;
|
||||
}
|
||||
|
||||
internal static void InsertNewNodeAfter(XmlNode node, string newNodeName, string newNodeText)
|
||||
{
|
||||
XmlDocument xmlFile = node.OwnerDocument;
|
||||
XmlNode newNode = xmlFile.CreateNode(XmlNodeType.Element, newNodeName, node.NamespaceURI);
|
||||
newNode.InnerText = newNodeText;
|
||||
node.ParentNode.InsertAfter(newNode, node);
|
||||
}
|
||||
|
||||
internal static void AppendNewChildNode(XmlDocument xmlFile, string nodeName, string newNodeName, string newNodeText)
|
||||
{
|
||||
XmlNode node = GetNode(xmlFile, nodeName);
|
||||
XmlNode newNode = xmlFile.CreateNode(XmlNodeType.Element, newNodeName, node.NamespaceURI);
|
||||
newNode.InnerText = newNodeText;
|
||||
node.AppendChild(newNode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
// ******************************************************************
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||
// ******************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Localization
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private const string separator = "**********************************************************************";
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
PrintHeader();
|
||||
LocalizationTool tool = new LocalizationTool();
|
||||
ToolCommandHandler commandHandler = new ToolCommandHandler();
|
||||
commandHandler.SubscribeOnCommand("help", PrintHelp);
|
||||
commandHandler.SubscribeOnCommand("gen", tool.GenerateProjectTemplatesHandler);
|
||||
commandHandler.SubscribeOnCommand("ext", tool.ExtractLocalizableItems);
|
||||
commandHandler.Listen();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.ToString());
|
||||
Console.WriteLine("Press any key to quit.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintHeader()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine("** Windows Template Studio Localization Tool");
|
||||
Console.WriteLine("** Copyright (c) 2017 Microsoft Corporation");
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
private static void PrintHelp(ToolCommandInfo commandInfo)
|
||||
{
|
||||
if (commandInfo.Arguments == null || commandInfo.Arguments.Length == 0)
|
||||
{
|
||||
Console.WriteLine("For more information on a specific command, type HELP command-name");
|
||||
Console.WriteLine("EXIT\tQuits Windows Template Studio Localization Tool.");
|
||||
Console.WriteLine("EXT\tExtract localizable items for different cultures.");
|
||||
Console.WriteLine("GEN\tGenerates Project Templates for different cultures.");
|
||||
Console.WriteLine("HELP\tProvides Help information for Windows Template Studio Localization Tool.");
|
||||
Console.WriteLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (commandInfo.Arguments[0].ToUpper())
|
||||
{
|
||||
case "EXIT":
|
||||
Console.WriteLine("Quits Windows Template Studio Localization Tool.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("EXIT");
|
||||
Console.WriteLine();
|
||||
break;
|
||||
case "EXT":
|
||||
Console.WriteLine("Extract localizable items for different cultures.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("EXT [::TODO::]");
|
||||
Console.WriteLine();
|
||||
break;
|
||||
case "GEN":
|
||||
Console.WriteLine("Generates Project Templates for different cultures.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("GEN \"sourceDirectoryPath\" \"destinationDirectoryPath\" \"cultures\"");
|
||||
Console.WriteLine();
|
||||
break;
|
||||
case "HELP":
|
||||
Console.WriteLine("Provides Help information for Windows Template Studio Localization Tool.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("HELP [command]");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("\tcommand - displays help information on that command.");
|
||||
Console.WriteLine();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Command unknown.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string PrintArray(string[] array)
|
||||
{
|
||||
if (array == null || array.Length == 0)
|
||||
return "\t\tEmpty or Null...";
|
||||
StringBuilder writer = new StringBuilder();
|
||||
foreach (string item in array)
|
||||
{
|
||||
writer.AppendLine("\t\t" + item);
|
||||
}
|
||||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Localization")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Localization")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("84900dd1-8f31-4d6f-8c8a-0baac25829da")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="StyleCop.Analyzers" version="1.0.2" targetFramework="net462" developmentDependency="true" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче