Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Loading lang file within a module.
  • Okay, so I'm trying to load a language file from a module in a module.  It is the same module, (Users)....   I'm able to load the lang file to the module from the app/lang/eng/login.php  but the language file in /modules/Users/lang/en/login.php won't load, so for now I am just using the app/lang one, but would prefer to load the modules lang file from the module itself.   Any help would be great.
  • I'm just wondering if it would be better to just do a main config file, and do 

    return array(
    'login' => array(
    'key' => 'value',
    ),
    'dashboard' => array(
    'key' => 'value',
    ));

    Assuming I understand the docs correctly, I could name this like main.php in the language file, auto load it and then call upon this lang file as needed like such login.key would out put the value of that key.  
  • HarroHarro
    Accepted Answer
    Fuel works with what we call request context.

    If the request loads an app controller, your in the app context, if the request loads a module controller, your in the module context, of that specific module.

    Only if you are in a module context, you can load module assets, like lang files, config, views, etc.

    If you call a module controller or class directly, you are still in the original context, so you can not load any module assets.

    So, as you say you try to load from a module, from what exactly? And how was that called?
  • For example I have a module for Users, with classes inside of that is the controller, view, model.  Then the Lang folder in the Users folder, with en, and inside that a file login.php.  I'm just unsure how I would load that from my controller within the module Users. 

    The controller that is in the module (login.php) is calling the lang file in the before(); by \Lang::load('login', null, null, true);  In which I have also just tried to do \Lang::load('login');


    I'm not to stressed about it, it is just a personal project of mine.  Just so that the main features that aren't going to be in the html (view) I can update easily with lang files, for spelling errors, or updating.  But it would be nice to know the correct way to load a module's lang file in that module.



    **Update**'

    Well I seem to be able to access the lang file now, maybe it was something I was doing wrong before I was using 

    \Messages::error(__('login.login-error'));  which I changed to
    \Messages::error(__('login-error'));  (Droping the login. part and it works.

    Which I understand now, as I have updated my lang file again in the module to;

    <?php

    return array(

        // Login lang files.
        'login' => array(
            'login-error' => 'We are truly sorry, it appears that you have entered a invaild username or password.  Please try again.' , // Error message displayed when incorrect login.
        ),

        );

    Which now will allow me to do \Messages::error(__('login.login-error')); 

    Thanks for your answer got me thinking :D  So in the end I was loading it correctly I was just calling on a array of options that wasn't there.  I needed to make login a array and the options to follow under it to make it login.key 
  • Cool, glad you have it sorted.

Howdy, Stranger!

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

In this Discussion