]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - locale/po2strings.c
Add ellipsis to "Looking for printer" message.
[thirdparty/cups.git] / locale / po2strings.c
index fd869a77b50eaa5d02d11442d0089caf389d11cf..0536c4360b49c06f8002e64cbf9aee98954ea194 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Convert a GNU gettext .po file to an Apple .strings file.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
@@ -49,6 +49,9 @@
  * characters like newline and the double quote character.
  */
 
+static char    *normalize_string(const char *idstr, char *buffer, size_t bufsize);
+
+
 /*
  *   main() - Convert .po file to .strings.
  */
@@ -66,7 +69,8 @@ main(int  argc,                               /* I - Number of command-line args */
                        *ptr,           /* Pointer into buffer */
                        *temp,          /* New string */
                        *msgid,         /* msgid string */
-                       *msgstr;        /* msgstr string */
+                       *msgstr,        /* msgstr string */
+                       normalized[8192];/* Normalized msgid string */
   size_t               length;         /* Length of combined strings */
   int                  use_msgid;      /* Use msgid strings for msgstr? */
 
@@ -190,8 +194,7 @@ main(int  argc,                             /* I - Number of command-line args */
         if (msgid && msgstr)
        {
          if (*msgid)
-            cupsFilePrintf(strings, "\"%s\" = \"%s\";\n", msgid,
-                          (use_msgid || !*msgstr) ? msgid : msgstr);
+            cupsFilePrintf(strings, "\"%s\" = \"%s\";\n", msgid, normalize_string((use_msgid || !*msgstr) ? msgid : msgstr, normalized, sizeof(normalized)));
        }
 
        if (msgid)
@@ -270,8 +273,7 @@ main(int  argc,                             /* I - Number of command-line args */
   if (msgid && msgstr)
   {
     if (*msgid)
-      cupsFilePrintf(strings, "\"%s\" = \"%s\";\n", msgid,
-                    (use_msgid || !*msgstr) ? msgid : msgstr);
+      cupsFilePrintf(strings, "\"%s\" = \"%s\";\n", msgid, normalize_string((use_msgid || !*msgstr) ? msgid : msgstr, normalized, sizeof(normalized)));
   }
 
   if (msgid)
@@ -287,6 +289,73 @@ main(int  argc,                            /* I - Number of command-line args */
 }
 
 
+/*
+ * 'normalize_string()' - Normalize a msgid string.
+ *
+ * This function converts ASCII ellipsis and double quotes to their Unicode
+ * counterparts.
+ */
+
+static char *                          /* O - Normalized string */
+normalize_string(const char *idstr,    /* I - msgid string */
+                 char       *buffer,   /* I - Normalized string buffer */
+                 size_t     bufsize)   /* I - Size of string buffer */
+{
+  char *bufptr = buffer,               /* Pointer into buffer */
+       *bufend = buffer + bufsize - 3; /* End of buffer */
+  int  quote = 0;                      /* Quote direction */
+
+
+  while (*idstr && bufptr < bufend)
+  {
+    if (*idstr == '.' && idstr[1] == '.' && idstr[2] == '.')
+    {
+     /*
+      * Convert "..." to Unicode ellipsis...
+      */
+
+      *bufptr++ = (char)0xE2;
+      *bufptr++ = (char)0x80;
+      *bufptr++ = (char)0xA6;
+      idstr += 2;
+    }
+    else if (*idstr == '\"')
+    {
+      if (quote)
+      {
+       /*
+        * Convert " to right quote.
+        */
+
+       *bufptr++ = (char)0xE2;
+       *bufptr++ = (char)0x80;
+       *bufptr++ = (char)0x9D;
+      }
+      else
+      {
+       /*
+        * Convert " to left quote.
+        */
+
+       *bufptr++ = (char)0xE2;
+       *bufptr++ = (char)0x80;
+       *bufptr++ = (char)0x9C;
+      }
+
+      quote = !quote;
+    }
+    else
+      *bufptr++ = *idstr;
+
+    idstr ++;
+  }
+
+  *bufptr = '\0';
+
+  return (buffer);
+}
+
+
 /*
  * End of "$Id$".
  */