Re: Translator with Localized texts

2012-11-13 Thread Lance Java
1. Pass ComponentMessagesSource and ThreadLocale to the YesNoTranslator
constructor

2.
public String toClient(Boolean flag) { 
Messages messages =
messagesSource.getApplicationCatalog(threadLocale.getLocale());
return (flag ? messages.get("boolean.true") :
messages.get("boolean.false"); 
}

3. Add entries for boolean.true and boolean.false for your languages to your
root application message catalogues



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Translator-with-Localized-texts-tp5717981p5717983.html
Sent from the Tapestry - Dev mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: dev-unsubscr...@tapestry.apache.org
For additional commands, e-mail: dev-h...@tapestry.apache.org



Translator with Localized texts

2012-11-13 Thread Oli
Hello,
I need to create a Boolean translator to display boolean field value as a
localized text (yes/oui/..., no/non/...)
I have added my translator into AppModile.java class.

/public static void contributeTranslatorSource(MappedConfiguration configuration) {
configuration.add(Boolean.class, new YesNoTranslator());
}/

I can use it with hard coded String, but how can I add localized message
into it ?

/public class YesNoTranslator extends AbstractTranslator {
public YesNoTranslator() {
super("yesno", Boolean.class, "yesno-format-exception");
}

public String toClient(Boolean value) {
return (value != true ? "no" : "yes");
}

public Boolean parseClient(Field field, String clientValue, String
message) throws ValidationException {
if (clientValue == null) {
return Boolean.FALSE;
} else {
String s = clientValue.toLowerCase();
if (s.equals("no")) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
}

public void render(Field field, String message, MarkupWriter writer,
FormSupport formSupport) {
}
}/

Thanks



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Translator-with-Localized-texts-tp5717981.html
Sent from the Tapestry - Dev mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: dev-unsubscr...@tapestry.apache.org
For additional commands, e-mail: dev-h...@tapestry.apache.org