Craig Gidney
Craig Gidney

Reputation: 18296

Internationalizing a duration via gwt Messages

I want to include a timeout duration, like "25 seconds" or "1 minute", in a user-facing message. Is there a way to do this in gwt?

From this resource, I know that I can do dates like this:

@DefaultMessage("Last update: {0,date,medium} {0,time,medium}")
String lastUpdate(Date timestamp);

but there doesn't seem to be anything like:

// hypothetical
@DefaultMessage("Requests time out after {0,duration}")
String timeout(Interval duration); // also Interval is a JodaTime concept...

Is there?

Upvotes: 1

Views: 81

Answers (1)

Chris Lercher
Chris Lercher

Reputation: 37778

JodaTime still isn't really available for GWT (there are/were several projects, but unfortunately none ever really established itself). I hope someday we'll see JavaSE 8's new Date API in GWT!

Until then, I would use the following approach:

  • Storing the duration as a number of seconds (or milliseconds if required).
  • Creating one internationalized message for 0-59 seconds, one for 1-59 minutes, and one for 1-... hours.
  • Each of these messages can use Plural Forms.
  • Selecting the best message (seconds/minutes/hours) programmatically.

Upvotes: 1

Related Questions