Translating database tables using gettext

Can I use gettext to translate the contents of a database table?

For example, I have several database tables that never change content, for example. a table that links the country identifier ("fr", "de", ...) with the names of countries ("France", "Germany", ...), where the names of countries are written in English. I could add additional table columns to provide translation of country names in different languages, but I was wondering if it is possible to somehow use gettext to translate country names.

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

+4
source share
2 answers

You should just use

 string gettext ( string $message ) 

where $message is your country name from db.

+1
source

This has not been tested, but have you tried to add countries to the database with __(); markup __(); ? Therefore, the contents of the table are as follows:

 __('Germany'); 

Since gettext translates the same lines, you now simply open the .po file of the language you want to translate into a text editor and add:

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

You can use any file name or string (this works for me, my gettext is here )

0
source

Source: https://habr.com/ru/post/1495057/


All Articles