diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2016-09-26 22:14:37 +0300 |
---|---|---|
committer | Kenneth Skovhede <kenneth@hexad.dk> | 2016-09-26 22:14:37 +0300 |
commit | 41915061878235bbb0a063ca8307bd4838ccdd2a (patch) | |
tree | c069585d10665d785e341656341ecfdc0a591dcf /BuildTools | |
parent | 2722ddad8eed260be4e29945f97941414fc11437 (diff) |
Updated new localization tool to generate .po files
Diffstat (limited to 'BuildTools')
-rw-r--r-- | BuildTools/LocalizationTool2/LocalizationTool2.sln | 29 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/Program.cs | 151 | ||||
-rw-r--r-- | BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs | 4 |
3 files changed, 119 insertions, 65 deletions
diff --git a/BuildTools/LocalizationTool2/LocalizationTool2.sln b/BuildTools/LocalizationTool2/LocalizationTool2.sln index ec485633a..6bde3c715 100644 --- a/BuildTools/LocalizationTool2/LocalizationTool2.sln +++ b/BuildTools/LocalizationTool2/LocalizationTool2.sln @@ -14,4 +14,33 @@ Global {6795DFBA-B494-4D6F-A79C-9118EF1CC109}.Release|x86.ActiveCfg = Release|x86
{6795DFBA-B494-4D6F-A79C-9118EF1CC109}.Release|x86.Build.0 = Release|x86
EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ Policies = $0
+ $0.TextStylePolicy = $1
+ $1.inheritsSet = VisualStudio
+ $1.scope = text/plain
+ $1.FileWidth = 120
+ $1.EolMarker = Windows
+ $1.inheritsScope = text/plain
+ $0.CSharpFormattingPolicy = $2
+ $2.NewLinesForBracesInProperties = True
+ $2.NewLinesForBracesInAccessors = True
+ $2.NewLinesForBracesInAnonymousMethods = True
+ $2.NewLinesForBracesInControlBlocks = True
+ $2.NewLinesForBracesInAnonymousTypes = True
+ $2.NewLinesForBracesInObjectCollectionArrayInitializers = True
+ $2.NewLinesForBracesInLambdaExpressionBody = True
+ $2.NewLineForElse = True
+ $2.NewLineForCatch = True
+ $2.NewLineForFinally = True
+ $2.NewLineForMembersInObjectInit = True
+ $2.NewLineForMembersInAnonymousTypes = True
+ $2.NewLineForClausesInQuery = True
+ $2.SpacingAfterMethodDeclarationName = False
+ $2.SpaceAfterMethodCallName = False
+ $2.SpaceBeforeOpenSquareBracket = False
+ $2.inheritsSet = Mono
+ $2.inheritsScope = text/x-csharp
+ $2.scope = text/x-csharp
+ EndGlobalSection
EndGlobal
diff --git a/BuildTools/LocalizationTool2/Program.cs b/BuildTools/LocalizationTool2/Program.cs index 487807ab5..c443dc242 100644 --- a/BuildTools/LocalizationTool2/Program.cs +++ b/BuildTools/LocalizationTool2/Program.cs @@ -1,63 +1,88 @@ -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; - - } - } -} +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>();
+
+ if (!sourcefolder.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
+ sourcefolder += Path.DirectorySeparatorChar;
+
+ 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, f.Substring(sourcefolder.Length), 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));
+
+ File.WriteAllLines(
+ Path.Combine(sourcefolder, "translations.po"),
+ map.OrderBy(x => x.Key).Select(x => x.Value).SelectMany(x => new string[] {
+ "#: " + x.SourceLocations.FirstOrDefault(),
+ string.Format("msgid: \"{0}\"", (x.SourceString ?? "")),
+ string.Format("msgstr: \"{0}\"", (x.SourceString ?? "")),
+ ""
+ }),
+ System.Text.Encoding.UTF8
+ );
+
+ File.WriteAllLines(
+ Path.Combine(sourcefolder, "translations-by-file.po"),
+ map.OrderBy(x => x.Value.SourceLocations.FirstOrDefault()).Select(x => x.Value).SelectMany(x => new string[] {
+ "#: " + x.SourceLocations.FirstOrDefault(),
+ string.Format("msgid: \"{0}\"", (x.SourceString ?? "")),
+ string.Format("msgstr: \"{0}\"", (x.SourceString ?? "")),
+ ""
+ }),
+ System.Text.Encoding.UTF8
+ );
+
+ return 0;
+
+ }
+ }
+}
diff --git a/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs b/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs index aa13857f5..477ec7720 100644 --- a/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs +++ b/BuildTools/LocalizationTool2/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. @@ -17,7 +17,7 @@ using System.Runtime.CompilerServices; // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("2.0.0.7")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. |