Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Creating a Model including trasnlation
  • Hi,

    I am developing a backend system for my applications. These applications will be multi-language.

    There are some database-based modules, like menu, pages which will also be multi-language.

    For these database I want to make the translation in database.

    My first plan is to do it in Models. Extend the ORM Model, and rewrite the getter to automatically return the appropriate string in the appropriate language, if there is any.
    The translations would be stored in a table, eg lang_menu

    Structure:
    ID;property;lang;value

    Hos would you do this?
  • What exactly do you want to translate?

    If this is about property labels (for fieldsets), that already supports i18n, just define the language key as the label.
  • Example:
    I have a table, called menu with the following structure:
    id;menu;title;link
    1;main;This is a title;http://example.com

    I want to translate the title field like this:
    lang_menu:
    id;object_id;lang;property;value
    1;1;de;title;Das ist ein titel

    I want to store the translations in database.

    Maybe this is not the best implementation.

    My other idea was to create a lang.php and return the queried data from database, and load it via Lang class.
  • Ah, ok.

    If this is not static data, I would create an i18n table:

    menu:
    id;menu;link

    menutitle:
    id;menu_id;language;title

    You can then define a condition on the relation which will act like a permanent filter on language. This does require that all language strings are present though.

    Alternatively you could use an EAV container, where 'language' is the 'key' column, and 'title' is the 'value' column. This will allow you to access all languages simultaneously, and pick an other on a new found.

    EAV creates a virtual table layout like:

    menu:
    id;menu;german;english;french;spanish;link

    // get a menu item
    $menuitem = Model_Menu::find(1);
    $title = isset($menuitem->german) ? $menuitem->german : $menuitem->english;

Howdy, Stranger!

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

In this Discussion