perpetualkid / gettext.net Goto Github PK
View Code? Open in Web Editor NEWThis project forked from vitaliitsilnyk/ngettext
A .NET Standard cross-platform implementation of GNU Gettext
License: Other
This project forked from vitaliitsilnyk/ngettext
A .NET Standard cross-platform implementation of GNU Gettext
License: Other
use System.CommandLine package
Create Nuget package
Extractor should not output/save the catalog template if no entries were found (empty file with header only)
Extractor expects enum description on all members when applied to any member or the enum itself
[Description("Rotation")]
public enum Rotation
{
CounterClockwise = -1,
None = 0,
Clockwise = 1,
}
fails with NRE in ParserBase.GetStrings Line 143 when messageId will be null (since no attribute was extracted
catalog.AddOrUpdateEntry(context, messageId, $"{pathRelative}:{member.GetLocation().GetLineSpan().StartLinePosition.Line + 1}", false);
works:
[Description("Rotation")]
public enum Rotation
{
[Description("CounterClockwise")]CounterClockwise = -1,
[Description("None")]None = 0,
[Description("Clockwise")]Clockwise = 1,
}
Hello,
I faced the issue when the Extractor got all columns' headers successfully but in the runtime, Localizer doesn't localize headers.
I mean the ObjectListView package.
Regards.
Example:
GetString($"{Specifier}login {"username".Color(Utils.GreenHighlight)} {"password".Color(Utils.BoldHighlight)} - Logs in using your username and password.")
gets extracted as
{0}login {1} {2} - Logs in using your username and password.usernamepassword
rather than
{0}login {1} {2} - Logs in using your username and password.
In the generated translation template, set the Project-Id-Version value to the folder or solution/project name, instead PACKAGE VERSION
simplified parsing using Roslyn Syntax Tree. This may result in some false positives, and not be able to resolve variables/context, but has equivalent functionality as today's xgettext
Hello! In a project I work on there's a line:
if (json.RootElement.GetProperty("result").GetString() != "success")
The GetString
here is JsonElement.GetString
method. But GetText Extractor seems to treat this as GetText method and extracts the result
string.
Is there a way to tell the extractor to ignore this particular line or at least a .cs
file?
Escaped strings in the translated text are not decoded back to their original un escaped string, and are returned from GetString as is E.g. \'
does not become '
. It also looks like strings are not escaped when generating POT files from the extractors.
From the spec:
Each of untranslated-string and translated-string respects the C syntax for a character string, including the surrounding quotes and embedded backslashed escape sequences.
I am not using the extractors so have not tested in detail, but it looks like escaping was previously implemented and removed in 85eb836 .
I have not tested the same behaviour in NGettext - we much prefer this fork.
Trying to run the extractor I get the following error on macOS, as the code imports a Windows native dll.
Not sure about the details, but might Path.GetRelativePath(String, String)
do the job as well?
https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath?view=net-6.0
At least a quick smoke test seems to proof the example of the shlwapi
documentation. But maybe I'm missing the point of public static string GetRelativePath
's real usage.
Running on macOS
Running on Windows
❯ GetText.Extractor ─╯
Unhandled exception: System.DllNotFoundException: Unable to load shared library 'shlwapi.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libshlwapi.dll, 0x0001): tried: 'libshlwapi.dll' (no such file), '/usr/local/lib/libshlwapi.dll' (no such file), '/usr/lib/libshlwapi.dll' (no such file), '/Users/dw/dev/com.pm-international/pmi.services.identity/Identity.API/libshlwapi.dll' (no such file), '/usr/local/lib/libshlwapi.dll' (no such file), '/usr/lib/libshlwapi.dll' (no such file)
at GetText.Extractor.Template.NativeMethods.PathRelativePathTo(StringBuilder pszPath, String pszFrom, Int32 dwAttrFrom, String pszTo, Int32 dwAttrTo)
at GetText.Extractor.Template.PathExtension.GetRelativePath(String relativeTo, String path, Boolean unixStyle) in /_/src/GetText.Extractor/Template/PathExtension.cs:line 27
at GetText.Extractor.Engine.ParserBase`1.GetStrings(SyntaxTree tree)
at GetText.Extractor.Engine.SyntaxTreeParser.<Parse>b__1_1(SyntaxTree tree) in /_/src/GetText.Extractor/Engine/SyntaxTreeParser.cs:line 37
at System.Threading.Tasks.Dataflow.ActionBlock`1.ProcessMessage(Action`1 action, KeyValuePair`2 messageWithId)
at System.Threading.Tasks.Dataflow.ActionBlock`1.<>c__DisplayClass6_0.<.ctor>b__0(KeyValuePair`2 messageWithId)
at System.Threading.Tasks.Dataflow.Internal.TargetCore`1.ProcessMessagesLoopCore()
--- End of stack trace from previous location where exception was thrown ---
at GetText.Extractor.Engine.SyntaxTreeParser.Parse() in /_/src/GetText.Extractor/Engine/SyntaxTreeParser.cs:line 44
at GetText.Extractor.Program.Execute(FileInfo source, FileInfo target, Boolean unixStyle, Boolean sortOutput, Boolean verbose) in /_/src/GetText.Extractor/Program.cs:line 50
at GetText.Extractor.Program.<>c.<<Main>b__1_0>d.MoveNext() in /_/src/GetText.Extractor/Program.cs:line 36
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
dotnet --info ─╯
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.2
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/x64/sdk/6.0.100/
Host (useful for support):
Version: 6.0.2
Commit: 839cdfb0ec
.NET SDKs installed:
3.1.415 [/usr/local/share/dotnet/x64/sdk]
5.0.403 [/usr/local/share/dotnet/x64/sdk]
6.0.100 [/usr/local/share/dotnet/x64/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
ContextMenuStrip isn't localized when Form localizing
Localizer.Localize(form, catalog);
But it works as expected on direct call Localize for the contextMenuStrip:
Localizer.Localize(contextMenuStrip);
Bug?
As fa6da65, the unixStyle
replace the path to use unix separator. However, later when #34, the use of new Path.GetRelativePath
is not following this flag and always produce platform-specific path.
Hi
in GetText.NET.Extractor v0.9.5.0 error during extraction ?: operator
If there is a degeneracy in the code::
burnButton.Text = enable ? "&Burn" : "&Cancel";
that is extracted as a single word:
"&Burn&Cancel"
I expected two words
"&Burn" and "&Cancel"
We want our project to output strong named assemblies, but to do that all our references need to be strong-named as well. Can you strong-name sign the assemblies?
Thanks in advance
Hi,
Source:
using System;
using System.Windows.Forms;
namespace HelloApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
// Must be double "Text1"
button1.Text = "Text1";
button1.Text = "Text1";
}
}
}
Actual result in GetText.NET.Extractor v0.9.6.0:
If you then open this in PoEdit and click save, we will get:
Actual result in PoEdit 2.4.2:
References is broken (((
Which path is correct if there are spaces in the path?
#: .\Path with spaces\2.cs:13
or Unix paths, not Windows ones
#: ./Path with spaces/2.cs:13
Trying to integrate GetText.NET in a project. Running the extractor tool, I get the following error.
GetText.Extractor ─╯
Unhandled exception: System.ArgumentException: The SetHandler call for command 'GetText.Extractor' is missing an Argument or Option for the parameter at position 4. Did you mean to pass one of these?
at System.CommandLine.Handler.GetValueForHandlerParameter[T](IValueDescriptor[] symbols, Int32& index, InvocationContext context)
at System.CommandLine.Handler.<>c__DisplayClass23_0`5.<SetHandler>b__0(InvocationContext context)
at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
I guess my current environment is not the regular one, as I'm running on M1 macOS. Using the x64 framework/runtime, though.
dotnet --info ─╯
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.2
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/x64/sdk/6.0.100/
Host (useful for support):
Version: 6.0.2
Commit: 839cdfb0ec
.NET SDKs installed:
3.1.415 [/usr/local/share/dotnet/x64/sdk]
5.0.403 [/usr/local/share/dotnet/x64/sdk]
6.0.100 [/usr/local/share/dotnet/x64/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
Just wondering if there is anything wrong with the extractor installation, or if it is all about my setup. Happy for any input at this stage.
I feel really bad for not catching this sooner, but it appears that the recent changes have a caveat. While they do work, generally, the original goal of support for _() isn't exactly met, as currently custom aliases only work if they are in a member-access syntax, e.g. ClassName._(). This means that, say, a global static using directive wouldn't allow the programmer to extract from a method that is simply called via _().
I should be able to fix this when I have time today or maybe tomorrow, assuming it wouldn't break the code more generally.
Hi
in GetText.NET.Extractor v0.9.6.0 not all String.Format C# are marked as #, csharp-format
Source:
using System;
using System.Windows.Forms;
namespace HelloApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
labelTotalSize.Text = totalDiscSize < 1000000000 ?
catalog.GetString("{0} MB", totalDiscSize / 1000000) :
catalog.GetString("{0:F2} GB", (float)totalDiscSize / 1000000000.0);
}
}
}
Actual result:
msgid ""
msgstr ""
"Project-Id-Version: 1\n"
"POT-Creation-Date: 2020-11-12 10:52:56+0300\n"
"PO-Revision-Date: 2020-11-12 10:52:56+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: GetText.NET Extractor\n"
#: .\1\1.cs:16
#: .\1\1.cs:16
msgid "{0} MB"
msgstr ""
#: .\1\1.cs:17
#: .\1\1.cs:17
msgid "{0:F2} GB"
msgstr ""
and we also got a duplicate link.
Expected Result:
msgid ""
msgstr ""
"Project-Id-Version: 1\n"
"POT-Creation-Date: 2020-11-12 10:52:56+0300\n"
"PO-Revision-Date: 2020-11-12 10:52:56+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: GetText.NET Extractor\n"
#: .\1\1.cs:16
#, csharp-format
msgid "{0} MB"
msgstr ""
#: .\1\1.cs:17
#, csharp-format
msgid "{0:F2} GB"
msgstr ""
GetText.Extractor version: 1.8.7+bff42fb416
In our code we concatenate strings in this way:
lblArtCode.Text += " - " + ds.Current.Name;
and the correct call to extract is:
localizer.TextTranslator("Correct call to my localization method");
Calling GetText.Extractor -as TextTranslator
erroneously add the string " - "
to messages.pot
#: ..\example.cs:1
msgid " - "
msgstr ""
#: ..\example.cs:2
msgid "Correct call to my localization method"
msgstr ""
An outdated implementation by monoproject:
https://www.mono-project.com/archived/internationalization
The CultureInfo
for a Catalog
does not read from the catalog's Language
header, and instead uses the current culture by default. This means you can't tell what locale a Catalog
contains without parsing the headers yourself, and more confusingly, the CultureInfo
property normally doesn;t match the contents of the Catalog
.
Example header format:
Language: en
i.e. someControl.Text += "\r\n " + someExpression; ==> exports "\r\n "
Hello,
Is it possible to handle other control properties than Text/HeaderText/ToopTipText?
Is there a way to extend a list of predefined properties?
For instance, I'd like to localize property EmptyListMsg of ObjectListView control.
Thank you!
Regards.
Currently drops the formatting information while extracting
Unlike stated, extractor does not automatically append .pot file extension if only file name is given
The output extractions aren't deterministic, so it's impossible to automatically use GetText.Extractor to check for if the output is up to date as the spurious changes will confuse attempts to compare new vs current output.
Originally posted by a-sanders February 25, 2021
Hello,
It would be good to have the ability to mark some control as "non-localizable" for the Localizer (GetText.WindowsForms).
Regards.
Hello,
It would be good to have the ability to mark some control as "non-localizable" for the Localizer (GetText.WindowsForms).
Regards.
Hi
in GetText.NET.Extractor v0.9.6.0
Source:
using System;
using System.Windows.Forms;
namespace HelloApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
button1.Text = "Action: \"Operator Assistant\"";
}
}
}
Actual result:
If I combine ru.mo
and Messages. pot
I'll get an error
with System.CommandLine 2.0 Beta 4 the number of commandline options to be passed to rootCommand.SetHandler is reduced from 16 to 8 dotnet/command-line-api#1750 (comment).
Due to new alias* commands, Extractor currently requires the handler to pass 10 parameters. This needs to be refactored, ie. combining alias handling into a single paramter option, using resultfiles or other.
May need some further research before implementation.
This issue is currently blocking upgrade of System.CommandLine package.
@Owlblocks
Consider moving Extractor to .NET 6.
When I tried to extract messages from source
...
toolTip.SetToolTip(pictureBox, success ? "The server was connected successfully (1)." : "The server connection failed (1).");
string test = success ? "The server was connected successfully (2)." : "The server connection failed (2).";
...
I was confused by the contents of the POT-file in 2 points:
#: .\test.cs:6
msgid ""
"The server was connected successfully (1).The server connection failed (1)."
msgstr ""
Command line:
GetText.Extractor.exe --source test.cs --target test
GetText.Extractor.exe version:
0.9.9+0d4629f2b5b010d2734feac69a4b84f57ee6695a
Appropriate source and POT files attached
test.zip
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.