fix Ox.formatString
This commit is contained in:
parent
dc0c504809
commit
e2be60c762
2 changed files with 5 additions and 5 deletions
|
@ -747,11 +747,11 @@ Ox.formatString <f> Basic string formatting
|
||||||
> Ox.formatString('{a\\.b}', {'a.b': 'foobar'})
|
> Ox.formatString('{a\\.b}', {'a.b': 'foobar'})
|
||||||
'foobar'
|
'foobar'
|
||||||
> Ox.formatString('{1}', ['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) {
|
return string.replace(/\{([^}]+)\}/g, function(string, match) {
|
||||||
// make sure to not split at escaped dots ('\.')
|
// make sure to not split at escaped dots ('\.')
|
||||||
var key,
|
var key,
|
||||||
|
@ -768,7 +768,7 @@ Ox.formatString = function(string, collection, removeUnmatched) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value || (removeUnmatched ? '' : '{' + match + '}');
|
return value !== null ? value : keepUnmatched ? '{' + match + '}' : '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
var translation = translations[value];
|
var translation = translations[value];
|
||||||
log && log(value, translation);
|
log && log(value, translation);
|
||||||
translation = translation || value;
|
translation = translation || value;
|
||||||
return Ox.formatString(translation, options, true);
|
return Ox.formatString(translation, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
Loading…
Reference in a new issue