Skip to content

Instantly share code, notes, and snippets.

@oehme
Created June 13, 2012 14:31
Show Gist options
  • Save oehme/2924422 to your computer and use it in GitHub Desktop.
Save oehme/2924422 to your computer and use it in GitHub Desktop.
Freemarker I18n the hard way - Java side
public static Map<String, Object> getDataModel() {
HashMap<String, Object> datamodel = new HashMap<>();
datamodel.put("date", new Date());
datamodel.put("time", new Date());
datamodel.put("month", new Date());
datamodel.put("boolean", true);
datamodel.put("yes", getBundle().getString("yes"));
datamodel.put("no", getBundle().getString("no"));
datamodel.put("greeting", format(getBundle().getString("hello"), "Freemarker"));
return datamodel;
}
public static ResourceBundle getBundle() {
return ResourceBundle.getBundle(
"de.oehme.examples.freemarkerI18n.hardway.messages",
getLocale());
}
public static String format(String message, Object... args) {
MessageFormat format = new MessageFormat(message, getLocale());
return format.format(args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment