views:

19

answers:

2

Is there a way to pass an array of String to a resource bundle to localize an unknown number of argument for a given key?

I have:

my.message=List of retired products: {0}

getValue(bundle, "my.message", list.toArray());

With this, only the first item in the array is showed in the resulting message.

A: 

I think you are going to need a for loop.

Tom Hawtin - tackline
A: 

No, there are no builtin facilities for that in the MessageFormat API. You need to build a string with the values yourself. E.g.:

StringBuilder products = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
    products.append(list.get(i));
    if (i + 2 < list.size()) products.append(", ");
    else if (i + 2 == list.size()) products.append(" and "); // Localize this?
}
getValue(bundle, "my.message", products);
BalusC