Bifurcation depuis
spip / spip
21101 validations de retard le dépôt en amont.
-
Antoine Pitrou a rédigéAntoine Pitrou a rédigé
inc_lang.php3 15,81 Kio
<?php
// Ce fichier ne sera execute qu'une fois
if (defined("_ECRIRE_INC_LANG")) return;
define("_ECRIRE_INC_LANG", "1");
//
// Ecrire un fichier cache langue
//
function ecrire_cache_lang($lang, $module) {
include_ecrire('inc_filtres.php3');
$fichier_lang = $module.'_'.$lang.'.php3';
if ($t = @fopen('CACHE/lang_'.$fichier_lang.'_'.@getmypid(), "wb")) {
@fwrite($t, "<"."?php\n\n// Ceci est le CACHE d'un fichier langue spip\n\n");
if (is_array($cache = $GLOBALS['cache_lang'][$lang])) {
@fwrite($t, "\$GLOBALS[\$GLOBALS['idx_lang']] = array(\n");
$texte = '';
ksort($cache);
reset($cache);
while (list($code, ) = each($cache))
$texte .= ",\n\t'".$code."' => '".texte_script($GLOBALS['i18n_'.$module.'_'.$lang][$code])."'";
@fwrite($t, substr($texte,2)."\n);\n\n");
@fwrite($t, "\$GLOBALS['cache_lang']['$lang'] = array(\n");
$texte = '';
reset($cache);
while (list($code, ) = each($cache))
$texte .= ",\n\t'".$code."' => 1";
@fwrite($t, substr($texte,2)."\n);\n\n");
}
@fwrite($t, "\n\n?".">\n");
@fclose($t);
@rename('CACHE/lang_'.$fichier_lang.'_'.@getmypid(), 'CACHE/lang_'.$fichier_lang);
}
}
function ecrire_caches_langues() {
global $cache_lang_modifs;
reset($cache_lang_modifs);
while(list($module,$cache_module) = each($cache_lang_modifs))
while(list($lang, ) = each($cache_module))
ecrire_cache_lang($lang, $module);
}
//
// Charger un fichier langue
//
function charger_langue($lang, $module = 'spip', $forcer = false) {
global $dir_ecrire, $flag_ecrire;
$fichier_lang = 'lang/'.$module.'_'.$lang.'.php3';
$fichier_lang_exists = @file_exists($dir_ecrire.$fichier_lang);
// chercher dans le fichier cache ?
if (!$flag_ecrire AND $fichier_lang_exists) {
if (!$forcer AND @file_exists('CACHE/lang_'.$module.'_'.$lang.'.php3')
AND (@filemtime('CACHE/lang_'.$module.'_'.$lang.'.php3') > @filemtime('ecrire/lang/'.$module.'_'.$lang.'.php3'))
AND (@filemtime('CACHE/lang_'.$module.'_'.$lang.'.php3') > @filemtime('ecrire/lang/perso.php3'))) {
$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$lang;
return include_local('CACHE/lang_'.$module.'_'.$lang.'.php3');
}
else $GLOBALS['cache_lang_modifs'][$module][$lang] = true;
}
if ($fichier_lang_exists) {
$GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;
include_ecrire ($fichier_lang);
} else {
// si le fichier de langue du module n'existe pas, on se rabat sur
// le francais, qui *par definition* doit exister, et on copie le
// tableau 'fr' dans la var liee a la langue
$fichier_lang = 'lang/'.$module.'_fr.php3';
if (@file_exists($dir_ecrire.$fichier_lang)) {
$GLOBALS['idx_lang']='i18n_'.$module.'_fr';
include_ecrire ($fichier_lang);
}
$GLOBALS['i18n_'.$module.'_'.$lang] = $GLOBALS['i18n_'.$module.'_fr'];
}
// surcharge perso
if (@file_exists($dir_ecrire.'lang/perso.php3')) {
include($dir_ecrire.'lang/perso.php3');
}
}
//
// 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;
if ($lang && ereg(",$lang,", ",$all_langs,")) {
$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;
}
else
return false;
}
//
// Regler la langue courante selon les infos envoyees par le brouteur
//
function regler_langue_navigateur() {
global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS;
if ($cookie_lang = $HTTP_COOKIE_VARS['spip_lang']) {
if (changer_langue($cookie_lang)) return $cookie_lang;
}
$accept_langs = explode(',', $HTTP_SERVER_VARS['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, $flag_ecrire;
global $cache_lang;
// liste des modules a parcourir
$modules = array('spip');
if (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
while (!$text AND (list(,$module) = each ($modules))) {
$var = "i18n_".$module."_".$spip_lang;
if (!$GLOBALS[$var]) charger_langue($spip_lang, $module);
if (!$flag_ecrire) {
if (!isset($GLOBALS[$var][$code]))
charger_langue($spip_lang, $module, $code);
if (isset($GLOBALS[$var][$code]))
$cache_lang[$spip_lang][$code] = 1;
}
$text = $GLOBALS[$var][$code];
}
// 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, $args);
$spip_lang = $spip_lang_temp;
}
}
// inserer les variables
if (!$args) return $text;
while (list($name, $value) = each($args))
$text = str_replace ("@$name@", $value, $text);
return $text;
}
function traduire_nom_langue($lang) {
$r = $GLOBALS['codes_langues'][$lang];
if (!$r) $r = $lang;
return $r;
}
function init_codes_langues() {
$GLOBALS['codes_langues'] = array(
'aa' => "Afar",
'ab' => "Abkhazian",
'af' => "Afrikaans",
'am' => "Amharic",
'ar' => "العربية",
'as' => "Assamese",
'ay' => "Aymara",
'az' => "Азәрбајҹан",
'ba' => "Bashkir",
'be' => "Беларускі",
'bg' => "български",
'bh' => "Bihari",
'bi' => "Bislama",
'bn' => "Bengali; Bangla",
'bo' => "Tibetan",
'br' => "breton",
'ca' => "català",
'co' => "corsu",
'cpf' => "Kréol réyoné",
'cpf_dom' => "Kreyòl",
'cs' => "čeština",
'cy' => "Welsh",
'da' => "dansk",
'de' => "Deutsch",
'dz' => "Bhutani",
'el' => "ελληνικά",
'en' => "English",
'eo' => "Esperanto",
'es' => "Español",
'es_co' => "Colombiano",
'et' => "eesti",
'eu' => "euskara",
'fa' => "فارسى",
'fi' => "suomi",
'fj' => "Fiji",
'fo' => "føroyskt",
'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' => "Bahasa 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",
'ln' => "Lingala",
'lo' => "Laothian",
'lt' => "lietuvių",
'lv' => "latviešu",
'mg' => "Malagasy",
'mi' => "Maori",
'mk' => "македонски јазик",
'ml' => "Malayalam",
'mn' => "Mongolian",
'mo' => "Moldavian",
'mr' => "मराठी",
'ms' => "Bahasa Malaysia",
'mt' => "Maltese",
'my' => "Burmese",
'na' => "Nauru",
'ne' => "Nepali",
'nl' => "Nederlands",
'no' => "norsk",
'oc_lnc' => "òc lengadocian",
'oc_ni' => "òc niçard",
'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",
'qu' => "Quechua",
'rm' => "Rhaeto-Romance",
'rn' => "Kirundi",
'ro' => "română",
'ru' => "русский",
'rw' => "Kinyarwanda",
'sa' => "संस्कृत",
'sd' => "Sindhi",
'sg' => "Sangho",
'sh' => "Serbo-Croatian",
'si' => "Sinhalese",
'sk' => "slovenčina",
'sl' => "slovenski",
'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",
'yor' => "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_RIGHT
function lang_dir($lang, $droitier='ltr', $gaucher='rtl') {
if ($lang=='fa' OR $lang=='ar' OR $lang == 'he')
return $gaucher;
else
return $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';
else
return false;
}
// service pour que l'espace prive reflete la typo et la direction des objets affiches
function 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 langue
function lang_select ($lang='') {
global $pile_langues, $spip_lang;
php3_array_push($pile_langues, $spip_lang);
changer_langue($lang);
}
// revenir a la langue precedente
function lang_dselect ($rien='') {
global $pile_langues;
changer_langue(php3_array_pop($pile_langues));
}
//
// Afficher un menu de selection de langue
//
function menu_langues($nom_select = 'var_lang', $default = '', $texte = '', $herit = '') {
global $couleur_foncee, $couleur_claire;
if ($default == '')
$default = $GLOBALS['spip_lang'];
if ($nom_select == 'var_lang')
$langues = explode(',', $GLOBALS['all_langs']);
else
$langues = explode(',', lire_meta('langues_multilingue'));
if (count($langues) <= 1) return;
if (!$couleur_foncee) $couleur_foncee = '#044476';
$lien = $GLOBALS['clean_link'];
$lien->delVar($nom_select);
$lien = $lien->getUrl();
$amp = (strpos(' '.$lien,'?') ? '&' : '?');
$ret = "<form action='$lien' method='post' style='margin:0px; padding:0px;'>";
$ret .= $texte;
if ($nom_select == 'var_lang') $ret .= "\n<select name='$nom_select' class='verdana1' style='background-color: $couleur_foncee; color: white;' onChange=\"document.location.href='". $lien . $amp."$nom_select='+this.options[this.selectedIndex].value\">\n";
else $ret .= "\n<select name='$nom_select' class='fondl'>\n";
sort($langues);
while (list(, $l) = each ($langues)) {
if ($l == $default) {
$selected = ' selected';
}
else {
$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";
}
$ret .= "</select>\n";
if ($nom_select == 'var_lang') $ret .= "<noscript><INPUT TYPE='submit' NAME='Valider' VALUE='>>' class='verdana1' style='background-color: $couleur_foncee; color: white; height: 19px;'></noscript>";
else $ret .= "<INPUT TYPE='submit' NAME='Modifier' VALUE='"._T('bouton_modifier')."' CLASS='fondo'>";
$ret .= "</form>";
return $ret;
}
// menu dans l'espace public
function gerer_menu_langues() {
global $var_lang;
if ($var_lang) {
if (changer_langue($var_lang)) {
spip_setcookie('spip_lang', $var_lang, time() + 24 * 3600);
}
}
}
//
// Selection de langue haut niveau
//
function utiliser_langue_site() {
changer_langue($GLOBALS['langue_site']);
}
function utiliser_langue_visiteur() {
if (!regler_langue_navigateur())
utiliser_langue_site();
if ($GLOBALS['auteur_session']['lang'])
changer_langue($GLOBALS['auteur_session']['lang']);
}
//
// Initialisation
//
function init_langues() {
global $all_langs, $flag_ecrire, $langue_site, $cache_lang, $cache_lang_modifs;
global $pile_langues, $lang_typo, $lang_dir, $dir_ecrire;
$all_langs = lire_meta('langues_proposees');
$langue_site = lire_meta('langue_site');
$cache_lang = array();
$cache_lang_modifs = array();
$pile_langues = array();
$lang_typo = '';
$lang_dir = '';
$toutes_langs = Array();
if (!$all_langs || !$langue_site || $flag_ecrire) {
if (!$d = @opendir($dir_ecrire.'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 faire
if ($all_langs2 != $all_langs) {
$all_langs = $all_langs2;
if (!$langue_site) {
// Initialisation : le francais par defaut, sinon la premiere langue trouvee
if (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")) {
ecrire_meta('langues_proposees', $all_langs);
ecrire_metas();
}
}
}
init_codes_langues();
}
init_langues();
utiliser_langue_site();
//
// array_push et array_pop pour php3 (a virer si on n'a pas besoin de la compatibilite php3
// et a passer dans inc_version si on a besoin de ces fonctions ailleurs qu'ici)
//
/*
* Avertissement : Cette librairie de fonctions PHP est distribuee avec l'espoir
* qu'elle sera utile, mais elle l'est SANS AUCUNE GARANTIE; sans meme la garantie de
* COMMERCIALISATION ou d'UTILITE POUR UN BUT QUELCONQUE.
* Elle est librement redistribuable tant que la presente licence, ainsi que les credits des
* auteurs respectifs de chaque fonctions sont laisses ensembles.
* En aucun cas, Nexen.net ne pourra etre tenu responsable de quelques consequences que ce soit
* de l'utilisation ou la mesutilisation de ces fonctions PHP.
*/
/****
* Titre : array_push() et array_pop() pour PHP3
* Auteur : Cedric Fronteau
* Email : charlie@nexen.net
* Url :
* Description : Implementation de array_push() et array_pop pour PHP3
****/
// Le code qui suit est encore un peu trop leger. Y a personne pour le coder en Java (ou en Flash) ?
function php3_array_push(&$stack,$value){
if (!is_array($stack))
return FALSE;
end($stack);
do {
$k = key($stack);
if (is_long($k));
break;
} while(prev($stack));
if (is_long($k))
$stack[$k+1] = $value;
else
$stack[0] = $value;
return count($stack);
}
function php3_array_pop(&$stack){
if (!is_array($stack) || count($stack) == 0)
return NULL;
end($stack);
$v = current($stack);
$k = key($stack);
unset($stack[$k]);
return $v;
}
?>