Use template functions of WCF.Language.get for WCF.Like
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 28 May 2013 11:17:26 +0000 (13:17 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 28 May 2013 11:33:48 +0000 (13:33 +0200)
See WoltLab/com.woltlab.wcf.like#21

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

index 592b994a3cde8972743e4b398f86fe507970ce77..1bfe8496fc035c6b1b5803c06c3caa835e7f200c 100644 (file)
@@ -392,7 +392,7 @@ WCF.Like = Class.extend({
                        // update tooltip
                        var $likes = this._containerData[containerID].likes;
                        var $dislikes = this._containerData[containerID].dislikes;
-                       $badge.data('tooltip', eval(WCF.Language.get('wcf.like.tooltip')));
+                       $badge.data('tooltip', WCF.Language.get('wcf.like.tooltip', { likes: $likes, dislikes: $dislikes }));
                }
        },
        
@@ -408,7 +408,7 @@ WCF.Like = Class.extend({
                        for (var $userID in $users) $userArray.push($users[$userID].username);
                        var $others = this._containerData[containerID].likes - $userArray.length;
                        
-                       this._containerData[containerID].summary.children('span').html(eval(WCF.Language.get('wcf.like.summary')));
+                       this._containerData[containerID].summary.children('span').html(WCF.Language.get('wcf.like.summary', { users: $userArray, others: $others }));
                }
        },
        
index f6883db3caf57a7fb0f101014523721c51bde80a..b331335c8f62fde60869bf1ddaa7e491c2c94fe8 100755 (executable)
@@ -3844,7 +3844,13 @@ WCF.Template = Class.extend({
                
                template = "$output += '" + template + "';";
                
-               this.fetch = new Function("v", "var $output = ''; " + template + ' return $output;');
+               try {
+                       this.fetch = new Function("v", "var $output = ''; " + template + ' return $output;');
+               }
+               catch (e) {
+                       console.debug("var $output = ''; " + template + ' return $output;');
+                       throw e;
+               }
        },
        
        /**
index 85ddb56562393de7bdce37a26bfec0d7ea376c10..7c0c923b632ca783f86d33eca3828183a5799606 100644 (file)
@@ -1608,11 +1608,11 @@ Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getAllowedExtensions()
        <category name="wcf.like">
                <item name="wcf.like.cumulativeLikes"><![CDATA[Likes]]></item>
                <item name="wcf.like.tooltip"><![CDATA[{if $likes}{#$likes} Like{if $likes != 1}s{/if}{if $dislikes}, {/if}{/if}{if $dislikes}{#$dislikes} Dislike{if $dislikes != 1}s{/if}{/if}]]></item>
-               <item name="wcf.like.jsTooltip"><![CDATA[($likes > 0 ? ($likes + " Like" + ($likes != 1 ? "s" : "") + ($dislikes > 0 ? ", " : "")) : "") + ($dislikes > 0 ? ($dislikes + " Dislike" + ($dislikes != 1 ? "s" : "")) : "")]]></item>
+               <item name="wcf.like.jsTooltip"><![CDATA[{literal}{if $likes}{#$likes} Like{if $likes != 1}s{/if}{if $dislikes}, {/if}{/if}{if $dislikes}{#$dislikes} Dislike{if $dislikes != 1}s{/if}{/if}{/literal}]]></item>
                <item name="wcf.like.button.like"><![CDATA[Gefällt mir]]></item>
                <item name="wcf.like.button.dislike"><![CDATA[Gefällt mir nicht]]></item>
                <item name="wcf.like.likesReceived"><![CDATA[Erhaltene Likes]]></item>
-               <item name="wcf.like.summary"><![CDATA[$userArray.join(", ") + ($others > 0 ? (" und " + $others + (" weitere" + ($others > 1 ? "n" : "m"))) : "") + " gefällt das."]]></item>
+               <item name="wcf.like.summary"><![CDATA[{literal}{if $others == 0}{@$users.slice(0, -1).join(", ")}{if $users.length > 1} und {/if}{@$users.slice(-1)[0]}{else}{@$users.join(", ")} und {if $others == 1}einem{else}{#$others}{/if} weitere{if $others > 1}n{else}m{/if}{/if} gefällt das.{/literal}]]></item>
                <item name="wcf.like.details"><![CDATA[Details]]></item>
                <item name="wcf.like.details.like"><![CDATA[Likes]]></item>
                <item name="wcf.like.details.dislike"><![CDATA[Dislikes]]></item>
index 582a607501f8df242215d2b5fe32b430699306bb..9b2b27e23aee3a6f1321fea178f1d5e9802d60ff 100644 (file)
@@ -1606,11 +1606,12 @@ Allowed extensions: {', '|implode:$attachmentHandler->getAllowedExtensions()}]]>
        <category name="wcf.like">
                <item name="wcf.like.cumulativeLikes"><![CDATA[Likes]]></item>
                <item name="wcf.like.tooltip"><![CDATA[{if $likes}{#$likes} Like{if $likes != 1}s{/if}{if $dislikes}, {/if}{/if}{if $dislikes}{#$dislikes} Dislike{if $dislikes != 1}s{/if}{/if}]]></item>
-               <item name="wcf.like.jsTooltip"><![CDATA[($likes > 0 ? ($likes + " Like" + ($likes != 1 ? "s" : "") + ($dislikes > 0 ? ", " : "")) : "") + ($dislikes > 0 ? ($dislikes + " Dislike" + ($dislikes != 1 ? "s" : "")) : "")]]></item>
+               <item name="wcf.like.jsTooltip"><![CDATA[{literal}{if $likes}{#$likes} Like{if $likes != 1}s{/if}{if $dislikes}, {/if}{/if}{if $dislikes}{#$dislikes} Dislike{if $dislikes != 1}s{/if}{/if}{/literal}]]></item>
                <item name="wcf.like.button.like"><![CDATA[Like]]></item>
                <item name="wcf.like.button.dislike"><![CDATA[Dislike]]></item>
                <item name="wcf.like.likesReceived"><![CDATA[Likes Received]]></item>
                <item name="wcf.like.summary"><![CDATA[$userArray.join(", ") + ($others > 0 ? (" and " + $others + (" other" + ($others > 1 ? "s" : ""))) : "") + " like" + ($userArray.length == 1 ? "s" : "") +  " this."]]></item>
+               <item name="wcf.like.summary"><![CDATA[{literal}{if $others == 0}{@$users.slice(0, -1).join(", ")}{if $users.length > 1} and {/if}{@$users.slice(-1)[0]}{else}{@$users.join(", ")} and {if $others == 1}one{else}{#$others}{/if} other{if $others > 1}s{/if}{/if} like{if $users.length == 1}s{/if} this.{/literal}]]></item>
                <item name="wcf.like.details"><![CDATA[Details]]></item>
                <item name="wcf.like.details.like"><![CDATA[Likes]]></item>
                <item name="wcf.like.details.dislike"><![CDATA[Dislikes]]></item>