Git Product home page Git Product logo

ngettext's People

Contributors

am11 avatar jpk6789 avatar kukkimonsuta avatar mburtscher avatar neris 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngettext's Issues

CRLF-based verbatim string literals are not translated.

Hello.

I use NGettext with gettext on Windows.

In my project, all source codes are CRLF-based.

but, the verbatim literals like below are not translated.

// in CRLF-based source code.

var translated = _("foo bar baz");

var not_traslated = _(@"
foo
bar
baz
");

The gettext tools understand only LF (without CR) I think, so built *.po and *.mo files include only LF even though with CRLF-based source codes.
and, I found this has happened because NGettext doesn't ignore CRLF and LF differences.

I know I can change all of my code to LF-based, but it may be forgotten in the future because CRLF is the default on Windows.

so, I want NGettext to ignore the differences between CRLF and LF.

Thanks.

Plural translation wrong

ICatalog catalog = new Catalog("lv", "./locale", new CultureInfo("lv"));
Console.WriteLine(catalog.GetString("My name is {0}"), "Enzo");
int i = 0;
Console.WriteLine(catalog.GetPluralString("I'm {0} year old.", "I'm {0} years old.", i), i);
i = 21;
Console.WriteLine(catalog.GetPluralString("I'm {0} year old.", "I'm {0} years old.", i), i);
i = 22;
Console.WriteLine(catalog.GetPluralString("I'm {0} year old.", "I'm {0} years old.", i), i);

Those are translated to latvian which has (nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2);) using Poedit.
Console prints: (in paranthesis I have added from which translation it comes)

Mani sauc Enzo
Man ir 0 gads. (n -> 1, 21, 31, 41 translation)
Man ir 21 gadu. (n -> 2, 3, 4, 5.. translation)
Man ir 22 gadu. (Zero translation)

I really don't care about '0' case, because that's the first time I hear my native language has 3 types of those, but anyway, they are all wrong! xgettext prints this correctly.

String with context doesn't get localized and added to the .po file

Hello,
i'm using NGettext library combined with T.cs example class to localize my C# code.

GetString and GetPluralString are working fine:
T._("Hello, World!");
T._n("You have {0} apple.", "You have {0} apples.", count, count);

But GetParticularString doesn't get translated, and there is no string generated in a .po file.
T._p("Context", "Hello, World!");

I'm not sure if that's a bug or i'm doing something wrong?
I'm using Windows and xgettext tool, downloaded from here:
https://sourceforge.net/projects/getgnuwin32/files/getgnuwin32/0.6.30/

This is how i'm generating po files:
"i know that keyword '_p:1c,2' should cover that case"

"C:\Program Files (x86)\GnuWin32\bin\xgettext.exe" -k_ -k_n:1,2 -k_p:1c,2 -k_pn:1c,2,3 --from-code=UTF-8 -LC# --no-location --omit-header -o"%projectDir%locale\en-US\LC_MESSAGES\newmessages.pot" -fprojectfiles.txt

"C:\Program Files (x86)\GnuWin32\bin\msgmerge.exe" --backup=none -U "%projectDir%locale\en-US\LC_MESSAGES\messages.po" "%projectDir%locale\en-US\LC_MESSAGES\newmessages.pot"

Thanks for your help.

T class template plural method string isn't extracted bt xgettext

I'm using your T class in order to mark my strings.

I perform this xgettext command:

xgettext -kT._ -kT._n -LC# --omit-header --from-code=UTF-8 -o messages.pot -c -n ./TransClassOne.cs

In my dummy class I have strings like these:

public string sayHello(string person, int n)
{
    return String.Format(Utils.T._n("Hello, {0} - once!!", "Hello, {0} - twice or more!!", n), person);
}

After perform xgettext command, it only extracts first parameter string value: "Hello, {0} - once".

I've tried specifying -kT._ -kT._n.
Any idea?

Exception running gettext.extractor with no parameters.

I am testing GetText.NET.Extractor but I cannot make it work:

dotnet tool install --global GetText.NET.Extractor
gettext.extractor --version
1.0.5+d63f2976f1

However If I run gettext.extractor with no parameter, I get:

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()

How i can save catalog ?

Hi
I want use form UI to translate all key
after translating i want know how i can save after edited ?
thank you

Automated update of the Unicode CLDR Project data

In the DefaultPluralRuleGenerator we use pre-compiled plural forms for most known cultures based on the Unicode CLDR Project data. Honestly I don't remember how I implemented it back in 2012.
We need to update this rules to the latest CLDR release (v28) and make an automated update process for future CLDR releases and document it.

Plural rules can be found in: core.zip/common/supplemental/{plurals.xml|pluralRanges.xml}.

Original GNU/Gettext's msginit has support for the Unicode CLDR Project format. We can try use it.

Also this project looks interesting.

Backslashes in MsgId are interpreted as escape char

When calling catalog.GetString("\ ") on an empty catalog, I receive " " as result, the backslash disappears.

Is this intended or a bug? If it is a bug, I can look into that and (hopefully) create a PR.

Comparison

Hi,

There seem to be a lot of i18n gettext-inspired-c# libraries, though at first sight yours seems the cleanest (UTs, CI, interface-API, pure gettext).
Though some provide more features, e.g.:

  • SecondLanguage provides PO as well
  • Vernacular provides tools for extracting PO files from assemblies, gender support, and xaml bindings

Any thoughts around those other i18n libs and how ngettext fits ?

Thx

Code signing of NGettext.dll

I use NGettext with embedded .mo files (instead of having satellite assemblies for all the languages). But I see the NGettext.dll is required and added to the output folder. Unfortunately it does not have a digital signature, which is required for online publishing (ClickOnce). I could sign it using my own code signing certificate but cannot find the right event (e.g. before/after compile/build/publish) or location (e.g. obj/bin/publish). Ultimately, NGettext.dll.deploy needs to be signed just before it is published. Do you have any tips? I am developing in VB.NET (Visual Studio 2017).

NuGet package

Any plans for making a nuget package for this great tool?

Catalog path confussion

I am trying to use NGetText using T.cs and suggested Catalog loading code

Here is what I use to load a mo file
public static readonly ICatalog _Catalog = new Catalog("MyTestWebsite", "./locale");

I can't get the translated string from GetText function. So I am most probably pointing to some wrong location.

My problem is the same line just works the same way if I use a random string instead of MyTestWebsite. It should throw an exception if that file does not exist. And I see no filename when I debug into that variable.

So I am not sure what file it is trying to load, is it /bin/locale/... ? is it /locale/.... ? or is it trying to load the file from another directory?

Mark constants for translation

What is your recommendation to mark constants for translation e.g.:

public const string Hello = "Hello";

This won't be found by xgettext nor poedit

Trouble Compiling NGettext in Visual Studio 2019

I'm getting several

error CS0234: The type or namespace name 'AssemblyMetadataAttributeAttribute' does not exist in the namespace 'System.Reflection' (are you missing an assembly reference?)

errors when I try to compile this repository in Visual Studio 2019.

I can't get the plural string.

I am making a pot file in Japanese. And I have translated it into English po file.

pot is here:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-04-11 18:59+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: Sdx/Validation/StringLength.cs:15
#, csharp-format
msgid "現在{0}文字"
msgid_plural "現在{0}文字"
msgstr[0] ""
msgstr[1] ""

en.po is here:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-04-12 13:22+0900\n"
"PO-Revision-Date: 2016-04-12 13:23+0900\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.7\n"

#: Sdx/Validation/StringLength.cs:15
#, csharp-format
msgid "現在{0}文字"
msgid_plural "現在{0}文字"
msgstr[0] "{0} character now"
msgstr[1] "{0} characters now"

c# code is here:

var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream("Sdx.locale.en.message.mo");

Catalog catalog = new Catalog(new MoLoader(stream));
Console.WriteLog(catalog.GetPluralString("現在{0}文字", "現在{0}文字", 1, 1));
//log is `1 character now`

Console.WriteLog(catalog.GetPluralString("現在{0}文字", "現在{0}文字", 2, 2));
//log is `2 character now`

Two codes return the same string.
What is wrong with my code ?

Use ConcurrentDictionary instead of Dictionary in Catalog?

The Translation in Catalog.cs is Dictionary<string, string[]>, can we use ConcurrentDicitionary instead in order to make it thread safe to get translation?

public Dictionary<string, string[]> Translations { get; protected set; }

public virtual string[] GetTranslations(string messageId)
{
if (!this.IsTranslationExist(messageId)) return null;
return this.Translations[messageId];
}

Install package fails on Xamarin.Android and Xamarin.iOS

I'm trying to use NGettext from Xamarin, I was able to install it into the PCL, however when it comes to installing it into the platform-specific projects, the installation process will fail with the following message:
"Failed to add reference to 'System.Collections'. Please make sure that it is in the Global Assembly Cache."
Taking a look at the output there is an other message right after the package installation failed:
"Install failed. Rolling back...
Package 'NGettext.0.6.1 : Microsoft.CSharp [4.0.1-rc2-24027, ), System.Collections [4.0.11-rc2-24027, ), System.Diagnostics.Debug [4.0.11-rc2-24027, ), System.Diagnostics.TraceSource [4.0.0-rc2-24027, ), System.Globalization [4.0.11-rc2-24027, ), System.IO [4.1.0-rc2-24027, ), System.IO.FileSystem [4.0.1-rc2-24027, ), System.Runtime [4.1.0-rc2-24027, ), System.Runtime.Extensions [4.1.0-rc2-24027, ), System.Runtime.InteropServices [4.1.0-rc2-24027, ), System.Text.RegularExpressions [4.0.12-rc2-24027, )' does not exist in project"

Does it mean that NGettext can't be used in Xamarin.Android and Xamarin.iOS projects?

Question: Why does 'ReadUInt16' have the `CLSCompliant(false)` attribute?

When used in Unity I am seeing the following warning:

BigEndianBinaryReader.ReadUInt16()' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant

What is the purpose of the attribute in this scenario?

// This method does not have the attribute:
public override short ReadInt16()
{
	this._FillBuffer(2);
	return (short)(this._Buffer[1] | this._Buffer[0] << 8);
}

// This method does:
[CLSCompliant(false)]
public override ushort ReadUInt16()
{
	this._FillBuffer(2);
	return (ushort)(this._Buffer[1] | this._Buffer[0] << 8);
}

How to add cultures

We are currently evaluating NGettext and are in the need to add cultures that are not defined in .Net itself, especially "Gaelic (Scotland)" (iso code "gla") and "Catalan (Valencia)" (iso code ca, but the language is different from Catalonian Catalan, which also has "ca").

As there is no easy way to add new CultureInfo instances (this requires admin privileges), what would be an alternative to allow this inside an application?

Would you be open for a pull request that replaces the usage of CultureInfo with something we can populate ourselves? (while maintain API compatibility and keep calls with CultureInfo)

Or is there an easier way to achieve this?

Allow to pass a IFormatProvider to the Get*String functions

Currently, the only way to use a custom IFormatProvider with NGettext is to subclass CultureInfo, which is not very convenient.

The Get*String methods of ICatalog could take a IFormatProvider, so one can use custom formatters. The given IFormatProvider would be in charge of formatting numbers and date correctly.

Usage example: I am trying to do a simple "grammar macro" text, which looks like this:

String.Format("{0:They} {0:are} coding in C#", myPerson);

Which could give He is coding in C#, or retrieve a translation with other formatters from the catalog, like {0:Il} cod{0:ent} en C#

Is there a way to load .po files?

Hey

Just a quick question, is it possible to load the non-compiled .po files? or would this require a custom loader implementation?

Many thanks

Question: Support for translation of strings with more than one plural?

Is there consideration for support for the translation of statements that contain multiple plurals? I have looked at the docs and interface and I don't see such, unless I missed it. For example, a statement such as:

"Your payment plan requires n payments each month for the next i years."

Thanks for this project, great work!

Net5.0 Support

How can add support for Net5.0?

I try add to NGettext.cjproj

<TargetFrameworks>net20;net35;net40;net45;net46;portable-net40+sl5+win8+wp8;portable-net40+sl5+win8+wpa81+wp8;netstandard1.0;netstandard1.3;netstandard2.0;net5.0</TargetFrameworks>

But I get this
imagen

And when try to import in my net5.0 project, this not work.
imagen

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.