I have a table in my database with a name
field which content I want to translate. I am using lajax/translate-manager for that, and it's working fine. The problem comes when I want to sort the data in a GridView (or some other widget) by name
. When I query the database I specify name
as the sorting field, but it is done in the language it is stored (English). Then I use the Yii::t()
function in the GridView column to output the field and it gets translated, but obviously the ordering remains the same.
For example, in the table profession I have a row for which name
takes the value Accounting
, that in Spanish is Contabilidad
. If I show the table in Spanish that row should appear below than in English, and that is not happening.
Solution: I ended up fetching all records from the database as array, translating them with Yii::t and then putting it into an ArrayDataProvider. One more thing: to allow filtering I had also to check the correspondent columns of the array with PHP's function fnmatch.