Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6818501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:11:10+00:00 2026-05-26T21:11:10+00:00

I’m having a problem getting the data from my database which I created to

  • 0

I’m having a problem getting the data from my database which I created to be completely multilingual, and I hope someone here can help me.

I’ve split up all my tables in 2 parts; the “universal” table (does not contain any text that needs to be translated) and the table which contains all the fields that need to be translated with their translations.

Example tables:

base_material
    id
    picture
base_material_i18n
    base_material_id
    localization_id
    name
    description
    review_status
    review_notes
localization
    id
    language_name

Query to get the translations (using English (en) as a fall-back language if there is no translation available):

SELECT o.id
     , o.type
     , o.code
     , o.position
     , ifnull(t.name,d.name) name
     , ifnull(t.description,d.description) description
  FROM base_material o
       INNER JOIN base_material_i18n d
               ON ( o.id=d.base_material_id)
       LEFT OUTER JOIN base_material_i18n t
                    ON ( d.base_material_id=t.base_material_id AND t.localization_id='nl' )
 WHERE d.localization_id='en'

My question is how I can automatically get those translations (with the fall-back language as in this query) attached to my model in Yii when I’m searching for the base_material objects? (This is only 1 example table, but almost all my tables (20+) are built in this way, so if possible I would be needing something flexible)

An example of an existing system using what I would need is Propel: http://propel.posterous.com/propel-gets-i18n-behavior-and-why-it-matters

Any ideas how to go about doing that? I’ve checked the existing Yii extensions regarding multilingual sites (like Multilingual Active Record), but they all use a different database design (general information+fall-back language in the main table, translations in the i18n table), and I’m not sure how to change those extensions to use my kind of DB model.

If someone knows of a way to change that existing extension so it can use my kind of DB scheme, then that would be absolutely brilliant and probably the best way to do this.

Edit: I’ve added a bounty because I still can’t find anything on how to let Propel work with Yii (there does exist an extension for Doctrine, but Doctrine doesn’t support this kind of DB model with translations either), nor any more information as to how to deal with this using an existing Yii extension or with scopes.

Edit: 98 times viewed but only 3 upvotes and 1 comment. I can’t help feeling like I’m doing something wrong here, be it in my question or application/database design; either that or my problem is just very unique (which would surprise me, as I don’t think my multilingual database design is that absurd ;-). So, if anyone knows of a better all-round solution for multilingual sites with Yii and/or Propel (apart from the current extensions which I really don’t like due to the duplication of text fields) or something similar, please let me know as well.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:11:11+00:00Added an answer on May 26, 2026 at 9:11 pm

    I am also looking for a generic solution to implement i18n into Yii models.
    Recently I chose a very similar database schema for a project like you.
    The only difference is, that I am not using a separate language table, I store the language information in the i18n table.

    The following solution is without a custom SQL statement, but I think this could be implemented with relation params, anyway, if you’re working with foreign key in your database (eg. MySQL InnoDB) gii will create relations between your base_material and base_material_i18n table, like

    class BaseMaterial extends CActiveRecord
    
    public function relations()
    {
        return array(
            'baseMaterialI18ns' => array(self::HAS_MANY, 'base_material_i18n', 'id'),
        );
    }
    
    
    
    class BaseMaterialI18n extends CActiveRecord
    
    public function relations()
    {
        return array(
            'baseMaterial' => array(self::BELONGS_TO, 'base_material', 'id'),
        );
    }
    

    Now you’d be able to access your translations by using the object notation for relations.

    $model = BaseMaterial::model()->with('baseMaterialI18ns')->findByPk(1);
    foreach($model->baseMaterialI18ns AS $translation) {
      if ($translation->language != "the language I need") continue:
      // do something with translation data ...
    }
    

    I thought about creating a behavior or base class for those models which would act a as helper for managing the translations – pseudo code:

    I18nActiveRecord extends CActiveRecord
    
    protected $_attributesI18n;
    
    // populate _attributesI18n on query ...
    
    public function __get($name) {
      if(isset($this->_attributesI18n['language_I_need'][$name]))
        return $this->_attributesI18n[$name];
      else if(isset($this->_attributesI18n['fallback_language'][$name]))
        return $this->_attributesI18n[$name];
      else 
        parent::__get();
    }
    

    CActiveRecord __get() source

    There is more work to be done to find the needed i18n record, also you could further limit the with() option to improve performance and reduce parsing on the PHP side.

    But there may be different use cases how to determine the value, e.g. all translations, translation or fallback, no fallback (empty value).
    Scenarios could be helpful here.

    PS: I would be up for a github project!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem getting access to a database which lives on a remote
Not having much luck getting help from any of you Spring gurus on here.
I am having a problem getting a list of fields from a query defined
I am getting a set of data from the database where the query produces
I'm having problems doing the Database example from PhoneGap. http://docs.phonegap.com/phonegap_storage_storage.md.html#openDatabase The Problem is, when
I'm having trouble accessing a dataset. I've pulled data from an Access database (successfully
I'm having real problems getting my head around classes, and am hoping someone can
I'm having trouble with retrieving queries from my SQL database. I can get the
I'm having a problem getting some data since I'm just starting to use LINQToEntities,
Currently i am having some problems with getting some data out of a DataTable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.