Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
lang class
  • I still have a problem in the use of language file with fuephp. I followed the class documentation lang but its not working.
    i declare in my base controller:
    public function before()
     {
     
     // appel au fichier langue.
     // methode before
    Config::set('language','fr');
    Lang::load('exemple','test');
     parent::before();
     $current_user =null;
    // verifier si l'utilisateur est déja connecté 
    if(Warden::check())
    ....
    }
    in my view  i do a simple echo Lang::get('test.1')
    <?php 

    echo Lang::get('test.1'); ?>


    helppppp , it's urgentttttttt
  • What is not working?

    And what does your 'exemple.php' language file contain? If you do

    Lang::get('test.1');

    it shoud contain

    return array(
        '1' => 'some text here',
    );
  • in the folder "lang"  i create a new folder "fr" where i place my file" exemple.php"
    exemple.php is like that :
    <?php
    return array(
        '1' => 'identifiant',
        '2' => 'mot de passe',
        
    );
    ?>

  • Looks fine. And the problem is?
  • wen i do " echo Lang::get('test.1')"; 
    it's return NUll NOT THE VALUE  'identifiant'
  • Let me guess: it picks the wrong language.

    In FuelPHP, Views by default are lazy rendered. This means a View object is only converted to HTML when it's being send to the browser. This happens long after the Request has finished, in your index.php.

    Now, language settings are set per Request, to make sure that changes in HMVC calls don't alter the language on the parent request. This means that if you change the language in your controller, by the time the View renders the language has been reverted to the value from before the request started.

    Bottom line, make sure your config file contains the correct default language. Since you're using 'fr' hardcoded, better do that in your config file.

    If you want to set a custom language, for example based on a session value, a cookie value, or a URI segment, you will have to do that before the Request starts. You can do that in your app bootstrap, after the Fuel init call, or in a _init() method of a class that you define as always_load in your config.

  • thanks thats work, i m happyyy

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion