Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
best approach for i18n
  • I am creating a multilangual webpage and it is hard to find best way to design database and use it easily in application so.. here is my way but it looks ugly (copy paste of model file fragments): model/category.php
    protected static $_has_many = array('i18n_category');
    protected static $_properties = array(
      'id',
      'uri',
     );
    
    model/i18n/category.php
    protected static $_belongs_to = array('category', 'lang');
    protected static $_properties = array(
      'id',
      'category_id',
      'lang_id',
      'title',
     );
    
    model/lang.php
    protected static $_properties = array(
      'id',
      'slug',
      'title',
      'default',
     );
    
    so if I want to echo all category titles in "active" language I write this
    $categories = Model_Category::find('all');
    foreach($categories as $category)
      foreach($category->i18n_category as $i)
        echo $i->lang->slug == LANG ? $i->title : '';
    

    *LANG is the constant and contains "active" language It is very bad way to do this
    please help me to find out better approach
  • In my opinion, I think you are going the wrong way. FuelPHP is already has built-in support for i18n via
    Lang class and many other places. It is more convenient and easy. Look at the Lang class for more info.

Howdy, Stranger!

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

In this Discussion