I'm building a multilingual site in Drupal 7 and I'm struggling to figure out how to translate meta tags on the front page. The tags I need to translate are title, description and keywords. I have set up the meta tags quick module and it works fine for nodes but my front page is not a node but a collection of blocks so this approach can't be used.

I know there are meta tags quick front page settings in the structure in the admin panel but these only allow you to set up the default (in my case, English) version of the front page's description and keywords. there is no option to translate them. For the title tag, I found an option in configuration -> page titles but again, this only allows you to set the English version (or 1 default version, anyway) so you end up with a handful of duplciate titles. As a result, currently all my front pages (8 languages in total) have the same title, description and keywords tags). Any help would be much appreciated. Thanks in advance!

Comments

ameya karajgikar’s picture

You can not translate meta tags.

maxxer’s picture

isn't this kind of a critically missing feature?

mikaoelitiana@gmail.com’s picture

Have you found any solution for this problem? 1 year later I am still having the same problem

dnlt’s picture

I'm trying to achieve it through "context metatags", included in metatag. Obviously, it depends on context module.
You can make a context for each language, with two conditions, path= and language="whatever-lang-you-want".
The magic is that "context metatags" provides a reaction called "meta data", that allows you overwrite any meta data rule when the context applies.
Don't forget to set the "Require all conditions" checkbox on.
Good luck.

damic’s picture

Hello,

I had the same problem and found a solution using http://drupal.org/project/variable, http://drupal.org/project/token and a custom module.

mymodule.variable.inc

/**
 * @file
 * Variable API module. Definition for some xample variables
 */

/**
 * Implements hook_variable_info().
 */
function mymodule_variable_info($options) {
  // Simple text
  $variables['ic_meta_front_title'] = array(
    'type' => 'text',
    'title' => t('Frontpage title', array(), $options),
    'default' => 'Welcome to Independence Hotel, Resort and Spa Sihanoukville Cambodia',
    'description' => t('Set html title tag for the frontpage.', array(), $options),
    'required' => TRUE,
    'token' => TRUE,
    'group' => 'ic_frontpage_meta',
  );
  $variables['ic_meta_front_description'] = array(
    'type' => 'text',
    'title' => t('Frontpage meta description', array(), $options),
    'default' => 'Independence Hotel Sihanoukville. A luxury resort in Cambodia. 35ha landscape, 200m private beach, spa, pool villa, deluxe suite weddings, seminar...',
    'description' => t('Set meta description tag.', array(), $options),
    'required' => TRUE,
    'token' => TRUE,
    'group' => 'ic_frontpage_meta',
  );

  $variables['ic_meta_views_description'] = array(
    'type' => 'text',
    'title' => t('Meta description for views', array(), $options),
    'default' => 'Independence Hotel and Spa Sihanoukville Cambodia.',
    'description' => t('Set meta description tag.', array(), $options),
    'required' => TRUE,
    'token' => TRUE,
    'group' => 'ic_frontpage_meta',
  );
  
  return $variables;
}

/**
 * Implements hook_variable_group_info().
 */
function mymodule_variable_group_info() {
  $groups['ic_frontpage_meta'] = array(
    'title' => t('Frontpage meta tags'),
    'description' => t('Variables for frontpage meta tag.'),
    'access' => 'administer site configuration',
    'path' => array('admin/config/system/variable/frontpage_meta'),
  );
  return $groups;
}

mymodule.module

/**
 * @file
 * Code taken from variable example.
 */

/**
 * Implements hook_variable_realm_info()
 */
function mymodule_variable_realm_info() {
  $realm['frontpage_meta'] = array(
    'title' => t('Frontpage meta data'),
    'weight' => 10,
    'store class' => 'VariableStoreRealmStore',
    'keys' => array(
      'first' => t('Frontpage meta'),
      'second' => t('Frontpage meta 2'),
    ),
  );
  return $realm;
}

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items['admin/config/system/frontpage_variable'] = array(
    'title' => 'Frontpage meta data',
    'description' => 'Set title and meta description for frontpage.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('variable_group_form', 'ic_frontpage_meta'),
    'access arguments' => array('administer site configuration'),
  );
  $items['variable/frontpage_meta'] = array(
    'title' => 'Frontpage meta',
    'description' => 'List frontpage meta variables.',
    'page callback' => 'ic_frontpage_meta_page_list',
    'access arguments' => array('administer site configuration'),
  );
  $items['variable/realm/%/%'] = array(
    'title' => 'Frontpage realms',
    'description' => 'Frontpage exemple realms.',
    'page callback' => 'ic_frontpage_meta_page_realm',
    'page arguments' => array(2, 3),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}

/**
 * Variable example realm page.
 *
 * Will switch to given realm and display variables.
 */
function mymodule_page_list() {
  variable_include();
  $list = variable_list_group('site_information') + variable_list_group('ic_frontpage_meta');
  foreach ($list as $name => $variable) {
    $build[$name] = array(
      '#type' => 'item',
      '#title' => $variable['title'],
      '#markup' => variable_format_value($variable),
    );
  }
  return $build;
}

/**
 * Variable example realm page.
 *
 * Will switch to given realm and display variables.
 */
function mymodule_page_realm($realm, $key) {
  // Initialize realm from variable store.
  $variables = variable_store($realm, $key);
  // Set at least one variable for the realm
  $variables += array('site_name' => 'Variable example realm');
  variable_realm_add($realm, $key, $variables);
  variable_realm_switch($realm, $key);
  return variable_example_page_list();
}

Admin settings

  1. Go to admin/config/regional/i18n/variable and tick your variables.
  2. Go to admin/config/system/frontpage_variable and set your tags in your different languages
  3. Go to admin/config/search/metatags and use the token [variable:ic_meta_front_description] for frontpage settings

Hope it helps.

Kedar Lasane’s picture

Thanks @damouille , your code works fine for me...keep it up

parameshrag’s picture

Awesome!!! It worked for me also. Thanks for the code.

kristofsw’s picture

You can do this using the Internationalization module (i18n). The module comes with a bunch of small submodules, including String Translation (string_i18n).

If you enable that module you will see an option to translate your metatags if you go to admin/config/search/metatags

Hope this helps.