From 2366e8c25b1513d9ea275410cf7f786d2c90535a Mon Sep 17 00:00:00 2001 From: nd Date: Sun, 10 Mar 2024 17:28:33 +0100 Subject: [PATCH] Update + Updated factory patterns to support `GetTerm` and `__` keyword matching --- README.md | 6 +++--- src/wan24-PoeditParser CLI/ParserConfig.cs | 2 +- src/wan24-PoeditParser CLI/Program.cs | 6 ++---- src/wan24-PoeditParser CLI/README.md | 10 +++++++--- .../wan24-PoeditParser CLI.csproj | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d54e988..190c539 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ folder tree. Per default keywords will be found by these regular expressions: -- `^.*((Description|DisplayText)\(\s*(\"".*[^\\]\"")\s*\)).*$` (`$3`) -- `^.*((_|gettextn?|Translate(Plural)?)\(\s*(\"".*[^\\]\"")).*$` (`$4`) -- `^.*(CliApi[^\s]*\([^\)]*Example\s*\=\s*(\"".*[^\\]\"")).*$` (`$2`) +- `^.*((Description|DisplayText)\(\s*(\".*[^\\]\")\s*\)).*$` (`$3`) +- `^.*((__?|gettextn?|Translate(Plural)?|GetTerm)\(\s*(\".*[^\\]\")).*$` (`$4`) +- `^.*(CliApi[^\s]*\([^\)]*Example\s*\=\s*(\".*[^\\]\")).*$` (`$2`) **NOTE**: (Multiline) concatenated string value definitions (like `"Part a" + "Part b"`) or interpolations can't be parsed. The matched keyword diff --git a/src/wan24-PoeditParser CLI/ParserConfig.cs b/src/wan24-PoeditParser CLI/ParserConfig.cs index 773a62b..1d79534 100644 --- a/src/wan24-PoeditParser CLI/ParserConfig.cs +++ b/src/wan24-PoeditParser CLI/ParserConfig.cs @@ -22,7 +22,7 @@ static ParserConfig() }, new ParserPattern() { - Pattern= @"^.*((_|gettextn?|Translate(Plural)?)\(\s*(\"".*[^\\]\"")).*$", + Pattern= @"^.*((__?|gettextn?|Translate(Plural)?|GetTerm)\(\s*(\"".*[^\\]\"")).*$", Options = RegexOptions.Compiled, Replacement = "$4" }, diff --git a/src/wan24-PoeditParser CLI/Program.cs b/src/wan24-PoeditParser CLI/Program.cs index 72a761c..04dad52 100644 --- a/src/wan24-PoeditParser CLI/Program.cs +++ b/src/wan24-PoeditParser CLI/Program.cs @@ -7,10 +7,8 @@ CliConfig.Apply(new(args)); #if DEBUG Settings.LogLevel = LogLevel.Trace; -Logging.Logger = new VividConsoleLogger(LogLevel.Trace, await FileLogger.CreateAsync(Path.Combine(ENV.AppFolder, "wan24PoeditParser.log"), LogLevel.Trace)); -File.WriteAllText(Path.Combine(ENV.AppFolder, "wan24PoeditParser.CLI.log"), string.Join(' ', Environment.GetCommandLineArgs())); -throw new Exception(ENV.AppFolder); +Logging.Logger = new VividConsoleLogger(LogLevel.Trace, await FileLogger.CreateAsync(Path.Combine(ENV.AppFolder, "wan24PoeditParser.log"), LogLevel.Trace).DynamicContext()); #endif -Translation.Current = Translation.Dummy; +Translation.Current ??= Translation.Dummy; CliApi.CommandLine = "wan24PoeditParser"; return await CliApi.RunAsync(args, exportedApis: [typeof(CliHelpApi), typeof(ParserApi)]); diff --git a/src/wan24-PoeditParser CLI/README.md b/src/wan24-PoeditParser CLI/README.md index ed85abf..190c539 100644 --- a/src/wan24-PoeditParser CLI/README.md +++ b/src/wan24-PoeditParser CLI/README.md @@ -3,6 +3,10 @@ This is a small dotnet tool for parsing source code for gettext strings and writing the result in the PO format to a file or STDOUT. +**CAUTION**: It can create a PO file from the command line, but using it as +Poedit extractor didn't work yet (Poedit discards the custom extractor +configuration, which may be a bug - not sure yet). + It's pre-configured for use with the [`wan24-Core`](https://github.com/WAN-Solutions/wan24-Core) translation helpers for C#, but it can be customized easily for any environment and any @@ -39,9 +43,9 @@ folder tree. Per default keywords will be found by these regular expressions: -- `^.*((Description|DisplayText)\(\s*(\"".*[^\\]\"")\s*\)).*$` (`$3`) -- `^.*((_|gettextn?|Translate(Plural)?)\(\s*(\"".*[^\\]\"")).*$` (`$4`) -- `^.*(CliApi[^\s]*\([^\)]*Example\s*\=\s*(\"".*[^\\]\"")).*$` (`$2`) +- `^.*((Description|DisplayText)\(\s*(\".*[^\\]\")\s*\)).*$` (`$3`) +- `^.*((__?|gettextn?|Translate(Plural)?|GetTerm)\(\s*(\".*[^\\]\")).*$` (`$4`) +- `^.*(CliApi[^\s]*\([^\)]*Example\s*\=\s*(\".*[^\\]\")).*$` (`$2`) **NOTE**: (Multiline) concatenated string value definitions (like `"Part a" + "Part b"`) or interpolations can't be parsed. The matched keyword diff --git a/src/wan24-PoeditParser CLI/wan24-PoeditParser CLI.csproj b/src/wan24-PoeditParser CLI/wan24-PoeditParser CLI.csproj index 72de5ce..62ece4f 100644 --- a/src/wan24-PoeditParser CLI/wan24-PoeditParser CLI.csproj +++ b/src/wan24-PoeditParser CLI/wan24-PoeditParser CLI.csproj @@ -38,8 +38,8 @@ - - + +