+2003-12-26 Bruno Haible <bruno@clisp.org>
+
+ * write-java.c (write_java_code): Emit a static method
+ 'get_msgid_plural_table' instead of a static field 'plural'.
+ * gnu/gettext/DumpResource.java (DumpResource.dump): Exploit a
+ 'get_msgid_plural_table' method if it exists.
+
2003-12-14 Bruno Haible <bruno@clisp.org>
* message.h (format_type): New enum value 'format_csharp'.
/* GNU gettext for Java
- * Copyright (C) 2001 Free Software Foundation, Inc.
+ * Copyright (C) 2001-2003 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
}
private ResourceBundle catalog;
private Method lookupMethod;
- private Field pluralField;
// Lookup the value corresponding to a key found in catalog.getKeys().
// Here we assume that the catalog returns a non-inherited value for
// these keys. FIXME: Not true. Better see whether handleGetObject is
} catch (NoSuchMethodException e) {
} catch (SecurityException e) {
}
- pluralField = null;
+ Method pluralMethod = null;
+ try {
+ pluralMethod = catalog.getClass().getMethod("get_msgid_plural_table", new Class[0]);
+ } catch (NoSuchMethodException e) {
+ } catch (SecurityException e) {
+ }
+ Field pluralField = null;
try {
pluralField = catalog.getClass().getField("plural");
} catch (NoSuchFieldException e) {
{
Enumeration keys = catalog.getKeys();
Object plural = null;
- if (pluralField != null)
+ if (pluralMethod != null) {
+ // msgfmt versions > 0.13.1 create a static get_msgid_plural_table()
+ // method.
+ try {
+ plural = pluralMethod.invoke(catalog, new Object[0]);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.getTargetException().printStackTrace();
+ }
+ } else if (pluralField != null) {
+ // msgfmt versions <= 0.13.1 create a static plural field.
try {
plural = pluralField.get(catalog);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
+ }
if (plural instanceof String[]) {
// A GNU gettext created class with plural handling, Java2 format.
int i = 0;
if (plurals)
{
bool first;
- fprintf (stream, " public static final java.lang.String[] plural = new java.lang.String[] { ");
+ fprintf (stream, " public static final java.lang.String[] get_msgid_plural_table () {\n");
+ fprintf (stream, " return new java.lang.String[] { ");
first = true;
for (j = 0; j < mlp->nitems; j++)
{
}
}
fprintf (stream, " };\n");
+ fprintf (stream, " }\n");
}
if (plurals)
/* Emit the msgid_plural strings. Only used by msgunfmt. */
if (plurals)
{
- fprintf (stream, " public static final java.util.Hashtable plural;\n");
- fprintf (stream, " static {\n");
+ fprintf (stream, " public static final java.util.Hashtable get_msgid_plural_table () {\n");
fprintf (stream, " java.util.Hashtable p = new java.util.Hashtable();\n");
for (j = 0; j < mlp->nitems; j++)
if (mlp->item[j]->msgid_plural != NULL)
write_java_string (stream, mlp->item[j]->msgid_plural);
fprintf (stream, ");\n");
}
- fprintf (stream, " plural = p;\n");
+ fprintf (stream, " return p;\n");
fprintf (stream, " }\n");
}