summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-10-05 03:33:46 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-10-05 03:33:46 +0200
commitbb345770af627e21cb71e4f8d00c8d8536e13989 (patch)
tree0f5ea41c5cc74a3cd679796c9215bf4e16aa3619 /core
parent4fd53eca06e12b053f4760f2b776eab0e0e36ce9 (diff)
downloadnextcloud-server-bb345770af627e21cb71e4f8d00c8d8536e13989.tar.gz
nextcloud-server-bb345770af627e21cb71e4f8d00c8d8536e13989.zip
Suggestion for simple, yet efficient variable interpolation in js translations.
Diffstat (limited to 'core')
-rw-r--r--core/js/js.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 657dd6d6f8a..d87047dbc6b 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -5,7 +5,7 @@
* @return string
*/
-function t(app,text){
+function t(app,text, vars){
if( !( t.cache[app] )){
$.ajax(OC.filePath('core','ajax','translations.php'),{
async:false,//todo a proper sollution for this without sync ajax calls
@@ -21,11 +21,27 @@ function t(app,text){
t.cache[app] = [];
}
}
+ var _build = function(text, vars) {
+ return text.replace(/{([^{}]*)}/g,
+ function (a, b) {
+ var r = vars[b];
+ return typeof r === 'string' || typeof r === 'number' ? r : a;
+ }
+ );
+ }
if( typeof( t.cache[app][text] ) !== 'undefined' ){
- return t.cache[app][text];
+ if(typeof vars === 'object') {
+ return _build(t.cache[app][text], vars);
+ } else {
+ return t.cache[app][text];
+ }
}
else{
- return text;
+ if(typeof vars === 'object') {
+ return _build(text, vars);
+ } else {
+ return text;
+ }
}
}
t.cache={};