You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2006/12/21 23:12:59 UTC
svn commit: r489494 - in /incubator/xap/trunk: src/xap/util/MessageFormat.js
testsrc/xap/util/_TestMessageFormat.js
Author: jmargaris
Date: Thu Dec 21 15:12:58 2006
New Revision: 489494
URL: http://svn.apache.org/viewvc?view=rev&rev=489494
Log:
now message format will accept a single value instead of an array
and it will still work. I wonder if we also should support
variable number of string args like format, string1, string2, etc
Modified:
incubator/xap/trunk/src/xap/util/MessageFormat.js
incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js
Modified: incubator/xap/trunk/src/xap/util/MessageFormat.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/MessageFormat.js?view=diff&rev=489494&r1=489493&r2=489494
==============================================================================
--- incubator/xap/trunk/src/xap/util/MessageFormat.js (original)
+++ incubator/xap/trunk/src/xap/util/MessageFormat.js Thu Dec 21 15:12:58 2006
@@ -17,6 +17,7 @@
Xap.provide("xap.util.MessageFormat");
+Xap.require('dojo.lang');
@@ -38,11 +39,17 @@
* in arguments in that order. Currently there is no escape syntax at all. TODO
*
* @param {String} formatString The string message format.
- * @param {Array} args An array of arguments to plug into the message format.
+ * @param {String/Array} args An array of arguments to plug into the message format
+ * or a single argument
*/
xap.util.MessageFormat.format = function( formatString, args ){
if (!formatString){
return null;
+ }
+
+ //if not an array make it one
+ if (!dojo.lang.isArray(args)){
+ args = [args];
}
//IMPORTANT escaping syntax?? And if we replace something
Modified: incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js?view=diff&rev=489494&r1=489493&r2=489494
==============================================================================
--- incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js (original)
+++ incubator/xap/trunk/testsrc/xap/util/_TestMessageFormat.js Thu Dec 21 15:12:58 2006
@@ -43,4 +43,10 @@
returnValue = xap.util.MessageFormat.format(formatString, values);
assertTrue("Third message format failed",
returnValue=="Arg 1: ARG1 arg 2: ARG2 arg1: ARG1");
+
+ formatString = "Arg 1: {0} Arg1 again: {0}";
+ values = "ARG1"
+ returnValue = xap.util.MessageFormat.format(formatString, values);
+ assertTrue("Message format with no array",
+ returnValue=="Arg 1: ARG1 Arg1 again: ARG1");
}