From 88d6ce6efd80e5ef454fc6ecb21673749d23281f Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Tue, 1 Nov 2011 11:43:02 +0000
Subject: [PATCH] =?UTF-8?q?La=20fonction=20=5FT()=20accepte=20un=203=C3=A8?=
 =?UTF-8?q?me=20argument=20$options=20array=20qui=20permet=20de=20passer?=
 =?UTF-8?q?=20des=20options=20:=20string=20class=20:=20pour=20le=20nom=20d?=
 =?UTF-8?q?'une=20classe=20a=20poser=20sur=20un=20span=20encapsulant=20(vi?=
 =?UTF-8?q?de=20par=20defaut)=20bool=20force=20:=20pour=20forcer=20le=20re?=
 =?UTF-8?q?tour=20d'une=20chaine=20m=C3=AAme=20si=20pas=20de=20trad=20exis?=
 =?UTF-8?q?tante=20(true=20par=20defaut)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/inc/utils.php | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index 0cff926345..3c7e14b242 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -450,13 +450,26 @@ function test_plugin_actif($plugin){
 	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
 }
 
-//
-// Traduction des textes de SPIP
-//
-// http://doc.spip.org/@_T
-function _T($texte, $args=array(), $class='') {
-
+/**
+ * Traduction des textes de SPIP
+ * http://doc.spip.org/@_T
+ *
+ * @param string $texte
+ * @param array $args
+ * @param array $options
+ *   string class : nom d'une classe a ajouter sur un span pour encapsuler la chaine
+ *   bool force : forcer un retour meme si la chaine n'a pas de traduction
+ * @return mixed|string
+ */
+function _T($texte, $args=array(), $options=array()) {
 	static $traduire=false ;
+	$o = array('class'=>'','force'=>true);
+	if ($options){
+		// support de l'ancien argument $class
+		if (is_string($options))
+			$options = array('class'=>$options);
+		$o = array_merge($o,$options);
+	}
 
  	if (!$traduire) {
 		$traduire = charger_fonction('traduire', 'inc');
@@ -477,6 +490,9 @@ function _T($texte, $args=array(), $class='') {
 	$text = $traduire($texte, $lang);
 
 	if (!strlen($text)){
+		if (!$o['force'])
+			return '';
+
 		$text = $texte;
 		// pour les chaines non traduites, assurer un service minimum
 		if (!isset($GLOBALS['test_i18n']))
@@ -486,7 +502,7 @@ function _T($texte, $args=array(), $class='') {
 		$class=null;
 	}
 
-	return _L($text, $args, $class);
+	return _L($text, $args, $o['class']);
 
 }
 
-- 
GitLab