Global Language Variables

Last Updated: May 20, 2019
documentation for the dotCMS Content Management System

A fully multi-lingual site will need to display all site elements in different languages, including not just content but also common elements such as navigation menus, buttons, header and footer images, etc. You can enable a single Template, content, or other dotCMS object to support multiple different languages using Language Variables. Language Variables allow you to create multiple versions of the variable in different lanaguages, all of which use the same key, but have different values depending on the language. You can then reference the key from within any element, and dotCMS will automatically return the appropriate value for the key depending on the user's chosen language.

For each Language Variable you create, you may create one different value for each Language you have created.

Adding Language Variables

Adding a New Language Variable

To add a new Language Variable (one that does not yet exist in any Language):

  1. Open the Content Search screen.
  2. Select Language Variable from the Type field in the left sidbar.
  3. Click the actions button at the top right or the screen and select Add New Content.
  4. Select the Language you wish to add a value for.
    • It is recommended that you always have a version of each Language Variable in the Default Language, so when creating a new language variable, if you do not change this property, a version for the Default Language will be created.
  5. Enter a value for the Key.
    • The Key you use will be the key used to access the Language Variable from within your content, and will be shared by all Language versions of the same Language Variable.
  6. Add the Value for the currently selected Language.
  7. Save and Publish the content.

Adding a Value for New Language to an Existing Language Variable

To add a new Language to an existing Language Variable:

  1. Open the Content Search screen.
  2. Select Language Variable from the Type field in the left sidbar.
  3. Select the existing Language Variable from the list.
  4. Lock the content.
  5. Select the new Language you wish to add a value for.
  6. Add the Value for the selected Language.
  7. Save and Publish the content.

Example: Multiple Versions of the Same Language Variable

The image below shows a few terms added that have both English and Spanish language versions.

Language Variable

Pulling Language Variables in Content

Automatically Pulling the Appropriate Language

To retrieve the appropriate Language version of a Language Variable dynamically in content, use the following syntax. This returns the value for the corresponding language_id set in the current browser session.

$text.get("keyname")

Explicitly Pulling a Specific Language

You may specify which Language version of the Language Variable to retrieve by specifying the language_id of the language as a second parameter. For example, in the code below, the system has been configured to use language_id=1 for English and language_id=2 for Spanish:

#set( $EnglishValue = $text.get("keyname", "1") )
#set( $SpanishValue = $text.get("keyname", "2") )

Example: Multiple languages in the same widget

The following code pulls multiple language versions of several language variables at the same time:

<h3>English Language Variables</h3>
First Name: $text.get("firstName","1")<br>
Last Name: $text.get("lastName","1")<br>
City: $text.get("city","1")<br>
State: $text.get("state","1")<br>

<hr>
<h3>Spanish Language Variables</h3>
First Name: $text.get("firstName","2")<br>
Last Name: $text.get("lastName","2")<br>
City: $text.get("city","2")<br>
State: $text.get("state","2")<br>  

On this page

×

We Dig Feedback

Selected excerpt:

×