From e2be60c7628dd1d9e9cbca6839cc6405c18c216e Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Mon, 22 Jul 2013 17:49:50 +0000 Subject: [PATCH] fix Ox.formatString --- source/Ox/js/Format.js | 8 ++++---- source/Ox/js/Locale.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 31646ed2..5c3e8ad7 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -747,11 +747,11 @@ Ox.formatString Basic string formatting > Ox.formatString('{a\\.b}', {'a.b': 'foobar'}) 'foobar' > Ox.formatString('{1}', ['foobar']) - '{1}' - > Ox.formatString('{b}', {a: 'foobar'}, true) '' + > Ox.formatString('{b}', {a: 'foobar'}, true) + '{b}' @*/ -Ox.formatString = function(string, collection, removeUnmatched) { +Ox.formatString = function(string, collection, keepUnmatched) { return string.replace(/\{([^}]+)\}/g, function(string, match) { // make sure to not split at escaped dots ('\.') var key, @@ -768,7 +768,7 @@ Ox.formatString = function(string, collection, removeUnmatched) { break; } } - return value || (removeUnmatched ? '' : '{' + match + '}'); + return value !== null ? value : keepUnmatched ? '{' + match + '}' : ''; }); }; diff --git a/source/Ox/js/Locale.js b/source/Ox/js/Locale.js index 4445de5f..df0de2ac 100644 --- a/source/Ox/js/Locale.js +++ b/source/Ox/js/Locale.js @@ -69,7 +69,7 @@ var translation = translations[value]; log && log(value, translation); translation = translation || value; - return Ox.formatString(translation, options, true); + return Ox.formatString(translation, options); }; /*@