Index: inc/public/class.dc.template.php
===================================================================
--- inc/public/class.dc.template.php	(revision 2610)
+++ inc/public/class.dc.template.php	(revision 2646)
@@ -385,4 +385,33 @@
 	}
 
+	public function displayCounter($variable,$values,$attr,$count_only_by_default=false) {
+		if (isset($attr['count_only'])) {
+			$count_only=($attr['count_only']==1);
+		} else {
+			$count_only = $count_only_by_default;
+		}
+		if ($count_only) {
+			return "<?php echo ".$variable."; ?>";
+		} else {
+			$v=$values;
+			if (isset($attr['none'])) {
+				$v['none'] = addslashes($attr['none']);
+			}
+			if (isset($attr['one'])) {
+				$v['one'] = addslashes($attr['one']);
+			}
+			if (isset($attr['more'])) {
+				$v['more'] = addslashes($attr['more']);
+			}
+			return
+				"<?php if (".$variable." == 0) {\n".
+				"  printf(__('".$v['none']."'),".$variable.");\n".
+				"} elseif (".$variable." == 1) {\n".
+				"  printf(__('".$v['one']."'),".$variable.");\n".
+				"} else {\n".
+				"  printf(__('".$v['more']."'),".$variable.");\n".
+				"} ?>";
+		}
+	}
 	/* TEMPLATE FUNCTIONS
 	------------------------------------------------------- */
@@ -545,5 +574,14 @@
 	{
 		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$_ctx->archives->nb_post').'; ?>';
+		return $this->displayCounter(
+			sprintf($f,'$_ctx->archives->nb_post'),
+			array(
+				'none' => 'no archive',
+				'one'  => 'one archive',
+				'more' => '%d archives'
+			),
+			$attr,
+			true
+		);
 	}
 
@@ -1021,5 +1059,14 @@
 	{
 		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$_ctx->categories->nb_post').'; ?>';
+		return $this->displayCounter(
+			sprintf($f,'$_ctx->categories->nb_post'),
+			array(
+				'none' => 'No post',
+				'one'  => 'One post',
+				'more' => '%d posts'
+			),
+			$attr,
+			true
+		);
 	}
 
@@ -1720,4 +1767,7 @@
 	}
 
+
+
+
 	/*dtd
 	<!ELEMENT tpl:EntryCommentCount - O -- Number of comments for entry -->
@@ -1731,18 +1781,4 @@
 	public function EntryCommentCount($attr)
 	{
-		$none = 'no comment';
-		$one = 'one comment';
-		$more = '%d comments';
-
-		if (isset($attr['none'])) {
-			$none = addslashes($attr['none']);
-		}
-		if (isset($attr['one'])) {
-			$one = addslashes($attr['one']);
-		}
-		if (isset($attr['more'])) {
-			$more = addslashes($attr['more']);
-		}
-
 		if (empty($attr['count_all'])) {
 			$operation = '$_ctx->posts->nb_comment';
@@ -1751,12 +1787,14 @@
 		}
 
-		return
-		"<?php if (".$operation." == 0) {\n".
-		"  printf(__('".$none."'),".$operation.");\n".
-		"} elseif (".$operation." == 1) {\n".
-		"  printf(__('".$one."'),".$operation.");\n".
-		"} else {\n".
-		"  printf(__('".$more."'),".$operation.");\n".
-		"} ?>";
+		return $this->displayCounter(
+			$operation,
+			array(
+				'none' => 'no comment',
+				'one'  => 'one comment',
+				'more' => '%d comments'
+				),
+			$attr,
+			false
+		);
 	}
 
@@ -1771,26 +1809,14 @@
 	public function EntryPingCount($attr)
 	{
-		$none = 'no trackback';
-		$one = 'one trackback';
-		$more = '%d trackbacks';
-
-		if (isset($attr['none'])) {
-			$none = addslashes($attr['none']);
-		}
-		if (isset($attr['one'])) {
-			$one = addslashes($attr['one']);
-		}
-		if (isset($attr['more'])) {
-			$more = addslashes($attr['more']);
-		}
-
-		return
-		"<?php if (\$_ctx->posts->nb_trackback == 0) {\n".
-		"  printf(__('".$none."'),(integer) \$_ctx->posts->nb_trackback);\n".
-		"} elseif (\$_ctx->posts->nb_trackback == 1) {\n".
-		"  printf(__('".$one."'),(integer) \$_ctx->posts->nb_trackback);\n".
-		"} else {\n".
-		"  printf(__('".$more."'),(integer) \$_ctx->posts->nb_trackback);\n".
-		"} ?>";
+		return $this->displayCounter(
+			'$_ctx->posts->nb_trackback',
+			array(
+				'none' => 'no trackback',
+				'one'  => 'one trackback',
+				'more' => '%d trackbacks'
+				),
+			$attr,
+			false
+		);
 	}
 
Index: plugins/attachments/_public.php
===================================================================
--- plugins/attachments/_public.php	(revision 2566)
+++ plugins/attachments/_public.php	(revision 2646)
@@ -211,26 +211,15 @@
 	public static function EntryAttachmentCount($attr)
 	{
-		$none = 'no attachment';
-		$one = 'one attachment';
-		$more = '%d attachments';
-
-		if (isset($attr['none'])) {
-			$none = addslashes($attr['none']);
-		}
-		if (isset($attr['one'])) {
-			$one = addslashes($attr['one']);
-		}
-		if (isset($attr['more'])) {
-			$more = addslashes($attr['more']);
-		}
-
-		return
-		"<?php if (\$_ctx->posts->countMedia() == 0) {\n".
-		"  printf(__('".$none."'),(integer) \$_ctx->posts->countMedia());\n".
-		"} elseif (\$_ctx->posts->countMedia() == 1) {\n".
-		"  printf(__('".$one."'),(integer) \$_ctx->posts->countMedia());\n".
-		"} else {\n".
-		"  printf(__('".$more."'),(integer) \$_ctx->posts->countMedia());\n".
-		"} ?>";
+		global $core;
+		return $core->tpl->displayCounter(
+			'$_ctx->posts->countMedia()',
+			array(
+				'none' => 'no attachment',
+				'one'  => 'one attachment',
+				'more' => '%d attachments'
+			),
+			$attr,
+			false
+		);
 	}
 }
