Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Multi-language support
  • I have in app/lang:
    en(folder)
    english.php(file):
    return array(
        'hello' => 'Hello :name',
        'something'=> 'something :name!',
        'test'=> array('hello' => 'Hello', 'something' => 'Plop') // Group
    );
    en2(folder)
    english2.php(file, same as english.php):
    return array(
        'hello' => 'Hello :name',
        'something'=> 'something :name!',
        'test'=> array('hello' => 'Hello', 'something' => 'Plop') // Group
    );
    In my Controller:
                    Lang::load('english', 'en');
                    echo Lang::get('en.test.something');
                    Lang::load('english2', 'en2');
                    echo Lang::get('en2.test.something');
    I must have as result:
    Plop
    Plop
    But I have:
    Plop
    So this lines don't get anything from app/lang/en2/english2.php:
                    Lang::load('english2', 'en2');
                    echo Lang::get('en2.test.something');
    I have just seen in my config.php this:
    'always_load'  => array(
    'language'  => array(),
    ),
    If this helps, how can I use it? 
    I must get as result: 
    Plop
    Plop
    Not:
    only one of them(Plop)
  • And what does your view look like?

    You are echo'ing data in your controller, I don't see a view being used anywhere?

    When I use your exact code, I get "PlopPlop" echo'd, so it works fine here.
  • There isn't any view. I am sorry. I have already edited this topic
  • Did you check whether you language file actually is being loaded? You can dump all loaded lang-lines using something like ```\Debug::dump(\Lang::$lines)```. If you don't find anything for the 'en2' key, then your file isn't loaded in the first place (you can also check if its being loaded if you add something like ```logger(\Fuel::L_DEBUG, __FILE__);``` before the return statement in your lang file).

    Second thing worth checking might be that you are actually having a lang-line for ```en2.test.something``` by changing its value to something different than "Plop", too. It helps in finding it if there's different values to look for ;)
  • I change in my config.php:
    'language'           => 'some name', // Default language
    'language_fallback'  => array('en', 'en2'), // Fallback language when file isn't available for default language
    I managed to do it but this is not the right way.
  • Ah, I missed en and en2 are different languages.

    There is only one language active at any given point, and you indeed have a language to fall back to.

    Your fallback language should only be one, and should be your default one, the language file set that is 100% complete. It's a bit pointless to have multiple ones, if 'en' is complete, 'en2' will never be used. But it will be loaded, so it's only wasting processing time and memory.
  • So, I want to have two languages in php type. How can I make this?
  • I don't understand your question.

    Normally you develop the application in one language, your own language. The language files for this language are (or should be) always complete, and you use this language as the fallback.

    The primary language it the default the end-user of the application will see. This could be the same language, it could be something else. Your application could also contain logic to allow the end-user to change it, to select a preference.

    When making translations you copy the fallback language (which should be complete) to a second language folder, and you start translating.

Howdy, Stranger!

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

In this Discussion