5
votes

Is it possible to use gettext to translate content of a database table?

For example, I have some database tables which never change content, e.g. a table which connects country id ("fr", "de",...) with country names ("France", "Germany",...) where country names are written in the English language. I could add additional table columns to provide translation of country names in various languages, but I was wondering, whether it is somehow possible to use gettext for translation of country names.

In case it matters, I use php and mark other fixed strings in the code with _('text-for-translation').

2
Do you have a solution?Jorge B.

2 Answers

0
votes

You should be able to just use

string gettext ( string $message )

where $message is your countryname from the db.

0
votes

This is untested, but have you tried to add the countries in the Database with the __(); markup? So the content of the table look like this:

__('Germany');

Since gettext translates the same strings anyway you now just open the .po file of the language you like to translate it to in an text editor and add:

#: index.php:1
msgid "Germany"
msgstr "Deutschland"

You can use any file name or line (that works for me, my Gettext is from here)