Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
set a language and load a language file from a template controller
  • class Controller_Index extends Controller_Template { public $template = 'base'; public function _init()
    {
    Config::set('language', 'de');
    Lang::load('index'); }
    ......
    } Does not work, if I change these parameters in the config file instead then it works. any idea what I am doing wrong??
    also if I set only 'language' => array('index;) in the config file then the english file is loaded not the german one... I think this is related to the problem described above.
    thanks for your help
  • I can not reproduce this, your code works perfectly here. Are you sure your language file can be found? If not it will fall back to english.
  • Now I am completely at a loss...any idea where I should even start looking?
  • Open core/classes/lang.php, find where $langconf is set in the load() method, and Debug::dump($langconf). If the answer is 'de' ( after using Config::set('language', 'de') ), then the issue is that the language file isn't found. If the language selected is correct, do a Debug::dump($p) inside the foreach loop under that, to see if the file is found. it is app/lang/de/index.php ? and your webserver has rights to read it? I have a feeling you'll have to look in that direction. Did you check your logs for include notices?
  • thanks for the quick reply, i have done what you have recommended and everything seems to be ok ( at least from what i can tell)
    Debug::dump($langconf). Variable #1:
    array(1) {
    [0]=>
    string(2) "de"
    } Debug::dump($p). COREPATH/classes/lang.php @ line: 46
    Variable #1:
    string(59) "(...)Fuel/fuel/app/lang/de/index.php" as to the logs they show nothing about include.
    I doubt the issue is finding the language file because if it is loaded from the config file it works fine it is just when i load it from the controller that it doesnt work..
    any ideas where I should be looking for next?
    thank you for your help
  • This all looks ok, so how do you determine the load doesn't work from your controller? Your code was incomplete at that point...
  • When I do :
    echo Config::get('language'); inside the controller 's_init() i do get "de" however : echo Lang::line('index.welcome.h1'); gives nothing. mind you if the language file is loaded through the config file I get an output out of echo Lang::line('index.welcome.h1'); Though it is in English..( unless i specify "de" value for the "language" key in the config file)
  • Can you post your controller and language file on http://scrp.at/, so I can use it to test here? I can't reproduce the issue...
  • Hi there,
    here are the two : http://scrp.at/6n the "echo Config::get('language')" returns "de" as expected the "echo Lang::line('index.welcome.h1')" returns nothing Thank you very much for your help. I have been stuck on this with no headway
  • You're confused to how Fuel deals with internal array storage. The key hierarchy is flattened to a dot-separated string. So if you have an array like this:
    return array(
        'one' => array(
            'two' => 'three'
        )
    );
    
    You'll end up with a key called "one.two", which has the value "three". If you load this (could be a config file, or a language file), it will be loaded as such. So, if this array is in the language file "filename",
    Lang::load('filename');
    
    will load it as such. Which means you retrieve it by using
    Lang::line('one.two');
    
    you will retrieve your string. If you want it to be prefixed, you will have to load it as such:
    // load it with the prefix equal to the filename
    Lang::load('filename', true);
    
    // load it with a specific prefix
    Lang::load('filename', 'prefix');
    

    This is mentioned in the docs, but perhaps not clear enough. I'll see if I can add some clarification.
  • Thank you very much for your patience and clarification.
    my apologizes, this is what happens when one works late at night without breaks!!
    The docs were clear enough it was my mistake :)

Howdy, Stranger!

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

In this Discussion