]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Implement msgctxt for C# ResourceManagers.
authorBruno Haible <bruno@clisp.org>
Sun, 2 Sep 2007 09:47:54 +0000 (09:47 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:03 +0000 (12:15 +0200)
gettext-runtime/intl-csharp/ChangeLog
gettext-tools/src/ChangeLog
gettext-tools/src/msgunfmt.cs
gettext-tools/src/write-csharp.c
gettext-tools/src/x-csharp.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/lang-csharp
gettext-tools/tests/msgunfmt-csharp-1

index 6a2e34a295c9c6e513c94521992c7ba38ce0e4d1..2dd6b740b660b9f57014aa0abcf272fd5453c0ba 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-02  Bruno Haible  <bruno@clisp.org>
+
+       Implement msgctxt for C# ResourceManagers.
+       * intl.cs (GettextResourceManager): New methods GetParticularString,
+       GetParticularPluralString.
+
 2006-11-27  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.16.1 released.
index 2881871e0cfd7c6c8949ead915ccebdbc6370f65..5e1880602126b460b47708fa5f772ae449130b33 100644 (file)
@@ -1,3 +1,17 @@
+2007-09-02  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        Implement msgctxt for Java ResourceBundles.
index 1b53abb8e008e2210a3d1e34a10ef89b3d13388c..5b5bf3b8e839571d2963e454d1482c48a31348ed 100644 (file)
@@ -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 <bruno@clisp.org>, 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');
index 8664b528862143777ace42b69020d1b29629c227..cfc37513d4fc8c55cb5889c6ff973b89863e827a 100644 (file)
@@ -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.  */
index c469a0c67fbb9d487f87c93823044736d224fa80..2c25c4b9b4cc3dd3e6b8765f0c957e7adee49910 100644 (file)
@@ -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");
 }
 
index 0b1f6d1edf6593656d25a057970187847f939440..c4e908551ba18eb29da5b0023b4a1e1d9fab5c5b 100644 (file)
@@ -1,3 +1,11 @@
+2007-09-02  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        Implement msgctxt for Java ResourceBundles.
index 38e094df9c5da58b05faf99259cbf0cb75b4b277..78a6e5e41b883ee8fd978df6bc9f2add8e5a2f81 100644 (file)
@@ -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 \
index 044303f1609a8c1c6205a1148de2db8d74b7d4d8..354eace13888c23a683a789fbe954335cca2b8ab 100755 (executable)
@@ -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}
index bfd733213abdb11fae4937cab0fc2e0de78de605..8f948388d320aa61efd799daa8e9b9471cc452ac 100755 (executable)
@@ -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"