Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using lang from database
  • Hi,

    I'm a new Fuel user, moved from Kohana.
    I cannot find how I can configure Fuel to use the Lang_Db class, so I can use a language table from MySQL.

    I've tried some different settings in config.php for the option always_load:
    'language'  => array('db'=>true),
    'language'  => array('db'=>'db'),
    'language'  => array('filename'=>'db'),
    'language'  => array('file'=>'db')

    They all didn't work and always load the Lang_Php class.
    What do I wrong?
  • The structure of the language table, and how to define which table contains your lang strings, is documented in the introduction of the lang class.

    Selecting the backend for Lang works the same as with all other Fuel classes that have this functionality like Config of View: through the extension.

    So instead of

    \Lang::load('test');

    you would use

    \Lang::load('test.db');

    Same is true for always load, either

    'language'  => array('this.db', 'that.db')

    or

    'language'  => array('this.db' => 'thisgroup', 'that.db' => 'thatgroup')

  • I can't use language in db. The document just said about create lang table and define table name. No where say about how to use it.

    My table:
    ----------------------------------------------

    identifier | language | lang | hash

    fslang_test | en | Hello, test | fslang_test

    fslang_test | th | Hello this is test. | fslang_test
    ------------------------------------------------

    Table name ws_lang (ws_ is prefix)

    My config:
    'lang' => array(
            /*
             * Name of the table used by the Lang_Db driver
             */
            'table_name' => 'lang',
        ),

    My controller:
    \Lang::load('lang.db');
    echo \Lang::get('fslang_test').'<br>';

    Nothing come out. Just null.

    I have no idea what is identifier and hash for?
    I don't know how to use it I follow this topic and another topic but none of them work.
  •  hello vee, yes, unfortunately there's no instruction. the first thing is that the translation lines will not be saved as plain text, but as a serialized data.

    to understand that consider following example:

    //load translations from APPPATH/lang/<lang-code>/fslang_test.php into a group named fslang_test
    \Lang::load('fslang_test', 'fslang_test');
    // save ALL translation of group 'fslang_test' into a DB with fslang_test as identifier
    \Lang::save('fslang_test.db', 'fslang_test');
    //then try to load from db...
    \Lang::load('fslang_test.db', 'fslang_test');
    echo \Lang::get('fslang_test.fslang_test');



  • Yes! Thank you @vLight
  • There is indeed no instruction on how to add language data to the table. That should be added.

    Anyone up for a pull request?
  • @Harro, i've already posted an issue, but, honestly, my understanting of that particular topic isn't at 100% (i still do not know what 'hash-column' stands for and why/how it is important) and my english isn't well either.

    P.S. I made a task for converting all existing PHP-lang files (assuming they located in APPPATH/lang/<code>/) for all available languages (folders with lang-code in APPPATH/lang). Running task without any parameter will try to convert all located lang-files.  
  • I just found that hash column is auto generate by \Lang class.

    You guys are awesome @Harro, @vLight. Thanl you.
  • The problem with some RDBMS engines is that an UPDATE returns zero if no rows are updated (for example MySQL).

    That means you can't check whether the update failed, or the update was a success but nothing had changed. And Lang needs to know the difference, otherwise it can't insert new language strings. This is what the hash is for, it will make sure an UPDATE query always updates the row.

Howdy, Stranger!

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

In this Discussion