Re: GWT i18n - Dictionary message placeholders

2009-11-15 Thread TimP
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 MapString, PlaceholderDictionary cache =
new HashMapString, 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 SetString keySet() {
return dictionary.keySet();
}

public CollectionString values() {
return dictionary.values();
}

@Override
public String toString() {
return dictionary.toString();
}
}



On Nov 13, 7:56 pm, Jon Vaughan jsvaug...@gmail.com 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 google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=.




Re: GWT i18n - Dictionary message placeholders

2009-11-14 Thread rjcarr
I'm not entirely sure what you're asking.

A dictionary is obtained by parsing javascript objects (i.e.,
dictionary types).  In your javascript you can parameterize your
dictionaries all you want (as far as I know).  As far as something
more elaborate once the dictionary is built, I can't say I've seen
such a thing.

On Nov 13, 10:56 am, Jon Vaughan jsvaug...@gmail.com 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 google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=.




GWT i18n - Dictionary message placeholders

2009-11-13 Thread Jon Vaughan
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 google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=.