diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2012-10-10 00:40:47 -0700 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2012-10-10 00:40:47 -0700 |
commit | a0c53619ff9da35cc02b0c09beba7ecd756a0d7e (patch) | |
tree | be9f2fc24bd9051c3b455ee55e237179034f7507 /core/js | |
parent | fce6ce9bc602a4aea0150f92eaf1a1446575ceaf (diff) | |
parent | bb345770af627e21cb71e4f8d00c8d8536e13989 (diff) | |
download | nextcloud-server-a0c53619ff9da35cc02b0c09beba7ecd756a0d7e.tar.gz nextcloud-server-a0c53619ff9da35cc02b0c09beba7ecd756a0d7e.zip |
Merge pull request #24 from owncloud/js_variable_interpolation
A suggestion for simple, yet efficient variable interpolation in js translations
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/js.js | 22 |
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={}; |