@RequestScoped
@Named("msg")
public class Messages {
@Inject
private MvcContext mvcContext;
public final String get(final String key) {
LOGGER.info(String.format("Getting message '%s' for locale '%s'", key,
mvcContext.getLocale()));
final var bundle = ResourceBundle.getBundle("messages", mvcContext.getLocale());
return bundle.containsKey(key) ? bundle.getString(key) : formatUnknownKey(key);
}
private static String formatUnknownKey(final String key) {
return String.format("???%s???", key);
}
}