Hi Jon,
I have/had the same problem. I just wrote a wrapper for the
Dictionary class. I'm surprised I couldn't find an easy way to do it.
You can try this code if you want, although I don't guarantee its
correctness or quality. It works like the dictionary class with the
addition of the get(<name>, <values+>) method:
package net.timp.gwtmaps.client;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.google.gwt.i18n.client.Dictionary;
public class PlaceholderDictionary {
private static Map<String, PlaceholderDictionary> cache =
new HashMap<String, PlaceholderDictionary>();
private Dictionary dictionary;
public static PlaceholderDictionary getDictionary(java.lang.String
name) {
PlaceholderDictionary target = cache.get(name);
if (target == null) {
target = new PlaceholderDictionary(name);
cache.put(name, target);
}
return target;
}
private PlaceholderDictionary(String name) {
dictionary = Dictionary.getDictionary(name);
}
public String get(String key) {
return dictionary.get(key);
}
public String get(String key, String ... values) {
String string = dictionary.get(key);
int i = 0;
for ( String value : values ) {
string = string.replace("{" + i + "}", value);
}
return string;
}
public Set<String> keySet() {
return dictionary.keySet();
}
public Collection<String> values() {
return dictionary.values();
}
@Override
public String toString() {
return dictionary.toString();
}
}
On Nov 13, 7:56 pm, Jon Vaughan <[email protected]> wrote:
> Hi all,
>
> Just a quick query - is it possible to do placeholder substitution
> with messages obtained from a Dictionary? i..e into something like:
>
> permissionDenied = Error {0}: User {1} Permission denied.
>
> I couldn't see anything obvious in the doc or forums; does a
> Dictionary link in any way to a Messages instance?
>
> Thanks
>
> Jon
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=.