GithubHelp home page GithubHelp logo

perpetualkid / gettext.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vitaliitsilnyk/ngettext

32.0 32.0 9.0 1001 KB

A .NET Standard cross-platform implementation of GNU Gettext

License: Other

C# 100.00%
c-sharp csharp dotnet-core dotnet-standard extract extractor gettext i18n l10n

gettext.net's People

Contributors

am11 avatar jorrit avatar jpk6789 avatar kukkimonsuta avatar mburtscher avatar neris avatar owlblocks avatar perpetualkid avatar vdaron avatar vitaliitsilnyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gettext.net's Issues

Another control properties

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.

Extractor fails when enum description not applied on all members

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,
    }

GetText.Extractor: bug with ternary operator ?:

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 ""
  1. I expected that the extractor will ignore both lines but it extracts strings from the first line
  2. Two strings from the first line were combined to a single message.

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

Extractor wrongly extracts interpolated strings with strings inside of them

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.

Strong name signing assemblies

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

Wrong text extraction

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 ""

ContextMenuStrip is not localized

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?

Bug (?) with aliases requiring member syntax

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.

GetText.NET.Extractor: POT files’s references are Unix paths or Windows?

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

Non-localizable controls

Hello,
It would be good to have the ability to mark some control as "non-localizable" for the Localizer (GetText.WindowsForms).

Regards.

GetText.NET.Extractor: not all String.Format C# are marked as csharp-format

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 ""

Unhandled exception: System.ArgumentException: The SetHandler call for command 'GetText.Extractor' is missing an Argument or Option for the parameter at position 4

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.

Refactor commandline options for CommandLine package upgrade limiting options to 8

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

GetText.NET.Extractor: bug, if the backslash (\) in a string

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
изображение

Expected Result:
изображение
изображение

Simple Parsing use Syntax Tree

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

PathExtension requires Windows dll import

Trying to run the extractor I get the following error on macOS, as the code imports a Windows native dll.

[DllImport("shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]

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

image

Running on Windows

image

❯ 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

Ignore wrongly extracted string

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?

Language headers are not parsed

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

Escaped strings are not correctly handled

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.

Non-localizable control-content

Discussed in #24

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.

GetText.Extractor output is nondetererministic

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.