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.
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);
I think you are going to need a for
loop.
精彩评论