/*
- * "$Id: checkpo.c 7223 2008-01-16 23:41:19Z mike $"
- *
* Verify that translations in the .po file have the same number and type of
* printf-style format strings.
*
- * Copyright 2007-2009 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*
* Usage:
*
- * checkpo filename.po [... filenameN.po]
+ * checkpo filename.{po,strings} [... filenameN.{po,strings}]
*
* Compile with:
*
* gcc -o checkpo checkpo.c `cups-config --libs`
- *
- * Contents:
- *
- * main() - Validate .po files.
- * abbreviate() - Abbreviate a message string as needed.
- * collect_formats() - Collect all of the format strings in the msgid.
- * free_formats() - Free all of the format strings.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
-#include <cups/i18n.h>
+#include <cups/cups-private.h>
/*
/*
- * 'main()' - Validate .po files.
+ * 'main()' - Validate .po and .strings files.
*/
int /* O - Exit code */
if (argc < 2)
{
- puts("Usage: checkpo filename.po [... filenameN.po]");
+ puts("Usage: checkpo filename.{po,strings} [... filenameN.{po,strings}]");
return (1);
}
/*
- * Check every .po file on the command-line...
+ * Check every .po or .strings file on the command-line...
*/
for (i = 1, status = 0; i < argc; i ++)
* Use the CUPS .po loader to get the message strings...
*/
- if ((po = _cupsMessageLoad(argv[i], 0)) == NULL)
+ if (strstr(argv[i], ".strings"))
+ po = _cupsMessageLoad(argv[i], _CUPS_MESSAGE_STRINGS);
+ else
+ po = _cupsMessageLoad(argv[i], _CUPS_MESSAGE_PO | _CUPS_MESSAGE_EMPTY);
+
+ if (!po)
{
perror(argv[i]);
return (1);
}
+ if (i > 1)
+ putchar('\n');
printf("%s: ", argv[i]);
fflush(stdout);
msg;
msg = (_cups_message_t *)cupsArrayNext(po))
{
+ /*
+ * Make sure filter message prefixes are not translated...
+ */
+
+ if (!strncmp(msg->msg, "ALERT:", 6) || !strncmp(msg->msg, "CRIT:", 5) ||
+ !strncmp(msg->msg, "DEBUG:", 6) || !strncmp(msg->msg, "DEBUG2:", 7) ||
+ !strncmp(msg->msg, "EMERG:", 6) || !strncmp(msg->msg, "ERROR:", 6) ||
+ !strncmp(msg->msg, "INFO:", 5) || !strncmp(msg->msg, "NOTICE:", 7) ||
+ !strncmp(msg->msg, "WARNING:", 8))
+ {
+ if (pass)
+ {
+ pass = 0;
+ puts("FAIL");
+ }
+
+ printf(" Bad prefix on filter message \"%s\"\n",
+ abbreviate(msg->msg, idbuf, sizeof(idbuf)));
+ }
+
+ idfmt = msg->msg + strlen(msg->msg) - 1;
+ if (idfmt >= msg->msg && *idfmt == '\n')
+ {
+ if (pass)
+ {
+ pass = 0;
+ puts("FAIL");
+ }
+
+ printf(" Trailing newline in message \"%s\"\n",
+ abbreviate(msg->msg, idbuf, sizeof(idbuf)));
+ }
+
+ for (; idfmt >= msg->msg; idfmt --)
+ if (!isspace(*idfmt & 255))
+ break;
+
+ if (idfmt >= msg->msg && *idfmt == '!')
+ {
+ if (pass)
+ {
+ pass = 0;
+ puts("FAIL");
+ }
+
+ printf(" Exclamation in message \"%s\"\n",
+ abbreviate(msg->msg, idbuf, sizeof(idbuf)));
+ }
+
+ if ((idfmt - 2) >= msg->msg && !strncmp(idfmt - 2, "...", 3))
+ {
+ if (pass)
+ {
+ pass = 0;
+ puts("FAIL");
+ }
+
+ printf(" Ellipsis in message \"%s\"\n",
+ abbreviate(msg->msg, idbuf, sizeof(idbuf)));
+ }
+
if (!msg->str || !msg->str[0])
{
untranslated ++;
continue;
}
- else if (strchr(msg->id, '%'))
+ else if (strchr(msg->msg, '%'))
{
- idfmts = collect_formats(msg->id);
+ idfmts = collect_formats(msg->msg);
strfmts = collect_formats(msg->str);
fmtidx = 0;
printf(" Bad translation string \"%s\"\n for \"%s\"\n",
abbreviate(msg->str, strbuf, sizeof(strbuf)),
- abbreviate(msg->id, idbuf, sizeof(idbuf)));
+ abbreviate(msg->msg, idbuf, sizeof(idbuf)));
fputs(" Translation formats:", stdout);
for (strfmt = (char *)cupsArrayFirst(strfmts);
strfmt;
*/
for (strfmt = msg->str; *strfmt; strfmt ++)
- if (*strfmt == '\\' &&
- strfmt[1] != '\\' && strfmt[1] != 'n' && strfmt[1] != 'r' &&
- strfmt[1] != 't' && strfmt[1] != '\"' && !isdigit(strfmt[1] & 255))
- {
- if (pass)
+ {
+ if (*strfmt == '\\')
+ {
+ strfmt ++;
+
+ if (*strfmt != '\\' && *strfmt != 'n' && *strfmt != 'r' && *strfmt != 't' && *strfmt != '\"' && !isdigit(*strfmt & 255))
{
- pass = 0;
- puts("FAIL");
+ if (pass)
+ {
+ pass = 0;
+ puts("FAIL");
+ }
+
+ printf(" Bad escape \\%c in filter message \"%s\"\n"
+ " for \"%s\"\n", strfmt[1],
+ abbreviate(msg->str, strbuf, sizeof(strbuf)),
+ abbreviate(msg->msg, idbuf, sizeof(idbuf)));
+ break;
}
-
- printf(" Bad escape \\%c in filter message \"%s\"\n"
- " for \"%s\"\n\n", strfmt[1],
- abbreviate(msg->str, strbuf, sizeof(strbuf)),
- abbreviate(msg->id, idbuf, sizeof(idbuf)));
- break;
- }
-
- /*
- * Make sure filter message prefixes are preserved...
- */
-
- if ((!strncmp(msg->id, "ALERT:", 6) && strncmp(msg->str, "ALERT:", 6)) ||
- (!strncmp(msg->id, "CRIT:", 5) && strncmp(msg->str, "CRIT:", 5)) ||
- (!strncmp(msg->id, "DEBUG:", 6) && strncmp(msg->str, "DEBUG:", 6)) ||
- (!strncmp(msg->id, "DEBUG2:", 7) && strncmp(msg->str, "DEBUG2:", 7)) ||
- (!strncmp(msg->id, "EMERG:", 6) && strncmp(msg->str, "EMERG:", 6)) ||
- (!strncmp(msg->id, "ERROR:", 6) && strncmp(msg->str, "ERROR:", 6)) ||
- (!strncmp(msg->id, "INFO:", 5) && strncmp(msg->str, "INFO:", 5)) ||
- (!strncmp(msg->id, "NOTICE:", 7) && strncmp(msg->str, "NOTICE:", 7)) ||
- (!strncmp(msg->id, "WARNING:", 8) && strncmp(msg->str, "WARNING:", 8)))
- {
- if (pass)
- {
- pass = 0;
- puts("FAIL");
}
-
- printf(" Bad prefix on filter message \"%s\"\n for \"%s\"\n\n",
- abbreviate(msg->str, strbuf, sizeof(strbuf)),
- abbreviate(msg->id, idbuf, sizeof(idbuf)));
}
}
if (pass)
{
- if ((untranslated * 10) >= cupsArrayCount(po))
+ int count = cupsArrayCount(po); /* Total number of messages */
+
+ if (untranslated >= (count / 10) && strcmp(argv[i], "cups.pot"))
{
/*
* Only allow 10% of messages to be untranslated before we fail...
pass = 0;
puts("FAIL");
- printf(" Too many untranslated messages (%d of %d)\n\n",
- untranslated, cupsArrayCount(po));
+ printf(" Too many untranslated messages (%d of %d or %.1f%% are translated)\n", count - untranslated, count, 100.0 - 100.0 * untranslated / count);
}
else if (untranslated > 0)
- printf("PASS (%d of %d untranslated)\n\n", untranslated,
- cupsArrayCount(po));
+ printf("PASS (%d of %d or %.1f%% are translated)\n", count - untranslated, count, 100.0 - 100.0 * untranslated / count);
else
- puts("PASS\n");
+ puts("PASS");
}
if (!pass)
}
if (*s)
- strcpy(bufptr, "...");
+ memcpy(bufptr, "...", 4);
else
*bufptr = '\0';
cupsArrayDelete(fmts);
}
-
-
-/*
- * End of "$Id: checkpo.c 7223 2008-01-16 23:41:19Z mike $".
- */