0
votes

I am currently developing a website in PHP and I decided to go with gettext to manage the translations. I set up a nice Pootle server so that I can easily manage the translations and a bash script that runs with cron that extracts all of the values from the PHP files to be translated and creates the .pot translation template file.

So far, so good. However, I just remembered that part of the text of the site is stored in a database. Let's call it "products" for simplicity. I want the product description, name, and a few other fields to be translatable, but it would be great if I could have a centralized way to translate them without having to create a separate interface just to translate the database entries. Since Pootle is already set up, it would be nice to be able to use that.

I thought of two solutions:

  1. Forget using a database and use only PHP arrays
  2. Write a script that will extract all of the values from the database and generate a file that will then be scanned by the aforementioned bash script and add the values to the pot file, and another script that will run just after the bash script to re-update all of the values in the DB.

Neither of these solutions really seem to be ideal. The first one would be easy to set up and easy to use with Pootle, but I lose all flexibility that comes with using a DBMS and I would have to import the entire array every time I want to use it. Loss of functionality isn't really that bad, because I (currently) am not performing any advanced calculations on the rows, basically just SELECTs and that's it. The second one, could work, but would take significantly more planning (and coding) to set up correctly.

Are there any other ways that I'm missing that would give me the flexibility of a database, but allow me to easily translate it in a centralized place along with the rest of the site, like Pootle?

1

1 Answers

0
votes

You can generate pot/po files directly from the database and feed them into Pootle then. Then you would be able to use gettext functions directly on values returned from database.

As an example, you can look at phpMyAdmin, where we use similar approach to translate structured text file.