* Translate: Add GNU ngettext (plurals) support

This commit is contained in:
zzz
2010-05-27 00:38:32 +00:00
parent 9132e94143
commit dc3378d084
14 changed files with 377 additions and 39 deletions

View File

@ -8,11 +8,11 @@ import net.i2p.data.Destination;
import net.i2p.router.TunnelPoolSettings;
public class ConfigTunnelsHelper extends HelperBase {
static final String HOP = _x("hop");
static final String TUNNEL = _x("tunnel");
private static final String HOP = "hop";
private static final String TUNNEL = "tunnel";
/** dummies for translation */
static final String HOPS = _x("hops");
static final String TUNNELS = _x("tunnels");
private static final String HOPS = ngettext("1 hop", "{0} hops");
private static final String TUNNELS = ngettext("1 tunnel", "{0} tunnels");
public ConfigTunnelsHelper() {}
@ -196,14 +196,13 @@ public class ConfigTunnelsHelper extends HelperBase {
buf.append("<option value=\"").append(i).append("\" ");
if (i == now)
buf.append("selected=\"true\" ");
String pname;
// pluralize and then translate
if (i != 1 && i != -1)
pname = name + 's';
else
pname = name;
buf.append(">").append(prefix).append(i).append(' ').append(_(pname));
buf.append(">").append(_(i, "1 " + name, "{0} " + name + 's'));
buf.append("</option>\n");
}
}
/** dummy for tagging */
private static String ngettext(String s, String p) {
return null;
}
}

View File

@ -51,6 +51,11 @@ public abstract class HelperBase {
return Messages.getString(s, o, _context);
}
/** translate (ngettext) @since 0.7.14 */
public String _(int n, String s, String p) {
return Messages.getString(n, s, p, _context);
}
/**
* Mark a string for extraction by xgettext and translation.
* Use this only in static initializers.

View File

@ -29,4 +29,9 @@ public class Messages extends Translate {
public static String getString(String s, Object o, I2PAppContext ctx) {
return Translate.getString(s, o, ctx, BUNDLE_NAME);
}
/** translate (ngettext) @since 0.7.14 */
public static String getString(int n, String s, String p, I2PAppContext ctx) {
return Translate.getString(n, s, p, ctx, BUNDLE_NAME);
}
}