Skip to main content

Setup Entity Translation the right way

Published on 2014-11-27

Niels de Feyter November 27, 2014

 

This article contains a detailed instruction on how to setup the Entity Translation module for Drupal 7 websites.

 

Goal of this tutorial is to set up a multilingual website that can be navigated in multiple languages by visitors and to enable the content to be easily manageable by editors / cms administrators.

To get multilingual right, it’s critical that you configure your content-types and fields with care and precision and upfront, because if content is already in your database it is almost impossible to change these configurations.

 

Entity Translation is part of Drupal 8 core and its approach is to translate fields instead of full nodes/entities. Entity Translation module page on drupal.org(link is external) .

 

Table of contents

 

Table of contents

Example: a news article

Field configurations

Data model

Now what is in the database?

Most important things

Configuration entity translation

Setup entity translation globals

Settings per bundle (Node)

Step 1 node: settings “edit content-type"

Step 2 node: settings within “entity translation"

Settings per bundle (Taxonomy)

Step 1 taxonomy: settings of “edit vocabulary"

Step 2 taxonomy: settings within “entity translation"

Setup 'title module'

Title setup Node

Title setup Taxonomy

Settings per field

Creating translated content

Create content in the default site-language first

Create content translations

Result

Recap of most important things

 

Example: a news article

The example we are going to work with is an easy-to-understand multilingual content-type: a news article. This content-type is part of the Drupal 7 ‘standard’ install profile.

 

Field configurations

Our news article contains the following fields:

 

Field

Field Type

Translated

Cardinality

Title

Text

Yes

1

Body

Text

Yes

1

Image

Image

No

1

Tags

Entity Reference -> Taxonomy Term

<no, we translate the term itself>

multi

table: field node 'news article’

 

The ‘tags vocabulary’ has the following configuration:

 

Field

Field Type

Translated

Cardinality

Name

Text

Yes

1

Description

Text

Yes

1

table: fields taxonomy 'tags'

 

Data model

The data model looks like this:

 

schema: data model translated content

 

Now what is in the database?

When looking with Devel, what is actually stored in the database, the node (article) is like this:

 

 

Property

 

Value

Node ID

 

1

Language

 

en

 

 

 

Field

Language

Value

Title

en

My title

 

nl

Mijn titel

Body

en

My text

 

nl

Mijn tekst

Image

und

1233

Tags

und

123,124,125

table: saved data node ‘news article'

 

For a ‘term’ you would see this:

 

Property

 

Value

Term ID

 

123

Language

 

en

 

 

 

Field

Language

Value

Name

en

My term name

 

nl

Mijn term naam

Description

en

My text

 

nl

Mijn tekst

table: saved data taxonomy 'tags'

Most important things

  • Properties are not translated. An example property is the ID of an entity (nid, tid).
  • The language property of an entity must have a value and defaults to the website language (in this case 'en').
  • The “language” ‘und’ stands for ‘undefined’: it is not a language.
  • Translated fields have a value for each language (in this case ‘en’ and ‘nl’).
  • You must use the ‘title’ module to translate title properties of nodes and terms.
  • Reference fields (entity reference, term reference) refer to the ID of another entity. The reference field itself is thereby not translated.

 

Configuration entity translation

To configure entity translation you go through a few steps:

  1. Setup entity translation globals
  2. Settings per bundle (node: article, taxonomy: tags)
  3. Setup Title module
  4. Settings per field

Setup entity translation globals

go to /admin/config/regional/entity_translation

 

ON = Enable language fallback

ON = Display shared labels

OFF = Enable translation workflow permissions

 

Open “translatable entity types” fieldset and click the entity types that must be translated.

ON = Node

ON = Taxonomy Term

OFF = File

OFF = User

 

screendump: global settings Entity Translation

Settings per bundle (Node)

 

Step 1 node: settings “edit content-type"

Go to /admin/structure/types/manage/<content-type>

Open the tab “Publishing options”

 

Below “multilingual support” choose the next settings:

ON = “Enabled, with field translation”

OFF = “Hide content translation links”

 

Save the page and repeat for each content-type (= bundle of node).

 

screendump: bundle settings for a node

Step 2 node: settings within “entity translation"

Go to /admin/config/regional/entity_translation

Open vertical tab "Node"

Apply same settings for each bundle (content-type)

 

Default language = Default language

ON = Hide language selector

ON = Exclude Language neutral from the available languages

OFF = Prevent language from being changed once the entity has been created

OFF = Hide shared elements on translation forms

 

screendump: entity translation settings node

Settings per bundle (Taxonomy)

 

Step 1 taxonomy: settings of “edit vocabulary"

Go to /admin/structure/taxonomy/<vocabulary>/edit

 

Below “multilingual option” apply the next settings:

 

Translation mode: "no multilingual options for terms. Only the vocabulary will be translatable"

Note: the translations are applied at field level. 'No multilingual options' is the right setting!

 

Save the page.

 

screendump: bundle settings taxonomy term

 

Step 2 taxonomy: settings within “entity translation"

Go to /admin/config/regional/entity_translation

Open the vertical tab "Taxonomy term"

Apply same settings for each bundle (content-type)

NB: these settings are exactly the same as "Node".

 

Default language = Default language

ON = Hide language selector

ON = Exclude Language neutral from the available languages

OFF = Prevent language from being changed once the entity has been created

OFF = Hide shared elements on translation forms

 

screendump: entity translation settings taxonomy term

 

Setup 'title module'

By default, Drupal uses properties for the title of a node and the name and description of a taxonomy term. Because properties are not translatable, we use the module 'title'. This replaces properties by real fields.

Beware that in other modules (Views and Search API) you should use these new fields (‘title_field’, ‘name_field’, ‘description_field’), instead of the usual 'title'.

 

Title setup Node

Go to the tab "Manage Fields"

At Title click "replace". The title field will be created.

 

Title setup Taxonomy

Go to the tab "Manage Fields"

At Name and Description click "replace". The field name and description will be created.

 

screendump: Title module has not been applied yet.

 

screendump: Title module has been applied

 

At this point the entity-bundles are configured to make advance of entity_translation.

 

Settings per field

Now it’s time to apply the per-field settings. It does not matter whether you're dealing with a node or taxonomy term.

 

If a field is used in multiple bundles its translation settings will be the same for all its instances. So if you've already made the ‘title’ a translatable field, this is the case everywhere.

 

  1. Go to "Manage fields" in the relevant bundle.
  2. Under "Operations" click "edit".

You are now on the "Edit" tab of the field.

At the top are "label", "required field" and "help text".

 

 

screendump: Edit tab "Body" field in content-type "Page".

 

  1. Scroll all the way down to "Field Translation".
  2. Click "Enable translation" and then "Confirm".

 

screendump: Untranslated field

 

screendump: Translated field

 

Repeat this process for all your fields and you're done with configuration.

Creating translated content

This is the step its all about: creating translated content.

First we will create a piece of content in the default site-language, next we’ll translate this piece.

 

Create content in the default site-language first

In this example, the default language is ‘English’ and we create content of content-type ‘Page’. The steps for taxonomy terms and other content bundles are the same.

New content is always stored in the default language (we forced that in global entity-translation settings).

  1. Go to /node/add/page.
  2. Write your content
  3. Save

 

screendump: Writing content

 

When you visit the Devel-tab immediately after saving new content, you should see something like below:

screendump: Devel tab immediately after creating content.

 

A couple of things stand out:

The fields 'body' and 'title' have a value in the language 'en'. These are our translations so far.

The property 'language' has the value 'en'. This is the default-language and is necessary to force the translate-tab to appear.

The property 'translatable' has a value "0" (false). This is correct, because we translate fields and not the entire node.

Create content translations

The new node has a new ‘tab’ next to ‘view’, ‘edit’ and ‘devel’. When you click on it you have the possibility to add and/or modify translations.

screendump: Translate tab immediately after creating content.

 

  1. Click 'add' for the relevant language.
  2. Write your translation
  3. Save content
  4. Repeat for all languages.

 

For each translation that is added a sub-tab appears for that language

screendump: Adding the Dutch translation

 

When visiting the Devel-tab after translation you will see that the fields will have a translated value. Exactly how we want it.

screendump: Devel-tab after translating content.

 

Result

The content is now translated and can be viewed in different languages.

The language-selection takes place (which language should be visible) and is dependent how the Local module is configured. Configuring Local is not included in this manual.

Recap of most important things

  • Properties are not translated. An example property is the ID of an entity (nid, tid).
  • The language property of an entity must have a value and defaults to the website language (in this case 'en').
  • The “language” ‘und’ stands for ‘undefined’: it is not a language.
  • Translated fields have a value for each language (in this case ‘en’ and ‘nl’).
  • You must use the ‘title’ module to translate title properties of nodes and terms.
  • Reference fields (entity reference, term reference) refer to the ID of another entity. The reference field itself is thereby not translated.