Ignore:
Timestamp:
Dec 4, 2010, 3:43:02 PM (13 years ago)
Author:
mistic100
Message:

gestion des langues, ajout de l'anglais, correction de bugs mineurs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PHP_Optimisateur/files/functions.php

    r7991 r7993  
    55\***************************************/
    66
     7// Affiche les textes
     8function l10n($code){
     9        global $Lang;
     10        if (isset($Lang[$code])) {
     11                $args = func_get_args();
     12                if (count($args) > 1) {
     13                        array_shift($args);
     14                        return vsprintf($Lang[$code], $args);
     15                } else {
     16                        return $Lang[$code];
     17                }
     18        } else {
     19                return $code;
     20        }
     21}
     22
     23// Trouve la langue
     24function GetLanguage(){
     25        // tableau avec les langues installées
     26        $dh = opendir('language');
     27        while ($file = readdir($dh)) {
     28                if ($file !== '.' && $file !== '..' && is_dir('language/'.$file))
     29                        $languages[] = $file;
     30        }
     31        closedir($dh);
     32       
     33        // recherche du paramètre get ou session, ou langue du navigateur
     34        if(isset($_GET['Lang']))
     35                $_SESSION['Lang'] = $_GET['Lang'];
     36        else if(!isset($_SESSION['Lang']) OR $_SESSION['Lang'] == NULL)
     37                $_SESSION['Lang'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
     38        if(!in_array($_SESSION['Lang'], $languages))
     39                $_SESSION['Lang'] = 'en';
     40
     41        return array('Lang' => $_SESSION['Lang'], 'languages' => $languages);
     42}
     43
    744// Supprime les accents et tous caractères non conforme
    845function delete_special_car($string) {
    946        global $renameORNOT;
    10         $search = array ('#[éèêë]#','#[ÊËÈÉ]#','#[àâäã]#','#[ÂÄÁÀ]#','#[îïíì]#','#[ÎÏÍÌ]#','#[ûùüú]#','#[ÛÙÚÜ]#','#[ôóòõö]#','#[ÓÒÖÔÕ]#',
    11                 '#[ç]#','#[Ç]#','#[ñ]#','#[Ñ]#','#[ýÿ]#','#[Ý]#','#[ \&\!\#\"\(\)\{\}\'\=\+\~]#','#[^a-zA-Z0-9_\.\-]#');
     47       
     48        $search = array ('#[éèêë]#','#[ÊËÈÉ]#','#[àâäã]#','#[ÂÄÁÀ]#','#[îïíì]#','#[ÎÏÍÌ]#','#[ûùüúµ]#','#[ÛÙÚÜ]#','#[ôóòõö]#','#[ÓÒÖÔÕ]#',
     49                '#[ç]#','#[Ç]#','#[ñ]#','#[Ñ]#','#[ýÿ]#','#[Ý]#','#[ \&\!\?\#\"\(\)\{\}\[\]\=\+\~\%]#','#[^a-zA-Z0-9_\.\-]#');
    1250        $replace = array ('e','E','a','A','i','I','u','U','o','O','c','C',',n','N','y','Y','_','');
    1351       
    14         return preg_replace($search, $replace, $string);
     52        if ($renameORNOT) {
     53                return preg_replace($search, $replace, $string);
     54        } else {
     55                return str_replace(array('%','$'), '_', $string);
     56        }
    1557}
    1658
     
    5092                $dh = opendir($dir);
    5193        } else {
    52                 exit;
     94                exit('Dossier inexistant');
    5395        }
    5496        while (($file = readdir($dh)) !== false ) {
     
    97139}
    98140
     141// Charge la configuration
     142function load_config() {
     143        $config = simplexml_load_file('config.xml');
     144        $config = XMLParse($config);
     145        $config = array_settype($config);
     146        return $config;
     147}
     148
    99149// Convertit les booléens, entiers et flotants d'un tableau de 'string'
    100150function array_settype($array) {
     
    120170// Booléen vers français ou texte
    121171function bool_to_string($bool, $just_echo=0) {
     172        global $Lang;
    122173        # $just_echo pour pouvoir afficher un booléen tel quel
    123174        if (is_bool($bool)) {
    124175                if ($bool) {
    125176                        if ($just_echo) return 'true';
    126                         else return 'oui';
     177                        else return l10n('yes');
    127178                } else {
    128179                        if ($just_echo) return 'false';
    129                         else return 'non';
     180                        else return l10n('no');
    130181                }
    131182        } else {
Note: See TracChangeset for help on using the changeset viewer.