From: <dcr...@hy...> - 2010-03-17 23:07:28
|
Author: dcrutchf Date: 2010-03-17 16:07:21 -0700 (Wed, 17 Mar 2010) New Revision: 14393 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14393 Modified: trunk/src/org/hyperic/hq/hqu/rendit/i18n/BundleMapFacade.groovy Log: Added a method for parameterized i18n strings Modified: trunk/src/org/hyperic/hq/hqu/rendit/i18n/BundleMapFacade.groovy =================================================================== --- trunk/src/org/hyperic/hq/hqu/rendit/i18n/BundleMapFacade.groovy 2010-03-17 19:46:48 UTC (rev 14392) +++ trunk/src/org/hyperic/hq/hqu/rendit/i18n/BundleMapFacade.groovy 2010-03-17 23:07:21 UTC (rev 14393) @@ -1,5 +1,7 @@ package org.hyperic.hq.hqu.rendit.i18n +import java.text.MessageFormat; + /** * This class wraps a resource bundle and implements methods which make it * usable with the subscript operator (getAt) and also as object @@ -7,14 +9,18 @@ */ class BundleMapFacade { private ResourceBundle bundle - + private MessageFormat formatter + BundleMapFacade(bundle) { this.bundle = bundle + this.formatter = new MessageFormat(""); + + this.formatter.setLocale(bundle.locale); } def getAt(String o) { try { - return bundle.getString(o) + return this.bundle.getString(o) } catch(MissingResourceException e) { return "MISSING i18n KEY: ${o.toString()}" } @@ -23,4 +29,14 @@ def getProperty(String propName) { getAt(propName) } -} + + def getFormattedMessage(String key, Object... arguments) { + try { + this.formatter.applyPattern(this.bundle.getString(key)); + + return this.formatter.format(arguments); + } catch(MissingResourceException e) { + return "MISSING i18n KEY: ${o.toString()}" + } + } +} \ No newline at end of file |