Multilingual Variables

Last modified: November 16, 2008 - 10:40

Some text and settings are stored in Drupal as variables, and some site-wide ones like 'site name' and 'site slogan,' along with module-specific ones, can be edited through the administration pages. The Internationalization package makes it so these variables can be translatable.

To enable these variables to be translatable we need to identify the low-level names Drupal uses for them. This can be done looking at the 'variable' table in the database or searching through the code. However, we'll show you how to translate the more common settings below.

Once you have identified the variables you want to be translated, they need to be added in the settings.php file for the site as follows:

/**
 * Multilingual settings
 * 
 * This is a collection of variables that can be set up for each language when i18n is enabled.
 * These are the basic ones for Drupal core, but you can add your own here.
 */
$conf['i18n_variables'] = array(
  // Site name, slogan, mission, etc..
  'site_name',
  'site_slogan',
  'site_mission',
  'site_footer',
  'anonymous',
  // Different front page for each language
  'site_frontpage',
  // Primary and secondary links
  'menu_primary_links_source',
  'menu_secondary_links_source',
  // Contact form information
  'contact_form_information',
  // For theme variables, read more below
  'theme_settings',
  'theme_garland_settings',
);

About theme related settings, they're stored in a different variable for each theme, which is usually 'theme_THEMENAME_settings' and these are merged with the default theme settings in 'theme_settings'. Some themes may have other specific variables so you may need to take a look at the 'variable' table (or use devel module) to see how they're stored.

The configuration file is usually under /sites/default/settings.php or another subfolder under sites. Also, there may be more than one if you are using a multisite setup.

Once you have the correct settings added to your configuration file, they'll be marked as 'multilingual variable' when you go to the corresponding administration pages. You must switch the site language while in the administration pages to set the value for each language.

The values of the multilingual variables will be saved in the i18n_variable table.

Multilingual variablesFigure 1 - Multilingual settings

You must switch the site

druppi - November 4, 2008 - 14:21

You must switch the site language while in the administration pages to set the value for each language.

And you must also switch the presentation language to match the site language. If not, it will mess up.

And, don't forget to change the site and presentation language each time you maintain the site information, otherwise you will mess up your site information strings.

Nice feature, and so user-friendly :(

Clearer explanation

bsimon - November 14, 2008 - 05:57

Like a lot of the i18n features, this can be hard to understand the first time, so here's a more detailed explanation of some steps.

To keep things simple to begin with, just change one feature, the default front page for each language. This is a good place to start because the default front page seems to be the most obvious feature that simply will not work properly on a multilingual site (unless you follow the instructions on this page or figure out some other hack/workaround).

1. As explained above, add some code to the end of settings.php. If uncertain, make a backup of settings.php first. You probably need to temporarily change the permissions for settings.php to 644 to edit it. Change back to 444 after you save it.

The difference between this code and the code above is just that the '//' at the beginning of most lines makes those lines into comments so they have no effect. Remove '//' later when you're ready to implement each feature. It's easier to understand what's going on if you just change one thing at a time.

/**
* Multilingual settings
*
* This is a collection of variables that can be set up for each language when i18n is enabled.
* These are the basic ones for Drupal core, but you can add your own here.
*/
$conf['i18n_variables'] = array(
  // Site name, slogan, mission, etc..
//  'site_name',
//  'site_slogan',
//  'site_mission',
//  'site_footer',
//  'anonymous',
  // Different front page for each language
  'site_frontpage',
  // Primary and secondary links
//  'menu_primary_links_source',
//  'menu_secondary_links_source',
  // Contact form information
//  'contact_form_information',
);

So we only actually added 'site_frontpage' at the moment. Every other variable is behind a '//' and has no effect.

2. To test this new i18n variable, it's best to have the standard language switcher block enabled on every page. If you can't see it, enable it at Administer › Site building › Blocks

3. Now go to the admin page Administer › Site configuration › Site information

And... because of the new variable, 'site_frontpage', that you just added to settings.php, 'This is a multilingual variable' should have appeared after 'Default front page' . If not, it probably means your change to settings.php was not effective for some reason.

4. Next, click on the switcher block to change to one of the other languages you are using

Obviously, this should change the language for the whole page - that's normal, but you should also see that the language prefix in the path after 'Default front page' has changed. (the prefix is the two letter language code such as /en/, /fr/, /de/, /es/, /fr/, /zh/, etc)

5. Now, after 'Default front page', type the location of the other language's front page.

6. If you stay on the Site Information page and switch languages on the switcher block, you can immediately see the Default front page path change to match it.

7. Repeat from step 4. for all the languages you're using.

help pls

janbolat - November 25, 2008 - 14:12

I couldn't understand what is 'Default front page' on step 5?
could you please show these things on picture...
I have 'This is a multilingual variable' text near those strings...
But I can;t change them for each language

The default front page

bsimon - November 26, 2008 - 11:20

The default front page setting in step 5 is on your Drupal site administration page: example.com/admin/settings/site-information

If the multilingual variables are working OK, it should look like this.

http://img296.imageshack.us/my.php?image=drupali18nsettings2uc1.gif

But I think it's possible to see the 'This is a multilingual variable' text sometimes even when it's not working properly.

Contact Form Categories

meruthecat - December 16, 2008 - 07:24

I've created multilingual variables as described above and everything is great but I don't see a variable for the contact form categories nor can I locate the category strings using the translate interface. I've searched every forum post I can find on this issue and also installed the String Overrides Module and can't find a solution. Can these be translated and if so, how?

"Contact us" string

jonvaljean - December 19, 2008 - 10:58

Also: I cannot find any variable which produces the string "Contact us" as the title of the contact form. Any help ? My contact info is translated according to variable "contact_form_information", all went well, but the title sticks in English.

Thanks

Jon Cooper
Etretat, France

thanks for this helpful post

germinal - January 18, 2009 - 21:53

reading all these replies there seem to be alot of problems with the i18n module...

for me the frontpage var works.. I can change it.. but when adding 'menu_primary_links_source', to the settings.php it completely disappears from website... it doesnt show this a a multilang var in the menu.... deleting 'menu_primary_links_source', from the settings.php gives me back the primary menu..

strange issue...

SOLUTION

germinal - January 18, 2009 - 23:04

I found the solution to my problem... because you declare it ('menu_primary_links_source',) as a multilanguage variable in settings.php ini you should go to the http://127.0.0.1/admin/build/menu/settings page... then you need to switch to a certain language ... ie http://127.0.0.1/nl/admin/build/menu/settings.. (for dutch) and set the source for the primary menu for that particular language you choose before...

then the primary menu will reapear... do this for every language and it works like a charm

Default menu for nodes: add 'menu_default_node_menu'

ShutterFreak - April 10, 2009 - 09:42

If you also want to be able to set the default menu for nodes, then make sure you also add 'menu_default_node_menu' to the list of localizable variables in settings.php.

Translating slogan, mission, footer, front page

JeniferTucker - April 11, 2009 - 13:42

Great post - thanks for making this clearer and it worked first time :-)

JLT

not working

morningtime - December 18, 2008 - 02:00

// Primary and secondary links
'menu_primary_links_source',
'menu_secondary_links_source',

Above has no influence! Yes, it does state "this is a multilingual value" - but changes at different languages are NOT stored. Why? Same for Google Analytics code and such.

Solution?

second that

sigius - December 26, 2008 - 17:47

I have the same issue but with 'site_frontpage': It does state "this is a multilingual value" - but changes at different languages are NOT stored.

where can i find other variables?

menros - February 2, 2009 - 09:43

Thanks for this helpful guide.
I've followed it - and it works great.

I would like to go further and make my site more 'multilingual', i.e the new user registration help message, the e-mail that notifies a new user that the account is waiting approval, the wellcoming e-mail message with the account details, and more...

where can i find the name of these variables, so i can add them as more lines in the list at the end of settings.php?

many thanks

Variables names are In source or in DB

bsimon - February 2, 2009 - 13:20

You can often find the variable names just by looking at the source (in Firefox, select the relevant section, right click, choose 'view selection source' and look for a field like name="some-variable")

But for some types of variables (for example theme variables), this method will only appear to work. You get the 'This is a multilingual variable' message, but actually it doesn't have any effect.

In that case, you can also find the variable names in the database, as briefly described here: http://drupal.org/node/333796
Just using this method on its own will not display 'This is a multilingual variable', even when it's working.

I've got this working with a few variables that I needed to make multilingual (such as posting date formats and the logo path), but I don't know if these two methods will work in every case.

Also, for some of the things you want to do, it's possible the 'Translate interface' option in Admin might be the way to go.

Switchback to default Language doesn't work

pjunker - February 4, 2009 - 12:22

The Solution doesn't work for me. I added the multilingual variable to the settings.php and a frontpage link for my second Language in Administer->Site Configuration. The Switching of the Frontpage to my second Language works but the switchback to the default language not.

link of the default language: mysite.com/node/3
link of the second language: mysite.com/en/node/4

If i want to switchback drupal takes the link: mysite.com/node4 and not mysite.com/node/3

Where is my fault? or is it a bug? Can somebody help me?

Run Cron

dddave - March 13, 2009 - 09:26

It is vital to run Cron after making something a variable.

After that you can make your changes per language.

Didn't worked

binhcan - March 17, 2009 - 21:22

Thanks. After reading your comment I ran Cron and Updates but still there is no changes to the site information form.

Still couldn't translate it. :((

Me too, I see database

nguyendhex - March 31, 2009 - 08:58

Me too,

I see database records for variables are created but sitename still display nothing

--------------------------------------------------
Drupal Installing Service
Drupal themes. Free Drupal Themes and Templates

It works if i comment

nguyendhex - March 31, 2009 - 15:03

It works if i comment 'theme_garland_settings' variable

--------------------------------------------------
Drupal Installing Service
Drupal themes. Free Drupal Themes and Templates

I had the same problem as

roychri - September 11, 2009 - 19:32

I had the same problem as @binhcan and I solved it simply by installing the i18n module. The i18n_variables will not work unless you have that module enabled.

--
PHP5 Zend Certified Engineer
Christian Roy

Hi, How to translate the name

quicksand - April 19, 2009 - 10:04

Hi,

How to translate the name of a menu ?

Just search and translate

nguyendhex - April 22, 2009 - 00:36

Just search and translate (admin/build/translate/search) as normal string

--------------------------------------------------
Drupal Installing Service
Drupal themes. Free Drupal Themes and Templates

Multilingual variables in contrib module

iva2k - May 31, 2009 - 04:20

One thing is not clear - how one adds variables found in a contributed module? For example, I want to provide multilingual settings in the iTweak Login module. I want to execute this code:

  $conf['i18n_variables'] += array(
    'itweak_login_register_button',
    'itweak_login_register_button_name',
    'itweak_login_register_name',
    'itweak_login_recover_name',
    'itweak_login_recover_url',
    'itweak_login_login_button_name',
  );

Questions:

1). Where is the correct place - some hook or toplevel of .module file? Can anyone shed some light on that?

2). I searched for 'i18n_variables' (grep) in whole drupal-6.12 directory - zero results. Is there a specific contrib module that needs to be installed?

Added settings, but there are

MarvelME - June 13, 2009 - 12:40

Added settings, but there are no i18n_variable table in db, and changes affect all languages. Cron wont help.
Drupal 6.12

useful multilingual variables and how to find them

strellman - July 23, 2009 - 14:36

After you set a variable as multilingual be sure to save the default version first before translating it or you will lose your default.

Here is what we use at the bottom of settings.php:

/**
* Multilingual settings
*
* This is a collection of variables that can be set up for each language when i18n enabled.
* These are the basic ones for Drupal core, but you can add your own here.
* Find them by looking through source of page for name=
*/
$conf['i18n_variables'] = array(
'theme_default',
'file_directory_path',
'menu_primary_links_source',
'menu_default_node_menu',
'nice_menus_custom_css',
'site_mail',
'site_name',
'site_slogan',
'site_mission',
'site_footer',
'anonymous',
'site_frontpage',

/* User configuration */
'user_registration_help',
'user_mail_register_admin_created_subject',
'user_mail_register_admin_created_body',
'user_mail_register_no_approval_required_subject',
'user_mail_register_no_approval_required_body',
'user_mail_register_pending_approval_subject',
'user_mail_register_pending_approval_body',
'user_mail_password_reset_subject',
'user_mail_password_reset_body',
'user_mail_status_activated_subject',
'user_mail_status_activated_body',
'user_mail_status_blocked_subject',
'user_mail_status_blocked_body',
'user_mail_status_deleted_subject',
'user_mail_status_deleted_body',

/* Node help */
'blog_help',
'story_help',
'contact_form_information',

/* Location */
'location_default_country',
'location_settings_user',

/* Invite */
'invite_subject',
'invite_default_mail_template',

/* User_relationships */
'user_relationship_mailer_request_subject',
'user_relationship_mailer_request_message',
'user_relationship_mailer_cancel_subject',
'user_relationship_mailer_cancel_message',
'user_relationship_mailer_approve_subject',
'user_relationship_mailer_approve_message',
'user_relationship_mailer_disapprove_subject',
'user_relationship_mailer_disapprove_message',
'user_relationship_mailer_remove_subject',
'user_relationship_mailer_remove_message',
'user_relationship_mailer_pre_approved_subject',
'user_relationship_mailer_pre_approved_message',
'user_relationships_ui_msg_submitted',
'user_relationships_ui_msg_accepted',
'user_relationships_ui_msg_disapproved',
'user_relationships_ui_msg_cancel',
'user_relationships_ui_msg_default',
'user_relationships_ui_msg_removed',
'user_relationships_ui_msg_pending',
'user_relationships_ui_msg_pre_approved',
'user_relationships_ui_msg_too_many_relationships',
'user_relationships_ui_msg_existing_request',
'user_relationships_ui_msg_existing_relationship',
'user_relationships_ui_msg_not_accepting_requests',
'user_relationships_ui_msg_self_request',
'user_relationships_ui_msg_non_existant_user',
'user_relationships_ui_msg_non_existant_type',
'user_relationships_ui_msg_unknown_error',
'user_relationships_ui_msg_relationship_type_not_set',
'user_relationships_ui_msg_relationship_type_not_allowed',
);

To Multilingual theme vars

joch - July 26, 2009 - 01:31

Add to above list

.. $conf['i18n_variables'] = array(
'theme_default', ...

/* the next line make a theme vars Multilingual */
'theme_xxtheme_settings', /* xxtheme = name part of file in theme, xxtheme.info */

'logo_path',
);

byJOCh

 
 

Drupal is a registered trademark of Dries Buytaert.