3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
16 // Charger un fichier langue
18 // http://doc.spip.org/@chercher_module_lang
19 function chercher_module_lang($module, $lang = '') {
23 // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
24 if ($f = find_in_path($module.$lang.'.php', 'lang/'))
27 // 2) directement dans le chemin (old style, uniquement pour local)
28 return ($module == 'local')
29 ?
find_in_path('local'.$lang. '.php')
33 // http://doc.spip.org/@charger_langue
34 function charger_langue($lang, $module = 'spip') {
35 if ($lang AND $fichier_lang = chercher_module_lang($module, $lang)) {
36 $GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;
37 include($fichier_lang);
39 // si le fichier de langue du module n'existe pas, on se rabat sur
40 // la langue par defaut du site -- et au pire sur le francais, qui
41 // *par definition* doit exister, et on copie le tableau dans la
42 // var liee a la langue
43 $l = $GLOBALS['meta']['langue_site'];
44 if (!$fichier_lang = chercher_module_lang($module, $l))
45 $fichier_lang = chercher_module_lang($module, 'fr');
48 $GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;
49 include($fichier_lang);
50 $GLOBALS['i18n_'.$module.'_'.$lang]
51 = &$GLOBALS['i18n_'.$module.'_'.$l];
52 #spip_log("module de langue : ${module}_$l.php");
58 // Surcharger le fichier de langue courant avec un autre (tordu, hein...)
60 // http://doc.spip.org/@surcharger_langue
61 function surcharger_langue($fichier) {
62 static $surcharges = array();
63 if (!isset($GLOBALS['idx_lang'])) return;
64 if (!isset($surcharges[$fichier])) {
65 $idx_lang_normal = $GLOBALS['idx_lang'];
66 $GLOBALS['idx_lang'] = $GLOBALS['idx_lang'].'@temporaire';
68 $surcharges[$fichier] = $GLOBALS[$GLOBALS['idx_lang']];
69 unset ($GLOBALS[$GLOBALS['idx_lang']]);
70 $GLOBALS['idx_lang'] = $idx_lang_normal;
72 if (is_array($surcharges[$fichier])) {
73 $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
74 (array)$GLOBALS[$GLOBALS['idx_lang']],
81 // Traduire une chaine internationalisee
83 // http://doc.spip.org/@inc_traduire_dist
84 function inc_traduire_dist($ori, $lang) {
86 static $deja_vu = array();
88 if (isset($deja_vu[$lang][$ori]))
89 return $deja_vu[$lang][$ori];
91 // modules demandes explicitement <xxx/yyy/zzz:code>
92 if (strpos($ori,':')) {
93 list($modules,$code) = explode(':',$ori,2);
94 $modules = explode('/', $modules);
96 $modules = array('spip', 'ecrire');
101 // parcourir tous les modules jusqu'a ce qu'on trouve
102 foreach ($modules as $module) {
103 $var = "i18n_".$module."_".$lang;
104 if (empty($GLOBALS[$var])) {
105 charger_langue($lang, $module);
107 // surcharge perso -- on cherche (lang/)local_xx.php ...
108 if ($f = chercher_module_lang('local', $lang))
109 surcharger_langue($f);
110 // ... puis (lang/)local.php
111 if ($f = chercher_module_lang('local'))
112 surcharger_langue($f);
114 if (isset($GLOBALS[$var][$code])) {
115 $text = $GLOBALS[$var][$code];
120 // Retour aux sources si la chaine est absente dans la langue cible ;
121 // on essaie d'abord la langue du site, puis a defaut la langue fr
123 AND $lang !== 'fr') {
124 if ($lang !== $GLOBALS['meta']['langue_site'])
125 $text = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site']);
127 $text = inc_traduire_dist($ori, 'fr');
130 // Supprimer la mention <NEW> ou <MODIF>
131 if (substr($text,0,1) === '<')
132 $text = str_replace(array('<NEW>', '<MODIF>'), array(), $text);
134 // Si on n'est pas en utf-8, la chaine peut l'etre...
135 // le cas echeant on la convertit en entites html &#xxx;
136 if ($GLOBALS['meta']['charset'] !== 'utf-8'
137 AND preg_match(',[\x7f-\xff],S', $text)) {
138 include_spip('inc/charsets');
139 $text = charset2unicode($text,'utf-8');
142 $deja_vu[$lang][$ori] = $text;