Created
June 13, 2012 14:31
-
-
Save oehme/2924422 to your computer and use it in GitHub Desktop.
Freemarker I18n the hard way - Java side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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