From: Bruno Haible Date: Sun, 2 Sep 2007 09:47:54 +0000 (+0000) Subject: Implement msgctxt for C# ResourceManagers. X-Git-Tag: v0.17~265 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfbde1ec10ba13752314a2d8157d6b1fb0d434e0;p=thirdparty%2Fgettext.git Implement msgctxt for C# ResourceManagers. --- diff --git a/gettext-runtime/intl-csharp/ChangeLog b/gettext-runtime/intl-csharp/ChangeLog index 6a2e34a29..2dd6b740b 100644 --- a/gettext-runtime/intl-csharp/ChangeLog +++ b/gettext-runtime/intl-csharp/ChangeLog @@ -1,3 +1,9 @@ +2007-09-02 Bruno Haible + + Implement msgctxt for C# ResourceManagers. + * intl.cs (GettextResourceManager): New methods GetParticularString, + GetParticularPluralString. + 2006-11-27 Bruno Haible * gettext-0.16.1 released. diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 2881871e0..5e1880602 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,17 @@ +2007-09-02 Bruno Haible + + Implement msgctxt for C# ResourceManagers. + * x-csharp.c (init_keywords): Also register GetParticularString and + GetParticularPluralString. + (init_flag_table_csharp): Update accordingly. + * write-csharp.c: Include xmalloca.h. + (write_csharp_msgid): New function. + (write_csharp_code): Use it instead of write_csharp_string. + (msgdomain_write_csharp): Remove error message if mlp has entries with + context. + * msgunfmt.cs (DumpResource.DumpMessage): Emit an msgctxt line + if the message contain the context separator. + 2007-09-01 Bruno Haible Implement msgctxt for Java ResourceBundles. diff --git a/gettext-tools/src/msgunfmt.cs b/gettext-tools/src/msgunfmt.cs index 1b53abb8e..5b5bf3b8e 100644 --- a/gettext-tools/src/msgunfmt.cs +++ b/gettext-tools/src/msgunfmt.cs @@ -1,5 +1,5 @@ /* GNU gettext for C# - * Copyright (C) 2003-2004 Free Software Foundation, Inc. + * Copyright (C) 2003-2004, 2007 Free Software Foundation, Inc. * Written by Bruno Haible , 2003. * * This program is free software; you can redistribute it and/or modify @@ -56,6 +56,12 @@ namespace GNU.Gettext { Out.Write('"'); } private void DumpMessage (String msgid, String msgid_plural, Object msgstr) { + int separatorPos = msgid.IndexOf('\u0004'); + if (separatorPos >= 0) { + String msgctxt = msgid.Substring(0,separatorPos); + msgid = msgid.Substring(separatorPos+1); + Out.Write("msgctxt "); DumpString(msgctxt); + } Out.Write("msgid "); DumpString(msgid); Out.Write('\n'); if (msgid_plural != null) { Out.Write("msgid_plural "); DumpString(msgid_plural); Out.Write('\n'); diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c index 8664b5288..cfc37513d 100644 --- a/gettext-tools/src/write-csharp.c +++ b/gettext-tools/src/write-csharp.c @@ -82,6 +82,7 @@ #include "plural-exp.h" #include "po-charset.h" #include "xalloc.h" +#include "xmalloca.h" #include "filename.h" #include "fwriteerror.h" #include "clean-temp.h" @@ -216,6 +217,35 @@ write_csharp_string (FILE *stream, const char *str) } +/* Write a (msgctxt, msgid) pair as a string in C# Unicode notation to the + given stream. */ +static void +write_csharp_msgid (FILE *stream, message_ty *mp) +{ + const char *msgctxt = mp->msgctxt; + const char *msgid = mp->msgid; + + if (msgctxt == NULL) + write_csharp_string (stream, msgid); + else + { + size_t msgctxt_len = strlen (msgctxt); + size_t msgid_len = strlen (msgid); + size_t combined_len = msgctxt_len + 1 + msgid_len; + char *combined; + + combined = (char *) xmalloca (combined_len); + memcpy (combined, msgctxt, msgctxt_len); + combined[msgctxt_len] = MSGCTXT_SEPARATOR; + memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1); + + write_csharp_string (stream, combined); + + freea (combined); + } +} + + /* Write C# code that returns the value for a message. If the message has plural forms, it is an expression of type System.String[], otherwise it is an expression of type System.String. */ @@ -523,7 +553,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam for (j = 0; j < mlp->nitems; j++) { fprintf (stream, " t.Add("); - write_csharp_string (stream, mlp->item[j]->msgid); + write_csharp_msgid (stream, mlp->item[j]); fprintf (stream, ","); write_csharp_msgstr (stream, mlp->item[j]); fprintf (stream, ");\n"); @@ -539,7 +569,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam if (mlp->item[j]->msgid_plural != NULL) { fprintf (stream, " t.Add("); - write_csharp_string (stream, mlp->item[j]->msgid); + write_csharp_msgid (stream, mlp->item[j]); fprintf (stream, ","); write_csharp_string (stream, mlp->item[j]->msgid_plural); fprintf (stream, ");\n"); @@ -596,25 +626,6 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, if (mlp->nitems == 0) return 0; - /* Determine whether mlp has entries with context. */ - { - bool has_context; - size_t j; - - has_context = false; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgctxt != NULL) - has_context = true; - if (has_context) - { - multiline_error (xstrdup (""), - xstrdup (_("\ -message catalog has context dependent translations\n\ -but the C# .dll format doesn't support contexts\n"))); - return 1; - } - } - retval = 1; /* Convert the messages to Unicode. */ diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index c469a0c67..2c25c4b9b 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -105,6 +105,8 @@ init_keywords () xgettext.texi! */ x_csharp_keyword ("GetString"); /* Resource{Manager,Set}.GetString */ x_csharp_keyword ("GetPluralString:1,2"); /* GettextResource{Manager,Set}.GetPluralString */ + x_csharp_keyword ("GetParticularString:1c,2"); /* Resource{Manager,Set}.GetParticularString */ + x_csharp_keyword ("GetParticularPluralString:1c,2,3"); /* Resource{Manager,Set}.GetParticularPluralString */ default_keywords = false; } } @@ -115,6 +117,9 @@ init_flag_table_csharp () xgettext_record_flag ("GetString:1:pass-csharp-format"); xgettext_record_flag ("GetPluralString:1:pass-csharp-format"); xgettext_record_flag ("GetPluralString:2:pass-csharp-format"); + xgettext_record_flag ("GetParticularString:2:pass-csharp-format"); + xgettext_record_flag ("GetParticularPluralString:2:pass-csharp-format"); + xgettext_record_flag ("GetParticularPluralString:3:pass-csharp-format"); xgettext_record_flag ("String.Format:1:csharp-format"); } diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 0b1f6d1ed..c4e908551 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,11 @@ +2007-09-02 Bruno Haible + + Implement msgctxt for C# ResourceManagers. + * xgettext-csharp-7: New file. + * msgunfmt-csharp-1: Add a few messages with context. + * lang-csharp: Likewise. + * Makefile.am (TESTS): Add xgettext-csharp-7. + 2007-09-01 Bruno Haible Implement msgctxt for Java ResourceBundles. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 38e094df9..78a6e5e41 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -75,6 +75,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ xgettext-c-16 \ xgettext-csharp-1 xgettext-csharp-2 xgettext-csharp-3 \ xgettext-csharp-4 xgettext-csharp-5 xgettext-csharp-6 \ + xgettext-csharp-7 \ xgettext-elisp-1 xgettext-elisp-2 \ xgettext-glade-1 xgettext-glade-2 xgettext-glade-3 \ xgettext-java-1 xgettext-java-2 xgettext-java-3 xgettext-java-4 \ diff --git a/gettext-tools/tests/lang-csharp b/gettext-tools/tests/lang-csharp index 044303f16..354eace13 100755 --- a/gettext-tools/tests/lang-csharp +++ b/gettext-tools/tests/lang-csharp @@ -43,6 +43,8 @@ class Program { Console.WriteLine(catalog.GetString("'Your command, please?', asked the waiter.")); Console.WriteLine(String.Format(catalog.GetPluralString("a piece of cake","{0} pieces of cake",n), n)); Console.WriteLine(String.Format(catalog.GetString("{0} is replaced by {1}."), "FF", "EUR")); + Console.WriteLine(String.Format(catalog.GetParticularPluralString("++","a piece of cake","{0} pieces of cake",n), n)); + Console.WriteLine(String.Format(catalog.GetParticularString("++","{0} is replaced by {1}."), "FF", "EUR")); } } EOF @@ -72,6 +74,18 @@ msgstr[1] "" #, csharp-format msgid "{0} is replaced by {1}." msgstr "" + +#, csharp-format +msgctxt "++" +msgid "a piece of cake" +msgid_plural "{0} pieces of cake" +msgstr[0] "" +msgstr[1] "" + +#, csharp-format +msgctxt "++" +msgid "{0} is replaced by {1}." +msgstr "" EOF : ${DIFF=diff} @@ -98,6 +112,20 @@ msgstr[1] "{0} morceaux de gateau" #, csharp-format msgid "{0} is replaced by {1}." msgstr "{1} remplace {0}." + +# Euphemistic formulation. +#, csharp-format +msgctxt "++" +msgid "a piece of cake" +msgid_plural "{0} pieces of cake" +msgstr[0] "un morceau de gateau succulent" +msgstr[1] "{0} morceaux de gateau succulent" + +# Euphemistic formulation. +#, csharp-format +msgctxt "++" +msgid "{0} is replaced by {1}." +msgstr "Le nouveau {1} remplace le vieux {0}." EOF tmpfiles="$tmpfiles fr.po.tmp fr.po.new" @@ -149,11 +177,15 @@ cat <<\EOF > prog.ok «Votre commande, s'il vous plait», dit le garçon. 2 morceaux de gateau EUR remplace FF. +2 morceaux de gateau succulent +Le nouveau EUR remplace le vieux FF. EOF cat <<\EOF > prog.oku «Votre commande, s'il vous plait», dit le garçon. 2 morceaux de gateau EUR remplace FF. +2 morceaux de gateau succulent +Le nouveau EUR remplace le vieux FF. EOF : ${LOCALE_FR=fr_FR} diff --git a/gettext-tools/tests/msgunfmt-csharp-1 b/gettext-tools/tests/msgunfmt-csharp-1 index bfd733213..8f948388d 100755 --- a/gettext-tools/tests/msgunfmt-csharp-1 +++ b/gettext-tools/tests/msgunfmt-csharp-1 @@ -40,6 +40,15 @@ msgstr[1] "{0} morceaux de gateau" #, csharp-format msgid "{0} is replaced by {1}." msgstr "{1} remplace {0}." + +# A proximity measure. +msgid "Close" +msgstr "Proche" + +# A menu entry. +msgctxt "File" +msgid "Close" +msgstr "Fermer" EOF tmpfiles="$tmpfiles fr/prog.resources.dll" @@ -67,6 +76,13 @@ msgstr "" msgid "'Your command, please?', asked the waiter." msgstr "«Votre commande, s'il vous plait», dit le garçon." +msgid "Close" +msgstr "Proche" + +msgctxt "File" +msgid "Close" +msgstr "Fermer" + msgid "a piece of cake" msgid_plural "{0} pieces of cake" msgstr[0] "un morceau de gateau"