Rev 609 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/***************************************************************************\* SPIP, Systeme de publication pour l'internet ** ** Copyright (c) 2001-2005 ** Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James ** ** Ce programme est un logiciel libre distribue sous licence GNU/GPL. ** Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *\***************************************************************************/// Ce fichier ne sera execute qu'une foisif (defined("_ECRIRE_INC_LANG")) return;define("_ECRIRE_INC_LANG", "1");//// Charger un fichier langue//function charger_langue($lang, $module = 'spip') {$fichier_lang = $module.'_'.$lang.'.php3';$fichier_lang_exists = @is_readable(_DIR_LANG . $fichier_lang);if ($fichier_lang_exists) {$GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;include_lang($fichier_lang);} else {// si le fichier de langue du module n'existe pas, on se rabat sur// la langue par defaut du site -- et au pire sur le francais, qui// *par definition* doit exister, et on copie le tableau dans la// var liee a la langue$l = lire_meta('langue_site');if (!is_readable(_DIR_LANG . $module.'_'.$l.'.php3'))$l = 'fr';$fichier_lang = $module.'_' .$l. '.php3';if (is_readable(_DIR_LANG . $fichier_lang)) {$GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;include_lang($fichier_lang);$GLOBALS['i18n_'.$module.'_'.$lang]= &$GLOBALS['i18n_'.$module.'_'.$l];#spip_log("module de langue : ${module}_$l.php3");}}// surcharge perso -- on cherche le fichier local(_xx).php3 dans le cheminif ($f = (find_in_path('local.php3')))surcharger_langue($f);if ($f = (find_in_path('local_'.$lang.'.php3')))surcharger_langue($f);// compatibilite ascendante : chercher aussi local_xx.php3 dans ecrire/lang/else if (@is_readable($f = _DIR_LANG . 'local_'.$lang.'.php3'))surcharger_langue($f);}//// Surcharger le fichier de langue courant avec un autre (tordu, hein...)//function surcharger_langue($f) {$idx_lang_normal = $GLOBALS['idx_lang'];$GLOBALS['idx_lang'] .= '_temporaire';include($f);if (is_array($GLOBALS[$GLOBALS['idx_lang']]))foreach ($GLOBALS[$GLOBALS['idx_lang']] as $var => $val)$GLOBALS[$idx_lang_normal][$var] = $val;unset ($GLOBALS[$GLOBALS['idx_lang']]);$GLOBALS['idx_lang'] = $idx_lang_normal;}//// Changer la langue courante//function changer_langue($lang) {global $all_langs, $spip_lang_rtl, $spip_lang_right, $spip_lang_left, $spip_lang_dir, $spip_dir_lang;$liste_langues = $all_langs.','.lire_meta('langues_multilingue');if ($lang && ereg(",$lang,", ",$liste_langues,")) {$GLOBALS['spip_lang'] = $lang;$spip_lang_rtl = lang_dir($lang, '', '_rtl');$spip_lang_left = lang_dir($lang, 'left', 'right');$spip_lang_right = lang_dir($lang, 'right', 'left');$spip_lang_dir = lang_dir($lang);$spip_dir_lang = " dir='$spip_lang_dir'";return true;}elsereturn false;}//// Regler la langue courante selon les infos envoyees par le brouteur//function regler_langue_navigateur() {global $_SERVER, $_COOKIE;$accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);if (is_array($accept_langs)) {while(list(, $s) = each($accept_langs)) {if (eregi('^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$', trim($s), $r)) {$lang = strtolower($r[1]);if (changer_langue($lang)) return $lang;}}}return false;}//// Traduire une chaine internationalisee//function traduire_chaine($code, $args) {global $spip_lang;// modules par defautif (_DIR_RESTREINT)$modules = array('spip');else$modules = array('spip', 'ecrire');// modules demandes explicitement$code_ori = $code; # le garder pour le fallback plus tardif (strpos($code, ':')) {if (ereg("^([a-z/]+):(.*)$", $code, $regs)) {$modules = explode("/",$regs[1]);$code = $regs[2];}}// parcourir tous les modules jusqu'a ce qu'on trouve$text = '';while (!$text AND (list(,$module) = each ($modules))) {$var = "i18n_".$module."_".$spip_lang;if (empty($GLOBALS[$var]))charger_langue($spip_lang, $module);$text = $GLOBALS[$var][$code];}// fallback langues pas finies ou en retard (eh oui, c'est moche...)if ($spip_lang<>'fr') {$text = ereg_replace("^<(NEW|MODIF)>","",$text);if (!$text) {$spip_lang_temp = $spip_lang;$spip_lang = 'fr';$text = traduire_chaine($code_ori, $args);$spip_lang = $spip_lang_temp;}}// inserer les variablesif (!$args) return $text;while (list($name, $value) = each($args))$text = str_replace ("@$name@", $value, $text);return $text;}function traduire_nom_langue($lang) {init_codes_langues();$r = $GLOBALS['codes_langues'][$lang];if (!$r) $r = $lang;include_ecrire("inc_charsets.php3");$r = html2unicode($r);return $r;}function init_codes_langues() {$GLOBALS['codes_langues'] = array('aa' => "Afar",'ab' => "Abkhazian",'af' => "Afrikaans",'am' => "Amharic",'ar' => "العربية",'as' => "Assamese",'ast' => "asturiano",'ay' => "Aymara",'az' => "Азәрбајҹан",'ba' => "Bashkir",'be' => "Беларускі",'bg' => "български",'bh' => "Bihari",'bi' => "Bislama",'bm' => "Bambara",'bn' => "Bengali; Bangla",'bo' => "Tibetan",'br' => "breton",'ca' => "català",'co' => "corsu",'cpf' => "Kréol réyoné",'cpf_dom' => "Kreyòl",'cpf_hat' => "Kréyòl (Péyi Dayiti)",'cs' => "čeština",'cy' => "Cymraeg", # welsh, gallois'da' => "dansk",'de' => "Deutsch",'dz' => "Bhutani",'el' => "ελληνικά",'en' => "English",'en_hx' => "H4ck3R",'eo' => "Esperanto",'es' => "Español",'es_co' => "Colombiano",'et' => "eesti",'eu' => "euskara",'fa' => "فارسى",'ff' => "Fulah", // peul'fi' => "suomi",'fj' => "Fiji",'fo' => "føroyskt",'fon' => "fongbè",'fr' => "français",'fr_tu' => "français copain",'fy' => "Frisian",'ga' => "Irish",'gd' => "Scots Gaelic",'gl' => "galego",'gn' => "Guarani",'gu' => "Gujarati",'ha' => "Hausa",'he' => "עברית",'hi' => "हिंदी",'hr' => "hrvatski",'hu' => "magyar",'hy' => "Armenian",'ia' => "Interlingua",'id' => "Indonesia",'ie' => "Interlingue",'ik' => "Inupiak",'is' => "íslenska",'it' => "italiano",'iu' => "Inuktitut",'ja' => "日本語",'jw' => "Javanese",'ka' => "ქართული",'kk' => "Қазащb",'kl' => "Greenlandic",'km' => "Cambodian",'kn' => "Kannada",'ko' => "한국어",'ks' => "Kashmiri",'ku' => "Kurdish",'ky' => "Kirghiz",'la' => "Latin",'lb' => "Lëtzebuergesch",'ln' => "Lingala",'lo' => "Laothian",'lt' => "lietuvių",'lu' => "luba-katanga",'lv' => "latviešu",'mg' => "Malagasy",'mi' => "Maori",'mk' => "македонски јазик",'ml' => "Malayalam",'mn' => "Mongolian",'mo' => "Moldavian",'mos' => "Moré",'mr' => "मराठी",'ms' => "Bahasa Malaysia",'mt' => "Maltese",'my' => "Burmese",'na' => "Nauru",'ne' => "Nepali",'nl' => "Nederlands",'no' => "norsk",'nb' => "norsk bokmål",'nn' => "norsk nynorsk",'oc' => "òc",'oc_lnc' => "òc lengadocian",'oc_ni' => "òc niçard",'oc_ni_la' => "òc niçard (larg)",'oc_prv' => "òc provençau",'oc_gsc' => "òc gascon",'oc_lms' => "òc lemosin",'oc_auv' => "òc auvernhat",'oc_va' => "òc vivaroaupenc",'om' => "(Afan) Oromo",'or' => "Oriya",'pa' => "Punjabi",'pl' => "polski",'ps' => "Pashto, Pushto",'pt' => "Português",'pt_br' => "Português do Brasil",'qu' => "Quechua",'rm' => "Rhaeto-Romance",'rn' => "Kirundi",'ro' => "română",'ru' => "русский",'rw' => "Kinyarwanda",'sa' => "संस्कृत",'sc' => "sarde",'sd' => "Sindhi",'sg' => "Sangho",'sh' => "srpskohrvastski",'sh_lat' => 'srpskohrvastski','sh_cyr' => 'Српскохрватски','si' => "Sinhalese",'sk' => "slovenčina", // (Slovakia)'sl' => "slovenščina", // (Slovenia)'sm' => "Samoan",'sn' => "Shona",'so' => "Somali",'sq' => "shqipe",'sr' => "српски",'ss' => "Siswati",'st' => "Sesotho",'su' => "Sundanese",'sv' => "svenska",'sw' => "Kiswahili",'ta' => "தமிழ் - tamil",'te' => "Telugu",'tg' => "Tajik",'th' => "ไทย",'ti' => "Tigrinya",'tk' => "Turkmen",'tl' => "Tagalog",'tn' => "Setswana",'to' => "Tonga",'tr' => "Türkçe",'ts' => "Tsonga",'tt' => "Татар",'tw' => "Twi",'ug' => "Uighur",'uk' => "україньска",'ur' => "ٱردو",'uz' => "U'zbek",'vi' => "Tiếng Việt",'vo' => "Volapuk",'wo' => "Wolof",'xh' => "Xhosa",'yi' => "Yiddish",'yo' => "Yoruba",'za' => "Zhuang",'zh' => "中文",'zu' => "Zulu");}//// Filtres de langue//// afficher 'gaucher' si la langue est arabe, hebreu, persan, 'droitier' sinon// utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHTfunction lang_dir($lang, $droitier='ltr', $gaucher='rtl') {if ($lang=='fa' OR $lang=='ar' OR $lang == 'he')return $gaucher;elsereturn $droitier;}function lang_typo($lang) {if ($lang == 'eo' OR $lang == 'fr' OR substr($lang, 0, 3) == 'fr_' OR $lang == 'cpf')return 'fr';else if ($lang)return 'en';elsereturn false;}// service pour que l'espace prive reflete la typo et la direction des objets affichesfunction changer_typo($lang = '', $source = '') {global $lang_typo, $lang_dir, $dir_lang;if (ereg("^(article|rubrique|breve|auteur)([0-9]+)", $source, $regs)) {$r = spip_fetch_array(spip_query("SELECT lang FROM spip_".$regs[1]."s WHERE id_".$regs[1]."=".$regs[2]));$lang = $r['lang'];}if (!$lang)$lang = lire_meta('langue_site');$lang_typo = lang_typo($lang);$lang_dir = lang_dir($lang);$dir_lang = " dir='$lang_dir'";}// selectionner une languefunction lang_select ($lang='') {global $pile_langues, $spip_lang;array_push($pile_langues, $spip_lang);changer_langue($lang);}// revenir a la langue precedentefunction lang_dselect ($rien='') {global $pile_langues;changer_langue(array_pop($pile_langues));}//// Afficher un menu de selection de langue// - 'var_lang_ecrire' = langue interface privee,// - 'var_lang' = langue de l'article, espace public// - 'changer_lang' = langue de l'article, espace prive//function menu_langues($nom_select = 'var_lang', $default = '', $texte = '', $herit = '') {global $couleur_foncee, $couleur_claire, $connect_id_auteur;$ret = liste_options_langues($nom_select, $default, $herit);if (!$ret) return '';if (!$couleur_foncee) $couleur_foncee = '#044476';$lien = $GLOBALS['clean_link'];if ($nom_select == 'changer_lang') {$lien->delvar('changer_lang');$lien->delvar('url');$post = $lien->getUrl();$cible = '';} else {// eviter un bug a l'installation ; mais, dans le cas general,// pourquoi aurait-on besoin ici d'une URL absolue ?if (!defined('_ECRIRE_INSTALL')AND !defined('_TEST_DIRS'))$site = lire_meta("adresse_site");if (!$site)if (_DIR_RESTREINT)$site = '.';else$site = '..';if (!_DIR_RESTREINT) {include_ecrire('inc_admin.php3');$cible = _DIR_RESTREINT_ABS . $lien->getUrl();$post = "$site/spip_cookie.php3?id_auteur=$connect_id_auteur&valeur=".calculer_action_auteur('var_lang_ecrire', $connect_id_auteur);} else {$cible = $lien->getUrl();$post = "$site/spip_cookie.php3";}}$postcomplet = new Link($post);if ($cible) $postcomplet->addvar('url', $cible);return "<form action='". $post. "' method='post' style='margin:0px; padding:0px;'>". (!$cible ? '' : "<input type='hidden' name='url' value='".quote_amp($cible)."' />"). $texte. "<select name='$nom_select' ". (_DIR_RESTREINT ?("class='forml' style='vertical-align: top; max-height: 24px; margin-bottom: 5px; width: 120px;'") :(($nom_select == 'var_lang_ecrire') ?("class='verdana1' style='background-color: " . $couleur_foncee. "; max-height: 24px; border: 1px solid white; color: white; width: 100px;'") :"class='fondl'")). " onchange=\"document.location.href='". $postcomplet->geturl()."&$nom_select='+this.options[this.selectedIndex].value\">\n". $ret. "</select>\n". "<noscript><input type='submit' name='Valider' value='>>' class='spip_bouton' /></noscript>". "</form>";}function liste_options_langues($nom_select, $default='', $herit='') {if ($default == '') $default = $GLOBALS['spip_lang'];if ($nom_select == 'var_lang_ecrire')$langues = explode(',', $GLOBALS['all_langs']);else$langues = explode(',', lire_meta('langues_multilingue'));if (count($langues) <= 1) return '';$ret = '';sort($langues);while (list(, $l) = each ($langues)) {$selected = ($l == $default) ? ' selected=\'selected\'' : '';if ($l == $herit) {$ret .= "<option class='maj-debut' style='font-weight: bold;' value='herit'$selected>".traduire_nom_langue($herit)." ("._T('info_multi_herit').")</option>\n";}else $ret .= "<option class='maj-debut' value='$l'$selected>".traduire_nom_langue($l)."</option>\n";}return $ret;}//// Cette fonction est appelee depuis inc-public-global si on a installe// la variable de personnalisation $forcer_lang ; elle renvoie le brouteur// si necessaire vers l'URL xxxx?lang=ll//function verifier_lang_url() {global $_GET, $_COOKIE, $spip_lang, $clean_link;// quelle langue est demandee ?$lang_demandee = lire_meta('langue_site');if ($_COOKIE['spip_lang_ecrire'])$lang_demandee = $_COOKIE['spip_lang_ecrire'];if ($_COOKIE['spip_lang'])$lang_demandee = $_COOKIE['spip_lang'];if ($_GET['lang'])$lang_demandee = $_GET['lang'];// Verifier que la langue demandee existeinclude_ecrire('inc_lang.php3');lang_select($lang_demandee);$lang_demandee = $spip_lang;// Renvoyer si besoinif (!($_GET['lang']<>'' AND $lang_demandee == $_GET['lang'])AND !($_GET['lang']=='' AND $lang_demandee == lire_meta('langue_site'))){$destination = new Link;$destination->addvar('lang', $lang_demandee);if ($d = $GLOBALS['var_mode'])$destination->addvar('var_mode', $d);redirige_par_entete($destination->getUrl());}// Subtilite : si la langue demandee par cookie est la bonne// alors on fait comme si $lang etait passee dans l'URL// (pour criteres {lang}).$GLOBALS['lang'] = $_GET['lang'] = $spip_lang;}//// Selection de langue haut niveau//function utiliser_langue_site() {changer_langue($GLOBALS['langue_site']);}function utiliser_langue_visiteur() {global $_COOKIE;if (!regler_langue_navigateur())utiliser_langue_site();if (!empty($GLOBALS['auteur_session']['lang']))changer_langue($GLOBALS['auteur_session']['lang']);$cookie_lang = (_DIR_RESTREINT ? 'spip_lang' : 'spip_lang_ecrire');if (!empty($_COOKIE[$cookie_lang]))changer_langue($_COOKIE[$cookie_lang]);}//// Initialisation//function init_langues() {global $all_langs, $langue_site;global $pile_langues, $lang_typo, $lang_dir;$all_langs = lire_meta('langues_proposees').lire_meta('langues_proposees2');$langue_site = lire_meta('langue_site');$pile_langues = array();$lang_typo = '';$lang_dir = '';$toutes_langs = Array();if (!$all_langs || !$langue_site || !_DIR_RESTREINT) {if (!$d = @opendir(_DIR_LANG)) return;while ($f = readdir($d)) {if (ereg('^spip_([a-z_]+)\.php3?$', $f, $regs))$toutes_langs[] = $regs[1];}closedir($d);sort($toutes_langs);$all_langs2 = join(',', $toutes_langs);// Si les langues n'ont pas change, ne rien faireif ($all_langs2 != $all_langs) {$all_langs = $all_langs2;if (!$langue_site) {// Initialisation : le francais par defaut, sinon la premiere langue trouveeif (ereg(',fr,', ",$all_langs,")) $langue_site = 'fr';else list(, $langue_site) = each($toutes_langs);if (defined("_ECRIRE_INC_META"))ecrire_meta('langue_site', $langue_site);}if (defined("_ECRIRE_INC_META")) {# sur spip.net le nombre de langues proposees fait exploser# ce champ limite a 255 caracteres ; a revoir...if (strlen($all_langs) <= 255) {ecrire_meta('langues_proposees', $all_langs);effacer_meta('langues_proposees2');} else {ecrire_meta('langues_proposees', substr($all_langs,0,255));ecrire_meta('langues_proposees2', substr($all_langs,255));}ecrire_metas();}}}}init_langues();utiliser_langue_site();?>