Use WCF.Template for WCF.Language
authorTim Düsterhus <timwolla@arcor.de>
Sat, 21 Jan 2012 22:10:05 +0000 (23:10 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Sat, 21 Jan 2012 22:10:05 +0000 (23:10 +0100)
WCF.Language.add('language.item', '{$var}');
WCF.Language.get('language.item'); // {$var}
WCF.Language.get('language.item', { var: test }); // test

wcfsetup/install/files/js/WCF.js

index 524f9d4426f67e1976b540cdcf1ae649599f7df3..35be4130584c3b01f531bfdcde03a16dd2e31f9b 100644 (file)
@@ -1672,8 +1672,23 @@ WCF.Language = {
         * @param       string          key
         * @return      mixed
         */
-       get: function(key) {
-               return this._variables.get(key);
+       get: function(key, parameters) {
+               // initialize parameters with an empty object
+               if (typeof parameters === 'undefined') var parameters = {};
+               
+               var value = this._variables.get(key);
+               
+               if (typeof value === 'string') {
+                       // transform strings into template and try to refetch
+                       this.add(key, new WCF.Template(value));
+                       return this.get(key, parameters);
+               }
+               else if (value !== null && typeof value === 'object' && typeof value.fetch !== 'undefined') {
+                       // evaluate templates
+                       value = value.fetch(parameters);
+               }
+               
+               return value;
        }
 };