]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
The xgettext -j option may need to do charset conversion.
authorBruno Haible <bruno@clisp.org>
Thu, 13 Jan 2005 12:19:51 +0000 (12:19 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:03 +0000 (12:12 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/msgl-ascii.c
gettext-tools/src/msgl-ascii.h
gettext-tools/src/x-po.c
gettext-tools/src/xgettext.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am

index 545d9ab8f4bbb8c8061de1e1c7eaf189b63486ed..231a6275ed0f60f65f27a8b1e051f62a9391b7b5 100644 (file)
@@ -1,3 +1,16 @@
+2005-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * msgl-ascii.h (is_ascii_msgdomain_list): New declaration.
+       * msgl-ascii.c (is_ascii_msgdomain_list): New function.
+       * x-po.c (header_charset): New variable.
+       (extract_add_message): When seeing the header entry, store the charset
+       in header_charset.
+       (extract): Store the value of header_charset in the new constructed
+       header entry.
+       * xgettext.c (main): Convert the existing PO file to UTF-8 if it was
+       not entirely ASCII.
+       Reported by Jörg Schilling <schilling@fokus.fraunhofer.de>.
+
 2005-01-08  Bruno Haible  <bruno@clisp.org>
 
        * msggrep.c (usage): Explain COMMENT-PATTERN syntax as well.
index 90c401b5fa8cc00352d3a5723a76573a6c942208..da7494153ca0acf444b013be9ca78ae6dcc65b1e 100644 (file)
@@ -1,5 +1,5 @@
 /* Message list test for ASCII character set.
-   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2002, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -87,3 +87,15 @@ is_ascii_message_list (message_list_ty *mlp)
 
   return true;
 }
+
+bool
+is_ascii_msgdomain_list (msgdomain_list_ty *mdlp)
+{
+  size_t k;
+
+  for (k = 0; k < mdlp->nitems; k++)
+    if (!is_ascii_message_list (mdlp->item[k]->messages))
+      return false;
+
+  return true;
+}
index bff312964ad9a7e762a5124872b8a7a8c7f2462b..b4874e08abb5177cb300424e7a0b4d73b44359d0 100644 (file)
@@ -1,5 +1,5 @@
 /* Message list test for ASCII character set.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -37,6 +37,8 @@ extern bool
        is_ascii_message (message_ty *mp);
 extern bool
        is_ascii_message_list (message_list_ty *mlp);
+extern bool
+       is_ascii_msgdomain_list (msgdomain_list_ty *mdlp);
 
 
 #ifdef __cplusplus
index 89580b798428b55529fa4feb090dfec0060a1054..72045e1724774028127384c0301bf5715cb5b5c2 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext PO and JavaProperties backends.
-   Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -40,6 +40,9 @@
 #define _(str) gettext (str)
 
 
+/* The charset found in the header entry.  */
+static char *header_charset;
+
 /* Define a subclass extract_po_reader_ty of default_po_reader_ty.  */
 
 static void
@@ -56,12 +59,30 @@ extract_add_message (default_po_reader_ty *this,
     goto discard;
 
   /* If the msgid is the empty string, it is the old header.  Throw it
-     away, we have constructed a new one.
+     away, we have constructed a new one.  Only remember its charset.
      But if no new one was constructed, keep the old header.  This is useful
      because the old header may contain a charset= directive.  */
   if (*msgid == '\0' && !xgettext_omit_header)
     {
-      discard:
+      const char *charsetstr = strstr (msgstr, "charset=");
+
+      if (charsetstr != NULL)
+       {
+         size_t len;
+         char *charset;
+
+         charsetstr += strlen ("charset=");
+         len = strcspn (charsetstr, " \t\n");
+         charset = (char *) xmalloc (len + 1);
+         memcpy (charset, charsetstr, len);
+         charset[len] = '\0';
+
+         if (header_charset != NULL)
+           free (header_charset);
+         header_charset = charset;
+       }
+
+     discard:
       free (msgid);
       free (msgstr);
       return;
@@ -108,6 +129,8 @@ extract (FILE *fp,
 {
   default_po_reader_ty *pop;
 
+  header_charset = NULL;
+
   pop = default_po_reader_alloc (&extract_methods);
   pop->handle_comments = true;
   pop->handle_filepos_comments = (line_comment != 0);
@@ -119,6 +142,46 @@ extract (FILE *fp,
   po_scan ((abstract_po_reader_ty *) pop, fp, real_filename, logical_filename,
           syntax);
   po_reader_free ((abstract_po_reader_ty *) pop);
+
+  if (header_charset != NULL)
+    {
+      if (!xgettext_omit_header)
+       {
+         /* Put the old charset into the freshly constructed header entry.  */
+         message_ty *mp = message_list_search (mdlp->item[0]->messages, "");
+
+         if (mp != NULL && !mp->obsolete)
+           {
+             const char *header = mp->msgstr;
+
+             if (header != NULL)
+               {
+                 const char *charsetstr = strstr (header, "charset=");
+
+                 if (charsetstr != NULL)
+                   {
+                     size_t len, len1, len2, len3;
+                     char *new_header;
+
+                     charsetstr += strlen ("charset=");
+                     len = strcspn (charsetstr, " \t\n");
+
+                     len1 = charsetstr - header;
+                     len2 = strlen (header_charset);
+                     len3 = (header + strlen (header)) - (charsetstr + len);
+                     new_header = (char *) xmalloc (len1 + len2 + len3 + 1);
+                     memcpy (new_header, header, len1);
+                     memcpy (new_header + len1, header_charset, len2);
+                     memcpy (new_header + len1 + len2, charsetstr + len, len3 + 1);
+                     mp->msgstr = new_header;
+                     mp->msgstr_len = len1 + len2 + len3 + 1;
+                   }
+               }
+           }
+       }
+
+      free (header_charset);
+    }
 }
 
 
index 3732a5a580c8ad3b0eaf7f3c9af1c9342ab57e38..dba5ff4db902e33644ee071a51813347cdb558d7 100644 (file)
@@ -621,6 +621,8 @@ This version was built without iconv()."),
       extractor_ty po_extractor = { extract_po, NULL, NULL, NULL };
 
       extract_from_file (file_name, po_extractor, mdlp);
+      if (!is_ascii_msgdomain_list (mdlp))
+       mdlp = iconv_msgdomain_list (mdlp, "UTF-8", file_name);
 
       dir_list_restore (saved_directory_list);
     }
index 8186f97e7cde2555c8da709411520ea4d20a5450..36ecef2231ad3c47d5db9b3c968a5efd9d241a5f 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * xgettext-8: New file.
+       * Makefile.am (TESTS): Add it.
+
 2005-01-05  Bruno Haible  <bruno@clisp.org>
 
        * tstgettext.c (main): Update year in --version output.
index 1a74b3f602904bb4bb26aa74dcbdc5767ed12419..229589367237275e7db22bb9d69fd1ad8e32df02 100644 (file)
@@ -1,5 +1,5 @@
 ## Makefile for the gettext-tools/tests subdirectory of GNU gettext
-## Copyright (C) 1995-1997, 2001-2004 Free Software Foundation, Inc.
+## Copyright (C) 1995-1997, 2001-2005 Free Software Foundation, Inc.
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -58,7 +58,7 @@ TESTS = gettext-1 gettext-2 \
        msgunfmt-tcl-1 \
        msguniq-1 msguniq-2 msguniq-3 msguniq-4 \
        xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \
-       xgettext-7 \
+       xgettext-7 xgettext-8 \
        xgettext-awk-1 \
        xgettext-c-1 xgettext-c-2 xgettext-c-3 xgettext-c-4 xgettext-c-5 \
        xgettext-c-6 xgettext-c-7 xgettext-c-8 xgettext-c-9 \