CGridview - filtering on translated values

The all common CGridview relation/filter topic once again. How do you define a filter for translated values?

Scenario: Gridview where the user can search through several fields in his/her own language. Values in the DB are in English. Translation provided through Yii messages files.

function t in module MYMODULE delivers a translation for the data extracted (TEXTVALUE) from the database.

So in case if ‘TEXTVALUE’ would be ‘fruits’, it would display a translated value for ‘fruits’ in the gridview if the view language of the user is, say language NL.


‘columns’ => array(







How can I make the filter/model/gridview code to use the translated input in the filter, ‘untranslated’ it to search the db, and filter the gridview accordingly (all without the use of the dropdown filter function).

So short example:

Gridview with 15 rows show, 1 column. Column contains a translated version of the contents of the DB (in this example. Source language is UK, target language is NL). User sees the values in the gridview in NL (translated), user wants to filter the contents by putting in a Dutch (NL) searchword in the filter.

How do I code compare or ‘search’ function of the model?

The example below works fine with English words, but not Dutch search words (obviously).

$criteria->compare(‘TEXTVALUE’, $this->TEXTVALUE, true);

How can I call the untranslate function on the filter so that it searches correctly in the db?

No one has a clue? I could really use some fresh ideas on this one:)

I don’t see any way how would you search in the db… when you wrote that the translation are from the text files

Well, all values in the database have a translation available.

So say I have three values in the database: red, blue and white (and their Dutch translations: rood, blauw and wit).

So the gridview contains three rows with data and in the column with color, it shows the translation of the database values.

When using the gridfilter, I want to basically want to interpret the text to see if it matches (partially) with my translation by first translating the values from the database and then do a search/compare on them.

So say I want to search for Blauw (blue), I’d put in bla, which would then be match with the translated values from the database (rood, blauw, wit instead of red, blue and white).

It’d be nice if it is possible of course, but if it’s not possible, I’ll do it the ‘ugly’ way (dropdownbox as a filter with the translations).

The other option is to provide a translation database table I guess. And instead of looking at the translation text file, just pulling the translations out of the database for these values. But then again, it’s extra queries to be performed for a rather mundane ‘result’.

I guess I’m hoping for a different approach or something :)

You can always write your own components or use one with client-side sorting and filtering (there should be at least few available) :)

you can also move translation to database layer (some other table with translations and join it with main table)

Default CGridView works only on database level - sorting and filtering is translated to SQL query and data returned by that query is rendered as table. There is no way you can filter or sort by values translated the way you do it…