diff --git a/framework/org.tinygroup.i18n/src/main/java/org/tinygroup/i18n/impl/I18nMessageImpl.java b/framework/org.tinygroup.i18n/src/main/java/org/tinygroup/i18n/impl/I18nMessageImpl.java index bf20eb0e663829c1ee0554c7df77906f30b8e30a..0e7dc0f84803bb39413206340389d496a5fff173 100644 --- a/framework/org.tinygroup.i18n/src/main/java/org/tinygroup/i18n/impl/I18nMessageImpl.java +++ b/framework/org.tinygroup.i18n/src/main/java/org/tinygroup/i18n/impl/I18nMessageImpl.java @@ -23,6 +23,7 @@ import org.tinygroup.format.Formater; import org.tinygroup.i18n.I18nMessage; import org.tinygroup.i18n.I18nMessageFactory; +import java.text.MessageFormat; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -77,11 +78,17 @@ public class I18nMessageImpl implements I18nMessage { } public String getMessage(String code, Locale locale, Object... args) { - String message = I18nMessageFactory.getMessage(locale, code); - if (message == null) { + String pattern = I18nMessageFactory.getMessage(locale, code); + if (pattern == null) { return null; } - return format(message, args); + try { + //使用 java.text.MessageFormat 用以支持参数顺序及其他的强大功能。 + return MessageFormat.format(pattern, args); + } catch (IllegalArgumentException e) { + //之前型如 : This {} is {} sample. 不是java.text.MessageFormat合法规则,故使用旧方法处理。 + return format(pattern, args); + } } public String getMessage(String code) {