From: Bruno Haible Date: Sun, 2 Sep 2007 09:41:01 +0000 (+0000) Subject: Implement msgctxt for C# ResourceManagers. X-Git-Tag: v0.17~266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ceabed6e0ec95895779441031efd9db1f37cc7c;p=thirdparty%2Fgettext.git Implement msgctxt for C# ResourceManagers. --- diff --git a/gettext-runtime/intl-csharp/intl.cs b/gettext-runtime/intl-csharp/intl.cs index 854a877d4..43f0efac9 100644 --- a/gettext-runtime/intl-csharp/intl.cs +++ b/gettext-runtime/intl-csharp/intl.cs @@ -1,5 +1,5 @@ /* GNU gettext for C# - * Copyright (C) 2003, 2005 Free Software Foundation, Inc. + * Copyright (C) 2003, 2005, 2007 Free Software Foundation, Inc. * Written by Bruno Haible , 2003. * * This program is free software; you can redistribute it and/or modify it @@ -39,6 +39,9 @@ * returns the (English) message key in that case. * - In the .NET resource approach, there is no support for plural handling. * In the GNU gettext approach, we have the GetPluralString function. + * - In the .NET resource approach, there is no support for context specific + * translations. + * In the GNU gettext approach, we have the GetParticularString function. * * To compile GNU gettext message catalogs into C# assemblies, the msgfmt * program can be used. @@ -295,6 +298,53 @@ namespace GNU.Gettext { // ======================== Public Methods ======================== + /// + /// Returns the translation of in the context + /// of a given culture. + /// + /// the context for the key string, an ASCII + /// string + /// the key string to be translated, an ASCII + /// string + /// the translation of , or + /// if none is found + public String GetParticularString (String msgctxt, String msgid, CultureInfo culture) { + String combined = msgctxt + "\u0004" + msgid; + foreach (GettextResourceSet rs in GetResourceSetsFor(culture)) { + String translation = rs.GetString(combined); + if (translation != null) + return translation; + } + // Fallback. + return msgid; + } + + /// + /// Returns the translation of and + /// in the context of + /// in a given culture, choosing the right + /// plural form depending on the number . + /// + /// the context for the key string, an ASCII + /// string + /// the key string to be translated, an ASCII + /// string + /// the English plural of , + /// an ASCII string + /// the number, should be >= 0 + /// the translation, or or + /// if none is found + public virtual String GetParticularPluralString (String msgctxt, String msgid, String msgidPlural, long n, CultureInfo culture) { + String combined = msgctxt + "\u0004" + msgid; + foreach (GettextResourceSet rs in GetResourceSetsFor(culture)) { + String translation = rs.GetPluralString(combined, msgidPlural, n); + if (translation != null) + return translation; + } + // Fallback: Germanic plural form. + return (n == 1 ? msgid : msgidPlural); + } + /// /// Returns the translation of in the current /// culture. @@ -323,6 +373,39 @@ namespace GNU.Gettext { return GetPluralString(msgid, msgidPlural, n, CultureInfo.CurrentUICulture); } + /// + /// Returns the translation of in the context + /// of in the current culture. + /// + /// the context for the key string, an ASCII + /// string + /// the key string to be translated, an ASCII + /// string + /// the translation of , or + /// if none is found + public String GetParticularString (String msgctxt, String msgid) { + return GetParticularString(msgctxt, msgid, CultureInfo.CurrentUICulture); + } + + /// + /// Returns the translation of and + /// in the context of + /// in the current culture, choosing the + /// right plural form depending on the number . + /// + /// the context for the key string, an ASCII + /// string + /// the key string to be translated, an ASCII + /// string + /// the English plural of , + /// an ASCII string + /// the number, should be >= 0 + /// the translation, or or + /// if none is found + public virtual String GetParticularPluralString (String msgctxt, String msgid, String msgidPlural, long n) { + return GetParticularPluralString(msgctxt, msgid, msgidPlural, n, CultureInfo.CurrentUICulture); + } + } ///