/** * The first "."-delimited piece of the id is the bundle base with the remainder being the * message key. */ @Override public String getMessage(String id, Locale locale, Object... args) { try { String[] pcs = id.split("\\.", 2); String message = pcs.length < 2 ? null : ResourceBundle.getBundle(pcs[0], locale).getString(pcs[1]); return message == null ? null : format(message, locale, args); } catch (Exception e) { return null; } }
@Test public void testBundle() { Localizer.registerMessageSource(new BundleMessageSource()); Locale locale1 = new Locale("en"); Locale locale2 = new Locale("fr"); assertEquals("keyboard", StrUtil.getLabel("message.test1", locale1)); assertEquals("clavier", StrUtil.getLabel("message.test1", locale2)); }