0

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?

  • The important part of the question is who his supposed to do the localization in your case – Mark Kaplun Feb 7 '16 at 13:51
  • @MarkKaplun what do you mean? I'm localizing through .po files – Mark Feb 7 '16 at 14:42
  • Then what is in the DB? – Mark Kaplun Feb 7 '16 at 14:45
  • The rest of strings that i need to localize....... – Mark Feb 7 '16 at 22:18
0

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.

  • Thanks Remy but these solutions are all custom...i was asking if there's some way to use any Wordpress original function to achieve that without having to write my own structure. Your 3rd option moreover does not apply as i need to keep those strings in the db. – Mark Feb 9 '16 at 20:21
  • Ok, have not seen something like that yet. – Remy Feb 11 '16 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.