Community Documentation

Variable translation

Last updated November 5, 2012. Created by Jose Reyero on April 1, 2011.
Edited by frederickjh, Kristen Pol, epoitras, pixelite. Log in to edit this page.

The Variable translation module, part of the Internationalization (i18n) package, allows you to translate text and settings that are stored in Drupal as variables. These variables include text such as 'site name' and 'site slogan', as well as settings like 'Default front page' and 'Default 404 page'.

Dependency

The Variable translation module has a dependency on the Variable module.

Support for Contributed Modules

Variables provided by contributed modules can also be translated by the Variable translation module if they implement hook_variable_info(). For documentation, see the Variable module project page.

Usage

To enable multilingual variables (Figure 1):

  1. Enable the Variable translation module included with the Internationalization package
  2. Go to Administration > Configuration > Regional and language > Multilingual settings
  3. Click on the Variables tab
  4. Select the variables that will be multilingual
  5. Click Save configuration button

Figure 1

Once you have the correct settings, they'll be marked with "This is a multilingual variable" when you go to the corresponding administration pages (Figure 2). You must switch the site language while in the administration pages to set the variables for each language. A language switcher link will appear at the top of each administrative page that has multilingual variables.

Figure 2

AttachmentSize
multilingual_variables_1.png57.67 KB
multilingual_variables_2.png34.57 KB

Comments

Also for what it's worth if

Also for what it's worth if you need to access any of these variables that you have translated you can use variable_get_value($name, $options) where $options can contain your language to grab an appropriate language you might need.

Missing documentation

When defining your variables using hook_variable_info(), you have to specify a localize key if you want your variables to be translatables.

See an example above :

<?php
/**
* Implements hook_variable_info().
*/
function MYMODULE_variable_info($options) {
 
$variables['VAR_NAME'] = array(
   
'type' => 'array',
   
'title' => t('VAR TITLE', array(), $options),
   
'default' => array('*' => 0),
   
'description' => t('VAR DESCRIPTION', array(), $options),
   
'required' => TRUE,
   
'localize' => TRUE,
   
'group' => 'GROUP_NAME',
  );
  return
$variables;
}
?>

Frenchy drupal developper

Page status

About this page

Drupal version
Drupal 7.x
Audience
Programmers, Site administrators
Keywords
i18n, Internationalization, multilingual, multilingual variable, variable translation, variables
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here