Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Lang files -> Need help !
  • Hi everybody, here is my problem : 

    I want to use Lang files. I modify URI as explained here :

    So I've got a hierarchy which look likes :

    lang/en/myenlangfile.php
    lang/fr/myfrlangfile.php

    But I'm just testing my library functions with unit tests and some of these functions call the lang file. So there is no lang detection.

    I load my lang file like this : Lang::load('hierarchy','hierarchy');

    I tried var_dump('hierarchy'); and it returns an empty array.

    But my hierarchy lang file contains an array which is not empty.

    Have anyone got a solution?

    Thanks for any help.
  • Do you have en configured as the default Lang?

    I'm not sure you can var_dump('hierarchy'). I think you would need to do a var_dump(Lang::get('hierarchy')).

    Or just try to use one of your values like  Lang::get('hierarchy.value');
  • Sorry, i made a mistake, i used var_dump(Lang::get('hierarchy')) which returned an empty array and i did var_dump(Lang::get('hierarchy.value') which returned null.

    How to configure en as the default Lang please?
  • Unit tests run at the command line, so there is no URI, and no language to get from it. The method described in the blog post only works for interactive requests.

    You will have to make sure the default language is set correctly in your app/config/config.php (either to 'en' or 'fr').
  • Yes i did :

    return array(
        'language'           => 'fr', // Default language
        'language_fallback'  => 'en', // Fallback language when file isn't available for default language
        'locale'             => 'en_US', // PHP set_locale() setting, null to not set
        'locales'            => array(
            'en' => 'en_US',
            'fr' => 'fr_FR'
        ),
  • I followed this tutorial but also not working :

  • Where do you load the language file and do the var_dump()?

    If your default language is 'fr', it should load app/lang/fr/... without problems.
  • I load the language file in my library's constructor.
    The var_dump() is done in my library's function.

    in app/lang/fr/... there is nothing because I would like to use my lang file in a module which look likes modules/hierarchy/lang/fr/... and there is also a file in modules/hierarchy/lang/en/...
  • Ah, you didn't say that before.

    You can only load a file (language, config, etc) from a module in your in the "module context", i.e. if the request resolves to a module controller.

    It is considered bad design to do cross module calls, modules should be self contained and not be tightly coupled to something else.

    So if you need to fetch something from a module, do an HMVC request to a controller in that module that returns the information you need.
  • I found the solution. Thank you guys.
  • Perhaps you can share your solution, so it might help others having the same question?
  • I can't because that's not me who found the solution but another member of the company, sorry.

Howdy, Stranger!

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

In this Discussion