Skip to content

zend framework 2 - translation on steroids - some thoughts

The following lines are loud thoughts so far. I will give it a try and implement a fitting module for that. But so far, it is really just an idea.

You started your zend framework 2 translation by using the official translation guide for zend framework 2 and it was running fine with some words.
But then, you started working agile, using git flow and doing this by using multiple branches. It turned out that you will get a lot of merge conflicts (also on git) with your translation files if something had changed on your develop branch and on your feature branch. This results in high maintenance costs.

So what to do?
Here is my basic idea. Decouple the translation file from your code.

  • First of all, you want to shift from file based to database based translation.
  • After that, you reduce the usage of the database and add caching

Shift from file based to database based translation

  • Create a database with the name like "translation"
  • Inside this database, create a table called "keys" with the columns "id", "key_name" (or "name") and "created_at"
  • Inside this database, create as many "language" tables as you want
  • Each "language" table has the following columns "id", "key_id", "key_value" (or "value") and "created_at"
  • After that, create a basic import that inserts all names in the table "keys" and all values in the fitting "language" table
  • Next, you have to create an "translation adminstration" frontend to maintain the existing "translation keys" with its fitting "translation values" according to the right language.
  • Finally, you have to overwrite the existing view helper with your own, database driven, one

Reduce the usage of the database and add caching