IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Problème classe langage


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Par défaut Problème classe langage
    Bonjour,

    J'ai développé une classe (qui aura + tard une extension MySQL) pour gérer plusieurs langues d'un site.

    J'arrive au bout mais ne comprends pas une chose:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    // echo simple title
    echo PROGVIGADS_Welcome."<br/>";
    echo PROGVIGADS_my_location.PROGVIGADS_location."<br/>";
    echo PROGVIGADS_Class_version.PROGVIGADS_Version;
    ///////or you can do it with site setting or user profile load it with mysql and change site language
    // like $lang->load_language("fa");
    // or another way 
    
    
    if(isset($_GET['lang'])) 
    {
    	switch($_GET['lang']) 
    	{
    		case "ir":
    					$lang->set_language("fa");
    					break;
    		case "en":
    					$lang->set_language("en") ;
    					break;
    		case "tr":
    					$lang->set_language("tr") ;
    					break;
    	}
    }
    
    ?>
    <br />
    <br />
    
    <a href="index.php?lang=en">
    	<img src="images/us.gif" />
    </a> | 
    <a href="index.php?lang=ir">
    	<img src="images/ir.gif" /> 
    </a> |
    <a href="index.php?lang=tr"> 
    	<img src="images/tr.gif" />
    </a>
    <br />
    <a href="http://progvig.ir">Progvig.ir</a>
    
    <?php
    // echo simple title
    echo PROGVIGADS_Welcome."<br/>";
    echo PROGVIGADS_my_location.PROGVIGADS_location."<br/>";
    echo PROGVIGADS_Class_version.PROGVIGADS_Version;
    ///////or you can do it with site setting or user profile load it with mysql and change site language
    // like $lang->load_language("fa");
    // or another way 
    ?>
    Le 1er pavé en gras était dans l'original que j'ai reçu et adapté à outrance.
    Dans ce cas, cela ne fonctionne pas.
    Mais si je déplace vers le bas ce même coding, cela fonctionne...
    Mais pourquoi pas - pouquoi OK ?

    Voici mon index.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
     
    <?php
     
    session_start();
    // register session to change language
    session_register("mylang");
    //include language class
    require_once $_SERVER['DOCUMENT_ROOT'] . '/class/classlang.php';
     
    $lang = new Language();
     
     
    // echo simple title
    echo PROGVIGADS_Welcome."<br/>";
    echo PROGVIGADS_my_location.PROGVIGADS_location."<br/>";
    echo PROGVIGADS_Class_version.PROGVIGADS_Version;
    ///////or you can do it with site setting or user profile load it with mysql and change site language
    // like $lang->load_language("fa");
    // or another way 
     
     
    if(isset($_GET['lang'])) 
    {
    	switch($_GET['lang']) 
    	{
    		case "ir":
    					$lang->set_language("fa");
    					break;
    		case "en":
    					$lang->set_language("en") ;
    					break;
    		case "tr":
    					$lang->set_language("tr") ;
    					break;
    	}
    }
     
    ?>
    <br />
    <br />
     
    <a href="index.php?lang=en">
    	<img src="images/us.gif" />
    </a> | 
    <a href="index.php?lang=ir">
    	<img src="images/ir.gif" /> 
    </a> |
    <a href="index.php?lang=tr"> 
    	<img src="images/tr.gif" />
    </a>
    <br />
    <a href="http://progvig.ir">Progvig.ir</a>
     
    <?php
    // echo simple title
    echo PROGVIGADS_Welcome."<br/>";
    echo PROGVIGADS_my_location.PROGVIGADS_location."<br/>";
    echo PROGVIGADS_Class_version.PROGVIGADS_Version;
    ///////or you can do it with site setting or user profile load it with mysql and change site language
    // like $lang->load_language("fa");
    // or another way 
    ?>
    ma classe Langue

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
     
    <?php
    class Language
    {	private $language, $allowed = array("en" , "fa" , "tr") ;
    	private $default = "en" ;
     
    /**
    *
    *   Constructor
    *	===========
    **/
    	function __construct()
    	{	if (isset($_SESSION['mylang'])) 
    			$this->language = $_SESSION['mylang'] ;
    		else
    			{	$_SESSION['mylang'] = $this->default ;
    				$this->set_language($this->default) ;
    			}
    	}
     
    /**
    *
    *   Destructor
    *	==========
    **/
    	function __destruct()
    	{	user_error("destructor",E_USER_NOTICE) ;
    //		unset($_SESSION['mylang']) ;
    	}
     
    /**
    *
    *   set_language
    *	============
    **/
    	function set_language($lang) 
    	{	if (in_array($lang,$this->allowed) )
    			{	user_error("set_language[".$lang."]",E_USER_NOTICE) ;
    				$this->language = $_SESSION['mylang'] = $lang ;	
    			}
    		else
    			user_error("Bad language[".$lang."]" , E_USER_ERROR) ;
    		$this->load_language();	
    	}
     
    /**
    *
    *   set_default
    *	===========
    **/
    	function set_default($lang) 
    	{	if (in_array($lang,$this->allowed) )
    			{	user_error("set_language[".$lang."]",E_USER_NOTICE) ;
    				$this->default = $lang ;	
    			}
    		else
    			user_error("Bad language[".$lang."]" , E_USER_ERROR) ;
    		$this->load_language();	
    	}
     
    /**
    *
    *   get_language
    *	============
    **/
    	function get_language() 
    	{	user_error("get_language[".$this->language."]",E_USER_NOTICE) ;
    		return($this->language) ;  	}
     
    /**
    *
    *   load_language
    *	=============
    **/
    	function load_language() 
    	{	user_error("load_language[".$this->language."]",E_USER_NOTICE) ;
     
    		$lang = $this->get_language() ;
    		switch ($lang)
    		 {	case "fa":	require_once  $_SERVER['DOCUMENT_ROOT'] . '/class/lang-fa.class.php';
    						break;
     
    			case "en":	require_once $_SERVER['DOCUMENT_ROOT'] . '/class/lang-en.class.php';
    						break;
     
    			case "tr":	require_once $_SERVER['DOCUMENT_ROOT'] . '/class/lang-tr.class.php';
    						break;
     
    			default	:	user_error("Bad CodeLanguage[".$lang."]" , E_USERuERROR) ;
    		}
    		$this->language = lang ;
    	}
    	// end language function loading
     
    }
    ?>
    Et la classe contenant les constantes du code langue "en", les autres sont identiques:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <?php 
    // define words
    define("PROGVIGADS_Class_version","Class Version is :");
    define("PROGVIGADS_Version","1.0.0");
    define("PROGVIGADS_Welcome","Welcome To my site");
    define("PROGVIGADS_location","America");
    define("PROGVIGADS_my_location","My location is : ");
    ?>
    Dans le cas ou cela ne fonctionne pas, j'ai à l'écran:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    PROGVIGADS_Welcome
    PROGVIGADS_my_locationPROGVIGADS_location
    PROGVIGADS_Class_versionPROGVIGADS_Version
     
    | |
    et dans le log PHP:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_Welcome - assumed 'PROGVIGADS_Welcome' in F:\WebSites\langue\index.php on line 13
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_my_location - assumed 'PROGVIGADS_my_location' in F:\WebSites\langue\index.php on line 14
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_location - assumed 'PROGVIGADS_location' in F:\WebSites\langue\index.php on line 14
    
    [19-Jan-2011 14:23:49] PHP Notice: [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_Welcome - assumed 'PROGVIGADS_Welcome' in F:\WebSites\langue\index.php on line 13
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_my_location - assumed 'PROGVIGADS_my_location' in F:\WebSites\langue\index.php on line 14
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_location - assumed 'PROGVIGADS_location' in F:\WebSites\langue\index.php on line 14
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_Class_version - assumed 'PROGVIGADS_Class_version' in F:\WebSites\langue\index.php on line 15
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_Version - assumed 'PROGVIGADS_Version' in F:\WebSites\langue\index.php on line 15
    
    [19-Jan-2011 14:23:49] PHP Notice:  set_language[en] in F:\WebSites\langue\class\classlang.php on line 37
    
    [19-Jan-2011 14:23:49] PHP Notice:  load_language[en] in F:\WebSites\langue\class\classlang.php on line 75
    
    [19-Jan-2011 14:23:49] PHP Notice:  get_language[en] in F:\WebSites\langue\class\classlang.php on line 66
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant lang - assumed 'lang' in F:\WebSites\langue\class\classlang.php on line 90
    
    [19-Jan-2011 14:23:49] PHP Notice:  destructor in F:\WebSites\langue\class\classlang.php on line 26
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant PROGVIGADS_Version - assumed 'PROGVIGADS_Version' in F:\WebSites\langue\index.php on line 15
    
    [19-Jan-2011 14:23:49] PHP Notice:  set_language[en] in F:\WebSites\langue\class\classlang.php on line 37
    
    [19-Jan-2011 14:23:49] PHP Notice:  load_language[en] in F:\WebSites\langue\class\classlang.php on line 75
    
    [19-Jan-2011 14:23:49] PHP Notice:  get_language[en] in F:\WebSites\langue\class\classlang.php on line 66
    
    [19-Jan-2011 14:23:49] PHP Notice:  Use of undefined constant lang - assumed 'lang' in F:\WebSites\langue\class\classlang.php on line 90
    
    [19-Jan-2011 14:23:49] PHP Notice:  destructor in F:\WebSites\langue\class\classlang.php on line 26
    
    Et parfois, j'ai que ces constantes sont déjà définies !!
    Voilà mon soucis, pas grand-chose je me doute, mais une idée lumineuse pourrait jaillir de l'un d'entre vous....

    Merci à lui

  2. #2
    Membre expérimenté

    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    191
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 191
    Par défaut
    Use of undefined constant PROGVIGADS_Welcome
    ceci indique que tu utilise une constante non déclarée par conséquent le fichier de déclaration n'est pas inclus avant un appel de constante, a toi de bien placer tes inclusions

Discussions similaires

  1. problème classe managée.
    Par adicor dans le forum MFC
    Réponses: 5
    Dernier message: 08/05/2006, 21h19
  2. problème class vector
    Par Pe04 dans le forum SL & STL
    Réponses: 2
    Dernier message: 27/02/2006, 10h45
  3. Problème class
    Par Anduriel dans le forum Langage
    Réponses: 19
    Dernier message: 28/01/2006, 19h34
  4. problème classes templates...
    Par youp_db dans le forum C++
    Réponses: 3
    Dernier message: 02/11/2005, 13h04
  5. problème classe et fonction
    Par zmatz dans le forum C++
    Réponses: 14
    Dernier message: 19/10/2005, 21h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo