Asur
Asur

Reputation: 387

Translating text direcly from DB using .po file

I've been having this problem for several days, after reseaching, I haven't found a solution.
I'm on a cakePHP 2.5.6 project, and I'm on the internationalization right now, everything seemed to work just fine, but I came across this issue:
In my DB I store several tags for my articles, the problem is that the name of the tag is given to me by a query directly from the DB, and printed using a foreach.
Here is my doubt, is there any way to translate those fields using my .po file?
I have thought some solutions but I'm trying to avoid them because I think they are just lame, such as create a new column in my tags table with the translated name in it.

Upvotes: 1

Views: 415

Answers (1)

drmonkeyninja
drmonkeyninja

Reputation: 8540

CakePHP's pot files are generated for hard-coded strings in template files and elsewhere in your app. Basically anything like __('Hello'), it doesn't work if you use variables like __($var) as it needs to know the string to generate the translation files.

If the content is coming from the database you need to look at translating the database content within the database as you've suggested. Rather than create a new set of columns on your tags table you should look into using CakePHP's Translate behaviour. Cake's Translate behaviour should do what you are looking for without you needing to re-invent the wheel.

Upvotes: 1

Related Questions