Pooling translations

The pooling of translations in the CONSTANTS section of the root template facilitates the management of multilingual content in TypoScript.

Motivation

Sometimes it is necessary to write some text directly into a TypoScript template, e.g. to display an anchor text or the title attribute of a link or an image.

Writing these texts directly in the template's SETUP section would be very inflexible: If the same text occurs in multiple places and needs to be changed, it is likely that one or the other will be forgotten or misspelled

Another counter-argument is that in a multilingual web site, the various translations can not be inserted easily.

Negative Example

Let's suppose, we have an image and want to assign an alternative text in three different languages to it. The image is the same for all three languages and is included directly in the SETUP section of our root template.

The inflexible and cumbersome way would be this one:

Inflexible assignment of translations TypoScript, SETUP section
# Create two images and assign alternate texts in multiple languages
 
10 = IMAGE
10.file = fileadmin/images/house.jpg
# 1. English
[globalVar = GP:L=0]
10.altText = A house
[global]
# 2. German
[globalVar = GP:L=1]
10.altText = Ein Haus
[global]
# 3. French
[globalVar = GP:L=2]
10.altText = Une maison
[global]
 
20 = IMAGE
20.file = fileadmin/images/car.jpg
# 1. English
[globalVar = GP:L=0]
20.altText = A car
[global]
# 2. German
[globalVar = GP:L=1]
20.altText = Ein Auto
[global]
# 3. French
[globalVar = GP:L=2]
20.altText = Une voiture
[global]

This is cumbersome because the conditions for all languages must be rewritten at each location where that image is used. Furthermore, the code is not particularly easy to read.

Best Practice

The better way is to define the language versions as constants in the CONSTANTS section of the root template and then include them in the SETUP sections of the subpages:

Flexible assignment of translations TypoScript, CONSTANTS section
# Defining texts in multiple languages
# Please note that the names of the constants are the same in each language!
 
# 1. English
[globalVar = GP:L=0]
alt_house = A house
alt_car = A car
# ...
[global]
 
# 2. German
[globalVar = GP:L=1]
alt_house = Ein Haus
alt_car = Ein Auto
# ...
[global]
 
# 3. French
[globalVar = GP:L=2]
alt_house = Une maison
alt_car = Une voiture
# ...
[global]
Using the translations TypoScript, SETUP section
# Using the translated texts as constants
# The translation of the current language of the page will be inserted
 
10 = IMAGE
10.file = fileadmin/images/house.jpg
10.altText = {$alt_house}
 
20 = IMAGE
20.file = fileadmin/images/car.jpg
20.altText = {$alt_car}

As mentioned above, the translated texts can be used in the templates of all subpages. This way, not only alternate texts of images can be replaced. You can use this method to modify metatags, content in the footer of a page and other content parts as well.