Use template functions of WCF.Language.get for WCF.Date
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 28 May 2013 11:33:59 +0000 (13:33 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 28 May 2013 11:33:59 +0000 (13:33 +0200)
As eval is no longer used the scope can be minified more efficiently

wcfsetup/install/files/js/WCF.js
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index b331335c8f62fde60869bf1ddaa7e491c2c94fe8..fa901681606ff2e870b9a23fb906d9b8c61c3ef7 100755 (executable)
@@ -2805,23 +2805,23 @@ WCF.Date.Time = Class.extend({
                // timestamp is less than 60 minutes ago (display 1 hour ago rather than 60 minutes ago)
                else if (this._timestamp < ($timestamp + 3540)) {
                        var $minutes = Math.max(Math.round((this._timestamp - $timestamp) / 60), 1);
-                       $element.text(eval(WCF.Language.get('wcf.date.relative.minutes')));
+                       $element.text(WCF.Language.get('wcf.date.relative.minutes', { minutes: $minutes }));
                }
                // timestamp is less than 24 hours ago
                else if (this._timestamp < ($timestamp + 86400)) {
                        var $hours = Math.round((this._timestamp - $timestamp) / 3600);
-                       $element.text(eval(WCF.Language.get('wcf.date.relative.hours')));
+                       $element.text(WCF.Language.get('wcf.date.relative.hours', { hours: $hours }));
                }
                // timestamp is less than a week ago
                else if (this._timestamp < ($timestamp + 604800)) {
                        var $days = Math.round((this._timestamp - $timestamp) / 86400);
-                       var $string = eval(WCF.Language.get('wcf.date.relative.pastDays'));
                        
                        // get day of week
                        var $dateObj = WCF.Date.Util.getTimezoneDate(($timestamp * 1000), $offset);
                        var $dow = $dateObj.getDay();
+                       var $day = WCF.Language.get('__days')[$dow];
                        
-                       $element.text($string.replace(/\%day\%/, WCF.Language.get('__days')[$dow]).replace(/\%time\%/, $time));
+                       $element.text(WCF.Language.get('wcf.date.relative.pastDays', { days: $days, day: $day, time: $time }));
                }
                // timestamp is between ~700 million years BC and last week
                else {
index 7c0c923b632ca783f86d33eca3828183a5799606..cf8e2cb78db217c78ead965ba5aaaa2dd4d96b57 100644 (file)
@@ -1366,9 +1366,9 @@ Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getAllowedExtensions()
                
                <!-- variables for dynamic javascript datetime -->
                <item name="wcf.date.relative.now"><![CDATA[Vor einem Moment]]></item>
-               <item name="wcf.date.relative.minutes"><![CDATA['Vor ' + (($minutes > 1) ? $minutes + ' Minuten' : 'einer Minute' )]]></item>
-               <item name="wcf.date.relative.hours"><![CDATA['Vor ' + (($hours > 1) ? $hours + ' Stunden' : 'einer Stunde' )]]></item>
-               <item name="wcf.date.relative.pastDays"><![CDATA[(($days > 1) ? '%day%' : 'Gestern' ) + ', %time%']]></item>
+               <item name="wcf.date.relative.minutes"><![CDATA[{literal}Vor {if $minutes > 1}{#$minutes} Minuten{else}einer Minute{/if}{/literal}]]></item>
+               <item name="wcf.date.relative.hours"><![CDATA[{literal}Vor {if $hours > 1}{#$minutes} Stunden{else}einer Stunde{/if}{/literal}]]></item>
+               <item name="wcf.date.relative.pastDays"><![CDATA[{literal}{if $days > 1}{$day}{else}Gestern{/if}, {$time}{/literal}]]></item>
                
                <!-- variables for localized date formats -->
                <item name="wcf.date.hour"><![CDATA[Stunde]]></item>
index 9b2b27e23aee3a6f1321fea178f1d5e9802d60ff..63f01361f1394a44c42e343e5729d6fb51d57ff2 100644 (file)
@@ -1364,9 +1364,9 @@ Allowed extensions: {', '|implode:$attachmentHandler->getAllowedExtensions()}]]>
                
                <!-- variables for dynamic javascript datetime -->
                <item name="wcf.date.relative.now"><![CDATA[A moment ago]]></item>
-               <item name="wcf.date.relative.minutes"><![CDATA[(($minutes > 1) ? $minutes + ' minutes' : 'A minute') + ' ago']]></item>
-               <item name="wcf.date.relative.hours"><![CDATA[(($hours > 1) ? $hours + ' hours' : 'An hour' ) + ' ago']]></item>
-               <item name="wcf.date.relative.pastDays"><![CDATA[(($days > 1) ? '%day%' : 'Yesterday' ) + ', %time%']]></item>
+               <item name="wcf.date.relative.minutes"><![CDATA[{literal}{if $minutes > 1}{#$minutes} minutes{else}A minute{/if} ago{/literal}]]></item>
+               <item name="wcf.date.relative.hours"><![CDATA[{literal}{if $hours > 1}{#$hours} hours{else}An hour{/if} ago{/literal}]]></item>
+               <item name="wcf.date.relative.pastDays"><![CDATA[{literal}{if $days > 1}{$day}{else}Yesterday{/if}, {$time}{/literal}]]></item>
                
                <!-- variables for localized date formats -->
                <item name="wcf.date.hour"><![CDATA[Hour]]></item>