@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * La langue à utiliser |
| 34 | 34 | * @param string|array $liste_langues |
| 35 | 35 | * La liste des langues valides |
| 36 | - * @return string|bool |
|
| 36 | + * @return false|string |
|
| 37 | 37 | * string : La langue qui a été utilisée si trouvée |
| 38 | 38 | * false : aucune langue ne correspondait à la demande |
| 39 | 39 | **/ |
@@ -89,6 +89,9 @@ discard block |
||
| 89 | 89 | // retourne son 2e argument si c'est un index du premier |
| 90 | 90 | // ou un index approchant sinon et si possible, |
| 91 | 91 | // la langue X etant consideree comme une approche de X_Y |
| 92 | +/** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 92 | 95 | function approcher_langue($trads, $lang = '') { |
| 93 | 96 | |
| 94 | 97 | if (!$lang) { |
@@ -184,6 +187,9 @@ discard block |
||
| 184 | 187 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 185 | 188 | // |
| 186 | 189 | // https://code.spip.net/@menu_langues |
| 190 | +/** |
|
| 191 | + * @param string $nom_select |
|
| 192 | + */ |
|
| 187 | 193 | function menu_langues($nom_select, $default = '') { |
| 188 | 194 | include_spip('inc/actions'); |
| 189 | 195 | |
@@ -218,6 +224,10 @@ discard block |
||
| 218 | 224 | } |
| 219 | 225 | |
| 220 | 226 | // https://code.spip.net/@select_langues |
| 227 | +/** |
|
| 228 | + * @param string $change |
|
| 229 | + * @param string $options |
|
| 230 | + */ |
|
| 221 | 231 | function select_langues($nom_select, $change, $options, $label = "") { |
| 222 | 232 | static $cpt = 0; |
| 223 | 233 | $id = "menu_langues" . $cpt++; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,36 +39,36 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues=null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue']; |
|
| 44 | - } |
|
| 45 | - else { |
|
| 46 | - if (is_array($liste_langues)) { |
|
| 47 | - $liste_langues = implode(',', $liste_langues); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 51 | - |
|
| 52 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 53 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 54 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 55 | - if (!$lang) { |
|
| 56 | - return false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (strpos($liste_langues, ",$lang,") !== false |
|
| 60 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | - and strpos($liste_langues, ",$lang,") !== false) |
|
| 62 | - ) { |
|
| 63 | - |
|
| 64 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 65 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 66 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 67 | - |
|
| 68 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 69 | - } else { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue']; |
|
| 44 | + } |
|
| 45 | + else { |
|
| 46 | + if (is_array($liste_langues)) { |
|
| 47 | + $liste_langues = implode(',', $liste_langues); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 51 | + |
|
| 52 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 53 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 54 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 55 | + if (!$lang) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (strpos($liste_langues, ",$lang,") !== false |
|
| 60 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | + and strpos($liste_langues, ",$lang,") !== false) |
|
| 62 | + ) { |
|
| 63 | + |
|
| 64 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 65 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 66 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 67 | + |
|
| 68 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 69 | + } else { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 82 | 82 | |
| 83 | 83 | function choisir_traduction($trads, $lang = '') { |
| 84 | - $k = approcher_langue($trads, $lang); |
|
| 84 | + $k = approcher_langue($trads, $lang); |
|
| 85 | 85 | |
| 86 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // retourne son 2e argument si c'est un index du premier |
@@ -91,21 +91,21 @@ discard block |
||
| 91 | 91 | // la langue X etant consideree comme une approche de X_Y |
| 92 | 92 | function approcher_langue($trads, $lang = '') { |
| 93 | 93 | |
| 94 | - if (!$lang) { |
|
| 95 | - $lang = $GLOBALS['spip_lang']; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if (isset($trads[$lang])) { |
|
| 99 | - return $lang; |
|
| 100 | - } // cas des langues xx_yy |
|
| 101 | - else { |
|
| 102 | - $r = explode('_', $lang); |
|
| 103 | - if (isset($trads[$r[0]])) { |
|
| 104 | - return $r[0]; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return ''; |
|
| 94 | + if (!$lang) { |
|
| 95 | + $lang = $GLOBALS['spip_lang']; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if (isset($trads[$lang])) { |
|
| 99 | + return $lang; |
|
| 100 | + } // cas des langues xx_yy |
|
| 101 | + else { |
|
| 102 | + $r = explode('_', $lang); |
|
| 103 | + if (isset($trads[$r[0]])) { |
|
| 104 | + return $r[0]; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return ''; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * Nom de la langue, sinon son code. |
| 121 | 121 | **/ |
| 122 | 122 | function traduire_nom_langue($lang) { |
| 123 | - include_spip('inc/lang_liste'); |
|
| 124 | - include_spip('inc/charsets'); |
|
| 123 | + include_spip('inc/lang_liste'); |
|
| 124 | + include_spip('inc/charsets'); |
|
| 125 | 125 | |
| 126 | - return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang); |
|
| 126 | + return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 138 | 138 | // https://code.spip.net/@lang_dir |
| 139 | 139 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 140 | - static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'); |
|
| 140 | + static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'); |
|
| 141 | 141 | |
| 142 | - return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 143 | - $gaucher : $droitier; |
|
| 142 | + return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 143 | + $gaucher : $droitier; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // typo francaise ou anglaise ? |
@@ -150,31 +150,31 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | // https://code.spip.net/@lang_typo |
| 152 | 152 | function lang_typo($lang = '') { |
| 153 | - if (!$lang) { |
|
| 154 | - $lang = isset($GLOBALS['lang_objet']) |
|
| 155 | - ? $GLOBALS['lang_objet'] |
|
| 156 | - : $GLOBALS['spip_lang']; |
|
| 157 | - } |
|
| 158 | - if ($lang == 'eo' |
|
| 159 | - or $lang == 'fr' |
|
| 160 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 161 | - or $lang == 'cpf' |
|
| 162 | - ) { |
|
| 163 | - return 'fr'; |
|
| 164 | - } else { |
|
| 165 | - return 'en'; |
|
| 166 | - } |
|
| 153 | + if (!$lang) { |
|
| 154 | + $lang = isset($GLOBALS['lang_objet']) |
|
| 155 | + ? $GLOBALS['lang_objet'] |
|
| 156 | + : $GLOBALS['spip_lang']; |
|
| 157 | + } |
|
| 158 | + if ($lang == 'eo' |
|
| 159 | + or $lang == 'fr' |
|
| 160 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 161 | + or $lang == 'cpf' |
|
| 162 | + ) { |
|
| 163 | + return 'fr'; |
|
| 164 | + } else { |
|
| 165 | + return 'en'; |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 170 | 170 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 171 | 171 | // https://code.spip.net/@changer_typo |
| 172 | 172 | function changer_typo($lang = '') { |
| 173 | - if ($lang) { |
|
| 174 | - $GLOBALS['lang_objet'] = $lang; |
|
| 175 | - } else { |
|
| 176 | - unset($GLOBALS['lang_objet']); |
|
| 177 | - } |
|
| 173 | + if ($lang) { |
|
| 174 | + $GLOBALS['lang_objet'] = $lang; |
|
| 175 | + } else { |
|
| 176 | + unset($GLOBALS['lang_objet']); |
|
| 177 | + } |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // |
@@ -185,55 +185,55 @@ discard block |
||
| 185 | 185 | // |
| 186 | 186 | // https://code.spip.net/@menu_langues |
| 187 | 187 | function menu_langues($nom_select, $default = '') { |
| 188 | - include_spip('inc/actions'); |
|
| 189 | - |
|
| 190 | - $langues = liste_options_langues($nom_select); |
|
| 191 | - $ret = ""; |
|
| 192 | - if (!count($langues)) { |
|
| 193 | - return ''; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!$default) { |
|
| 197 | - $default = $GLOBALS['spip_lang']; |
|
| 198 | - } |
|
| 199 | - foreach ($langues as $l) { |
|
| 200 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 201 | - $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n"; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if (!test_espace_prive()) { |
|
| 205 | - $cible = self(); |
|
| 206 | - $base = ''; |
|
| 207 | - } else { |
|
| 208 | - $cible = self(); |
|
| 209 | - $base = spip_connect() ? 'base' : ''; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 213 | - |
|
| 214 | - return generer_action_auteur('converser', $base, $cible, |
|
| 215 | - (select_langues($nom_select, $change, $ret) |
|
| 216 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 217 | - " method='post'"); |
|
| 188 | + include_spip('inc/actions'); |
|
| 189 | + |
|
| 190 | + $langues = liste_options_langues($nom_select); |
|
| 191 | + $ret = ""; |
|
| 192 | + if (!count($langues)) { |
|
| 193 | + return ''; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!$default) { |
|
| 197 | + $default = $GLOBALS['spip_lang']; |
|
| 198 | + } |
|
| 199 | + foreach ($langues as $l) { |
|
| 200 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 201 | + $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n"; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if (!test_espace_prive()) { |
|
| 205 | + $cible = self(); |
|
| 206 | + $base = ''; |
|
| 207 | + } else { |
|
| 208 | + $cible = self(); |
|
| 209 | + $base = spip_connect() ? 'base' : ''; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 213 | + |
|
| 214 | + return generer_action_auteur('converser', $base, $cible, |
|
| 215 | + (select_langues($nom_select, $change, $ret) |
|
| 216 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 217 | + " method='post'"); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // https://code.spip.net/@select_langues |
| 221 | 221 | function select_langues($nom_select, $change, $options, $label = "") { |
| 222 | - static $cpt = 0; |
|
| 223 | - $id = "menu_langues" . $cpt++; |
|
| 224 | - |
|
| 225 | - return |
|
| 226 | - "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " . |
|
| 227 | - "<select name='$nom_select' id='$id' " |
|
| 228 | - . ((!test_espace_prive()) ? |
|
| 229 | - ("class='forml menu_langues'") : |
|
| 230 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 231 | - ("class='lang_ecrire'") : |
|
| 232 | - "class='fondl'")) |
|
| 233 | - . $change |
|
| 234 | - . ">\n" |
|
| 235 | - . $options |
|
| 236 | - . "</select>"; |
|
| 222 | + static $cpt = 0; |
|
| 223 | + $id = "menu_langues" . $cpt++; |
|
| 224 | + |
|
| 225 | + return |
|
| 226 | + "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " . |
|
| 227 | + "<select name='$nom_select' id='$id' " |
|
| 228 | + . ((!test_espace_prive()) ? |
|
| 229 | + ("class='forml menu_langues'") : |
|
| 230 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 231 | + ("class='lang_ecrire'") : |
|
| 232 | + "class='fondl'")) |
|
| 233 | + . $change |
|
| 234 | + . ">\n" |
|
| 235 | + . $options |
|
| 236 | + . "</select>"; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -255,34 +255,34 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | function liste_options_langues($nom_select) { |
| 257 | 257 | |
| 258 | - switch ($nom_select) { |
|
| 259 | - # #MENU_LANG |
|
| 260 | - case 'var_lang': |
|
| 261 | - # menu de changement de la langue d'un article |
|
| 262 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 263 | - case 'changer_lang': |
|
| 264 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 265 | - break; |
|
| 266 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 267 | - # les langues presentes sous forme de fichiers de langue |
|
| 268 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 269 | - case 'var_lang_ecrire': |
|
| 270 | - default: |
|
| 271 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 272 | - init_langues(); |
|
| 273 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 274 | - break; |
|
| 258 | + switch ($nom_select) { |
|
| 259 | + # #MENU_LANG |
|
| 260 | + case 'var_lang': |
|
| 261 | + # menu de changement de la langue d'un article |
|
| 262 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 263 | + case 'changer_lang': |
|
| 264 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 265 | + break; |
|
| 266 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 267 | + # les langues presentes sous forme de fichiers de langue |
|
| 268 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 269 | + case 'var_lang_ecrire': |
|
| 270 | + default: |
|
| 271 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 272 | + init_langues(); |
|
| 273 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 274 | + break; |
|
| 275 | 275 | |
| 276 | 276 | # dernier choix possible : toutes les langues = langues_proposees |
| 277 | 277 | # + langues_multilingues ; mais, ne sert pas |
| 278 | 278 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 279 | - } |
|
| 280 | - if (count($langues) <= 1) { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - sort($langues); |
|
| 279 | + } |
|
| 280 | + if (count($langues) <= 1) { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + sort($langues); |
|
| 284 | 284 | |
| 285 | - return $langues; |
|
| 285 | + return $langues; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | |
@@ -297,38 +297,38 @@ discard block |
||
| 297 | 297 | **/ |
| 298 | 298 | function verifier_lang_url() { |
| 299 | 299 | |
| 300 | - // quelle langue est demandee ? |
|
| 301 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 302 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 303 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 304 | - } |
|
| 305 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 306 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 307 | - } |
|
| 308 | - if (isset($_GET['lang'])) { |
|
| 309 | - $lang_demandee = $_GET['lang']; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 313 | - if ($GLOBALS['spip_lang'] != $lang_demandee |
|
| 314 | - and changer_langue($lang_demandee) |
|
| 315 | - and $lang_demandee != @$_GET['lang'] |
|
| 316 | - ) { |
|
| 317 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 318 | - // ici on a besoin des var_truc |
|
| 319 | - foreach ($_GET as $var => $val) { |
|
| 320 | - if (!strncmp('var_', $var, 4)) { |
|
| 321 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - include_spip('inc/headers'); |
|
| 325 | - redirige_par_entete($destination); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 329 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 330 | - // (pour criteres {lang}). |
|
| 331 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 300 | + // quelle langue est demandee ? |
|
| 301 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 302 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 303 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 304 | + } |
|
| 305 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 306 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 307 | + } |
|
| 308 | + if (isset($_GET['lang'])) { |
|
| 309 | + $lang_demandee = $_GET['lang']; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 313 | + if ($GLOBALS['spip_lang'] != $lang_demandee |
|
| 314 | + and changer_langue($lang_demandee) |
|
| 315 | + and $lang_demandee != @$_GET['lang'] |
|
| 316 | + ) { |
|
| 317 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 318 | + // ici on a besoin des var_truc |
|
| 319 | + foreach ($_GET as $var => $val) { |
|
| 320 | + if (!strncmp('var_', $var, 4)) { |
|
| 321 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + include_spip('inc/headers'); |
|
| 325 | + redirige_par_entete($destination); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 329 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 330 | + // (pour criteres {lang}). |
|
| 331 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -346,21 +346,21 @@ discard block |
||
| 346 | 346 | * La langue sélectionnée |
| 347 | 347 | **/ |
| 348 | 348 | function utiliser_langue_site($liste_langues = null) { |
| 349 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 350 | - if (isset($GLOBALS['meta']['langue_site']) |
|
| 351 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 352 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 353 | - and (!isset($GLOBALS['spip_lang']) |
|
| 354 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 355 | - ) { |
|
| 356 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 357 | - } |
|
| 358 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 359 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 360 | - spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $GLOBALS['spip_lang']; |
|
| 349 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 350 | + if (isset($GLOBALS['meta']['langue_site']) |
|
| 351 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 352 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 353 | + and (!isset($GLOBALS['spip_lang']) |
|
| 354 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 355 | + ) { |
|
| 356 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 357 | + } |
|
| 358 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 359 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 360 | + spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $GLOBALS['spip_lang']; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -379,30 +379,30 @@ discard block |
||
| 379 | 379 | **/ |
| 380 | 380 | function utiliser_langue_visiteur($liste_langues = null) { |
| 381 | 381 | |
| 382 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 383 | - if (isset($_COOKIE[$l])) { |
|
| 384 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 385 | - return $l; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 390 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 391 | - return $l; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 398 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 399 | - return $l; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return utiliser_langue_site($liste_langues); |
|
| 382 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 383 | + if (isset($_COOKIE[$l])) { |
|
| 384 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 385 | + return $l; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 390 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 391 | + return $l; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 398 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 399 | + return $l; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return utiliser_langue_site($liste_langues); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return int |
| 413 | 413 | */ |
| 414 | 414 | function match_langue($chaine) { |
| 415 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 415 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -430,36 +430,36 @@ discard block |
||
| 430 | 430 | **/ |
| 431 | 431 | function init_langues() { |
| 432 | 432 | |
| 433 | - // liste des langues dans les meta, sauf a l'install |
|
| 434 | - $all_langs = @$GLOBALS['meta']['langues_proposees']; |
|
| 435 | - |
|
| 436 | - $tout = array(); |
|
| 437 | - if (!$all_langs) { |
|
| 438 | - // trouver tous les modules lang/spip_xx.php |
|
| 439 | - $modules = find_all_in_path("lang/", "/spip_([a-z_]+)\.php$"); |
|
| 440 | - foreach ($modules as $name => $path) { |
|
| 441 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 442 | - if (match_langue($regs[1])) { |
|
| 443 | - $tout[] = $regs[1]; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - sort($tout); |
|
| 448 | - $tout = join(',', $tout); |
|
| 449 | - // Si les langues n'ont pas change, ne rien faire |
|
| 450 | - if ($tout != $all_langs) { |
|
| 451 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 452 | - include_spip('inc/meta'); |
|
| 453 | - ecrire_meta('langues_proposees', $tout); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 457 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 458 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 459 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false)) |
|
| 460 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 461 | - ecrire_meta('langue_site', $tout); |
|
| 462 | - } |
|
| 433 | + // liste des langues dans les meta, sauf a l'install |
|
| 434 | + $all_langs = @$GLOBALS['meta']['langues_proposees']; |
|
| 435 | + |
|
| 436 | + $tout = array(); |
|
| 437 | + if (!$all_langs) { |
|
| 438 | + // trouver tous les modules lang/spip_xx.php |
|
| 439 | + $modules = find_all_in_path("lang/", "/spip_([a-z_]+)\.php$"); |
|
| 440 | + foreach ($modules as $name => $path) { |
|
| 441 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 442 | + if (match_langue($regs[1])) { |
|
| 443 | + $tout[] = $regs[1]; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + sort($tout); |
|
| 448 | + $tout = join(',', $tout); |
|
| 449 | + // Si les langues n'ont pas change, ne rien faire |
|
| 450 | + if ($tout != $all_langs) { |
|
| 451 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 452 | + include_spip('inc/meta'); |
|
| 453 | + ecrire_meta('langues_proposees', $tout); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 457 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 458 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 459 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false)) |
|
| 460 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 461 | + ecrire_meta('langue_site', $tout); |
|
| 462 | + } |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | * Code html de la balise <html> |
| 474 | 474 | **/ |
| 475 | 475 | function html_lang_attributes() { |
| 476 | - $lang = $GLOBALS['spip_lang']; |
|
| 477 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 476 | + $lang = $GLOBALS['spip_lang']; |
|
| 477 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 478 | 478 | |
| 479 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 479 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | * @return string |
| 491 | 491 | */ |
| 492 | 492 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 493 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 493 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | |
@@ -37,17 +37,17 @@ discard block |
||
| 37 | 37 | * string : La langue qui a été utilisée si trouvée |
| 38 | 38 | * false : aucune langue ne correspondait à la demande |
| 39 | 39 | **/ |
| 40 | -function changer_langue($lang, $liste_langues=null) { |
|
| 40 | +function changer_langue($lang, $liste_langues = null) { |
|
| 41 | 41 | |
| 42 | 42 | if (is_null($liste_langues)) { |
| 43 | - $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue']; |
|
| 43 | + $liste_langues = @$GLOBALS['meta']['langues_proposees'].','.@$GLOBALS['meta']['langues_multilingue']; |
|
| 44 | 44 | } |
| 45 | 45 | else { |
| 46 | 46 | if (is_array($liste_langues)) { |
| 47 | 47 | $liste_langues = implode(',', $liste_langues); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | + $liste_langues = ','.$liste_langues.','; |
|
| 51 | 51 | |
| 52 | 52 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 53 | 53 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | foreach ($langues as $l) { |
| 200 | 200 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 201 | - $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n"; |
|
| 201 | + $ret .= "<option value='$l'$selected>[".$l."] ".traduire_nom_langue($l)."</option>\n"; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | if (!test_espace_prive()) { |
@@ -213,23 +213,21 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | return generer_action_auteur('converser', $base, $cible, |
| 215 | 215 | (select_langues($nom_select, $change, $ret) |
| 216 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 216 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 217 | 217 | " method='post'"); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // https://code.spip.net/@select_langues |
| 221 | 221 | function select_langues($nom_select, $change, $options, $label = "") { |
| 222 | 222 | static $cpt = 0; |
| 223 | - $id = "menu_langues" . $cpt++; |
|
| 223 | + $id = "menu_langues".$cpt++; |
|
| 224 | 224 | |
| 225 | 225 | return |
| 226 | - "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " . |
|
| 226 | + "<label for='$id'>".($label ? $label : _T('info_langues'))."</label> ". |
|
| 227 | 227 | "<select name='$nom_select' id='$id' " |
| 228 | 228 | . ((!test_espace_prive()) ? |
| 229 | - ("class='forml menu_langues'") : |
|
| 230 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 231 | - ("class='lang_ecrire'") : |
|
| 232 | - "class='fondl'")) |
|
| 229 | + ("class='forml menu_langues'") : (($nom_select == 'var_lang_ecrire') ? |
|
| 230 | + ("class='lang_ecrire'") : "class='fondl'")) |
|
| 233 | 231 | . $change |
| 234 | 232 | . ">\n" |
| 235 | 233 | . $options |
@@ -353,7 +351,7 @@ discard block |
||
| 353 | 351 | and (!isset($GLOBALS['spip_lang']) |
| 354 | 352 | or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 355 | 353 | ) { |
| 356 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 354 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 357 | 355 | } |
| 358 | 356 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 359 | 357 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -456,7 +454,7 @@ discard block |
||
| 456 | 454 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 457 | 455 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 458 | 456 | $GLOBALS['meta']['langue_site'] = $tout = |
| 459 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false)) |
|
| 457 | + (!$all_langs or (strpos(','._LANGUE_PAR_DEFAUT.',', ",$all_langs,") !== false)) |
|
| 460 | 458 | ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
| 461 | 459 | ecrire_meta('langue_site', $tout); |
| 462 | 460 | } |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | |
| 42 | 42 | if (is_null($liste_langues)) { |
| 43 | 43 | $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue']; |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | if (is_array($liste_langues)) { |
| 47 | 46 | $liste_langues = implode(',', $liste_langues); |
| 48 | 47 | } |