diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2016-09-20 13:04:11 +0300 |
---|---|---|
committer | Kenneth Skovhede <kenneth@hexad.dk> | 2016-09-20 16:34:05 +0300 |
commit | 47a62d775732cc190c57d8bbdf21b40c958b8e12 (patch) | |
tree | 77e554541a0246c5d7cfa4868c69ec50a4816518 /BuildTools | |
parent | bc5ead6028d966797f2484706a500e563b832aac (diff) |
Added a new tool to extract translate-able strings from the project files
Diffstat (limited to 'BuildTools')
-rw-r--r-- | BuildTools/LocalizationTool2/LocalizationEntry.cs | 29 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/LocalizationTool2.csproj | 46 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/LocalizationTool2.sln | 17 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/Program.cs | 63 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs | 26 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/packages.config | 4 |
6 files changed, 185 insertions, 0 deletions
diff --git a/BuildTools/LocalizationTool2/LocalizationEntry.cs b/BuildTools/LocalizationTool2/LocalizationEntry.cs new file mode 100644 index 000000000..dea40d9f9 --- /dev/null +++ b/BuildTools/LocalizationTool2/LocalizationEntry.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace LocalizationTool2 +{ + public class LocalizationEntry + { + public LocalizationEntry() + { + SourceLocations = new List<string>(); + } + + public LocalizationEntry(string text, string file, int position) + : this() + { + SourceString = text; + AddSource(file, position); + } + + internal void AddSource(string file, int linepos) + { + SourceLocations.Add(string.Format("{0}:{1}", file, linepos)); + } + + public string SourceString { get; set; } + public List<string> SourceLocations { get; set; } + +} +} diff --git a/BuildTools/LocalizationTool2/LocalizationTool2.csproj b/BuildTools/LocalizationTool2/LocalizationTool2.csproj new file mode 100644 index 000000000..181674f76 --- /dev/null +++ b/BuildTools/LocalizationTool2/LocalizationTool2.csproj @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProjectGuid>{6795DFBA-B494-4D6F-A79C-9118EF1CC109}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>LocalizationTool2</RootNamespace>
+ <AssemblyName>LocalizationTool2</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ExternalConsole>true</ExternalConsole>
+ <PlatformTarget>x86</PlatformTarget>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ExternalConsole>true</ExternalConsole>
+ <PlatformTarget>x86</PlatformTarget>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="LocalizationEntry.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file diff --git a/BuildTools/LocalizationTool2/LocalizationTool2.sln b/BuildTools/LocalizationTool2/LocalizationTool2.sln new file mode 100644 index 000000000..ec485633a --- /dev/null +++ b/BuildTools/LocalizationTool2/LocalizationTool2.sln @@ -0,0 +1,17 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalizationTool2", "LocalizationTool2.csproj", "{6795DFBA-B494-4D6F-A79C-9118EF1CC109}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6795DFBA-B494-4D6F-A79C-9118EF1CC109}.Debug|x86.ActiveCfg = Debug|x86
+ {6795DFBA-B494-4D6F-A79C-9118EF1CC109}.Debug|x86.Build.0 = Debug|x86
+ {6795DFBA-B494-4D6F-A79C-9118EF1CC109}.Release|x86.ActiveCfg = Release|x86
+ {6795DFBA-B494-4D6F-A79C-9118EF1CC109}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+EndGlobal
diff --git a/BuildTools/LocalizationTool2/Program.cs b/BuildTools/LocalizationTool2/Program.cs new file mode 100644 index 000000000..487807ab5 --- /dev/null +++ b/BuildTools/LocalizationTool2/Program.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace LocalizationTool2 +{ + class MainClass + { + public static int Main(string[] args) + { + var sourcefolder = Environment.CurrentDirectory; + if (args == null || args.Length != 0) + sourcefolder = args[0]; + + sourcefolder = Path.GetFullPath(sourcefolder.Replace("~", Environment.GetEnvironmentVariable("HOME"))); + + + if (!Directory.Exists(sourcefolder)) + { + Console.WriteLine("No such directory: {0}", sourcefolder); + return 1; + } + + sourcefolder = Path.GetFullPath(sourcefolder); + Console.WriteLine("Using directory {0}, scanning ....", sourcefolder); + + + var searchlist = new Dictionary<string, Regex>(); + searchlist.Add("html", new Regex("((\\{\\{)|(ng-bind-html\\s*=\\s*\"))\\s*\\'(?<sourcestring>(\\\\\\'|[^\\'])+)\\'\\s*\\|\\s*localize(\\s|\\:|\\})", RegexOptions.Multiline | RegexOptions.IgnoreCase)); + searchlist.Add("js", new Regex("Localization\\.localize\\(\\s*((\\'(?<sourcestring>(\\\\\\'|[^\\'])+)\\')|(\\\"(?<sourcestring>(\\\\\\\"|[^\\\"])+)\\\"))", RegexOptions.Multiline | RegexOptions.IgnoreCase)); + searchlist.Add("cs", new Regex("LC.L\\s*\\(((@\\s*\"(?<sourcestring>(\"\"|[^\"])+))|(\"(?<sourcestring>(\\\\\"|[^\"])+)))\"\\s*\\)", RegexOptions.Multiline | RegexOptions.IgnoreCase)); + + var map = new Dictionary<string, LocalizationEntry>(); + + foreach (var ext in searchlist.Keys) + { + var re = searchlist[ext]; + foreach (var f in Directory.GetFiles(sourcefolder, "*." + ext, SearchOption.AllDirectories)) + { + var txt = File.ReadAllText(f); + foreach (Match match in re.Matches(txt)) + { + var linepos = txt.Substring(match.Index).Count(x => x == '\n'); + var str = match.Groups["sourcestring"].Value; + LocalizationEntry le; + if (!map.TryGetValue(str, out le)) + map[str] = new LocalizationEntry(str, Path.GetFileName(f), linepos); + else + le.AddSource(Path.GetFileName(f), linepos); + } + } + } + + File.WriteAllText(Path.Combine(sourcefolder, "translations.json"), Newtonsoft.Json.JsonConvert.SerializeObject(map.Values.OrderBy(x => x.SourceLocations.FirstOrDefault()).ToArray(), Newtonsoft.Json.Formatting.Indented)); + File.WriteAllText(Path.Combine(sourcefolder, "translations-list.json"), Newtonsoft.Json.JsonConvert.SerializeObject(map.Select(x => x.Key).OrderBy(x => x).ToArray(), Newtonsoft.Json.Formatting.Indented)); + + return 0; + + } + } +} diff --git a/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs b/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..aa13857f5 --- /dev/null +++ b/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("LocalizationTool2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("kenneth")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/BuildTools/LocalizationTool2/packages.config b/BuildTools/LocalizationTool2/packages.config new file mode 100644 index 000000000..e1fae9c6a --- /dev/null +++ b/BuildTools/LocalizationTool2/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" /> +</packages>
\ No newline at end of file |