Localize strings from db

I'm using this method to translate strings in my template.

The question is, what if some strings are dynamically loaded from the db? How can i translate them? I've been googling for days and even asked on other communities but no solutions came out. Is there any trick / workaround to achieve this?

Topic l10n translation database Wordpress

Category Web


There are multiple ways to do this: 1. Add multiple columns to the table with the strings you have to localize. E.g. one column for German, one for English, and so on. And then get the string from the appropriate column. This is perfect if the number of languages stays more or less constant (you have to change the DB for every new language).
2. Add a translation table, with language, lockup and translation columns. So for every string you'll have multiple rows (one for each translation). This is good if the amount of languages changes/should be configurable.
3. Instead of the table solution, you could also lookup your string in a .po file.

But all of those need a little work and you have to have the option to change the way your db strings are read.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.