Gedmo Translations in Symfony 4

Today I’ve had to install Gedmo Translations into a Symfony 4 app and I had some trouble, so after fixing them problems I thought of writing them down in case someone else can benefit from it :)

Let’s start fromt he begginig.

Create a Symfony 4 project

Please use docker! :) More info here in the Docker for Symfony 4 post.

Here’s what my docker.compose.yml looks like

Installation of Gedmo’s bundle


Now we need to update our configuration file, so in the doctrine.yaml, under the doctrine key, we should go from this

To this

Also, in our stof_doctrine_extensions.yaml, let’s add the following configuration for the doctrine extensions.

Now, if we try to update our schema

Looks about right, so let’s hit it!

And we get the following error

Now, after looking for this issue with Symfony and Gedmo Translations in the internet, I found this issue about Doctrine and this other one, and the fix here.

As davidbehler and javiereguiluz explain in the posts,

the cause of this is that Symfony advises you to use utf8mb4_general_ci/utf8mb4 as collation/charset for your database. utf8mb4 takes 4 bytes per char, meaning a 255 char field needs 1020 bytes for an index.

And so it seems that MySql 5.6 has a max key length of 767 bytes, so that leaves us with three options:

  1. Decrease the field length to 191. However, we would have to override Gedmo’s translations bundle, as it uses 255 char fields everywhere..
  2. We could change the charset encoding to ut8 like so (thanks to Kuba Florczuk for the configuration):

3. We could upgrade to mysql 5.7 like so:

And update the doctrine config like so:

All of them solutions work gracefully. Hope this helps, happy coding! :)

Gedmo’s Translations Documentation

StofDoctrineExensionBundle in Symfony’s official website.
Doctrine’s extensions GitHub doc.
Translatable’s GitHub doc.

Originally published at Joey’s blog.

Coder, Entrepreneur, Co-founder at SlowCode

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store