Ejemplo n.º 1
0
function extraire_multi($letexte, $lang = null, $echappe_span = false)
{
    if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
        if (!$lang) {
            $lang = $GLOBALS['spip_lang'];
        }
        foreach ($regs as $reg) {
            // chercher la version de la langue courante
            $trads = extraire_trads($reg[1]);
            if ($l = approcher_langue($trads, $lang)) {
                $trad = $trads[$l];
            } else {
                include_spip('inc/texte');
                // langue absente, prendre la premiere dispo
                // mais typographier le texte selon les regles de celle-ci
                // Attention aux blocs multi sur plusieurs lignes
                $l = key($trads);
                $trad = $trads[$l];
                $typographie = charger_fonction(lang_typo($l), 'typographie');
                $trad = $typographie($trad);
                include_spip('inc/texte');
                // Tester si on echappe en span ou en div
                // il ne faut pas echapper en div si propre produit un seul paragraphe
                $trad_propre = preg_replace(",(^<p[^>]*>|</p>\$),Uims", "", propre($trad));
                $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
                $trad = code_echappement($trad, 'multi', false, $mode);
                $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
                if (lang_dir($l) !== lang_dir($lang)) {
                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
                }
                if (!$echappe_span) {
                    $trad = echappe_retour($trad, 'multi');
                }
            }
            $letexte = str_replace($reg[0], $trad, $letexte);
        }
    }
    return $letexte;
}
Ejemplo n.º 2
0
Archivo: lang.php Proyecto: JLuc/SPIP
function choisir_traduction($trads, $lang = '')
{
    $k = approcher_langue($trads, $lang);
    return $k ? $trads[$k] : array_shift($trads);
}
Ejemplo n.º 3
0
function extraire_multi($letexte, $lang=null, $echappe_span=false) {
	if (strpos($letexte, '<multi>') === false) return $letexte; // perf
	if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
		if (!$lang) $lang = $GLOBALS['spip_lang'];

		foreach ($regs as $reg) {
			// chercher la version de la langue courante
			$trads = extraire_trads($reg[1]);
			if ($l = approcher_langue($trads, $lang)) {
				$trad = $trads[$l];
			} else {
				include_spip('inc/texte');
				// langue absente, prendre la premiere dispo
				// mais typographier le texte selon les regles de celle-ci
				// Attention aux blocs multi sur plusieurs lignes
				$l = key($trads);
				$trad = $trads[$l];
				$typographie = charger_fonction(lang_typo($l), 'typographie');
				$trad = traiter_retours_chariots($typographie($trad));
				$trad = explode("\n", $trad);
				foreach($trad as $i => $ligne) {
					if (strlen($ligne)) {
						$ligne = code_echappement($ligne, 'multi');
						$ligne = str_replace("'", '"', inserer_attribut($ligne, 'lang', $l));
						if (lang_dir($l) !== lang_dir($lang))
							$ligne = str_replace("'", '"', inserer_attribut($ligne, 'dir', lang_dir($l)));
						$trad[$i] = $ligne;
					}
				}
				$trad = join("\n", $trad);
				if (!$echappe_span)
					$trad = echappe_retour($trad, 'multi');
			}
			$letexte = str_replace($reg[0], $trad, $letexte);
		}
	}

	return $letexte;
}
/**
 * Extrait une langue d'un texte <multi>[fr] xxx [en] yyy</multi>
 *
 * @param string $quoi le texte contenant ou non un multi
 * @param string $lang la langue a extraire
 * @return string, l'extrait trouve.
 **/
function _sqlite_func_extraire_multi($quoi, $lang)
{
    if (!defined('_EXTRAIRE_MULTI')) {
        include_spip('inc/filtres');
    }
    if (!function_exists('approcher_langue')) {
        include_spip('inc/lang');
    }
    if (preg_match_all(_EXTRAIRE_MULTI, $quoi, $regs, PREG_SET_ORDER)) {
        foreach ($regs as $reg) {
            // chercher la version de la langue courante
            $trads = extraire_trads($reg[1]);
            if ($l = approcher_langue($trads, $lang)) {
                $trad = $trads[$l];
            } else {
                $trad = reset($trads);
            }
            $quoi = str_replace($reg[0], $trad, $quoi);
        }
    }
    return $quoi;
}
Ejemplo n.º 5
0
function extraire_multi($letexte, $lang = null, $options = array())
{
    if ($letexte and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
        if (!$lang) {
            $lang = $GLOBALS['spip_lang'];
        }
        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
        if (is_bool($options)) {
            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
        }
        if (!isset($options['echappe_span'])) {
            $options = array_merge($options, array('echappe_span' => false));
        }
        if (!isset($options['lang_defaut'])) {
            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
        }
        include_spip('inc/lang');
        foreach ($regs as $reg) {
            // chercher la version de la langue courante
            $trads = extraire_trads($reg[1]);
            if ($l = approcher_langue($trads, $lang)) {
                $trad = $trads[$l];
            } else {
                if ($options['lang_defaut'] == 'aucune') {
                    $trad = '';
                } else {
                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
                    // ou la premiere dispo
                    // mais typographier le texte selon les regles de celle-ci
                    // Attention aux blocs multi sur plusieurs lignes
                    if (!($l = approcher_langue($trads, $options['lang_defaut']))) {
                        $l = key($trads);
                    }
                    $trad = $trads[$l];
                    $typographie = charger_fonction(lang_typo($l), 'typographie');
                    $trad = $typographie($trad);
                    // Tester si on echappe en span ou en div
                    // il ne faut pas echapper en div si propre produit un seul paragraphe
                    include_spip('inc/texte');
                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>\$),Uims", "", propre($trad));
                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
                    $trad = code_echappement($trad, 'multi', false, $mode);
                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
                    if (lang_dir($l) !== lang_dir($lang)) {
                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
                    }
                    if (!$options['echappe_span']) {
                        $trad = echappe_retour($trad, 'multi');
                    }
                }
            }
            $letexte = str_replace($reg[0], $trad, $letexte);
        }
    }
    return $letexte;
}