From dfce17eafe1070ebf24907955f2a056f418583cd Mon Sep 17 00:00:00 2001 From: chaowangbang Date: Tue, 21 Feb 2017 00:59:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20java.text.MessageFormat=20?= =?UTF-8?q?=E7=94=A8=E4=BB=A5=E6=94=AF=E6=8C=81=E5=8F=82=E6=95=B0=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E5=8F=8A=E5=85=B6=E4=BB=96=E7=9A=84=E5=BC=BA=E5=A4=A7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/tinygroup/i18n/impl/I18nMessageImpl.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 bf20eb0e6..0e7dc0f84 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) { -- Gitee