I am working on a module that has a per content type setting and I want that to be translatable using this module. I have defined all of the variables as per documentation but I cannot get the option to translate them.

here is what I have so far:


/**
 * Implements hook_variable_info().
 */
function csm_variable_info($options) {

  $variable['csm_create_[node_type]'] = array(
    'title' => t('Create status message', array(), $options),
    'description' => t('Create status message.', array(), $options),
    'type' => 'multiple',
    'repeat' => array(
      'default' => t('[node:content-type:name] <em>[node:title]</em> has been createdd.', array(), $options),
      'type' => 'string',
    ),
  );

  return $variable;
}


/**
 * Implements hook_variable_type_info()
 */
function csm_variable_type_info() {
  $type['node_type'] = array(
    'title' => t('Node type'),
    'options callback' => 'node_type_get_names',
    'type' => 'select',
  );
  return $type;
}

This will change a bit but only to give you an idea.

I see the variable on the variable translation screen and I also see it in the variables admin but either way, I can't get it to be multilingual even if I configured it to be by checking the box next to it on the multilingual variables configuration.

What am I missing?

Comments

hanoii’s picture

Title: [node_type] usage for multilingual variables » _[node_type] variables usage for multilingual variables
jose reyero’s picture

I don't know whether this will work but here are some clues:

- You don't need to define'node_type' variable type as it is already defined in includes/node.variable.inc
- You need to mark the variable as 'localize' => TRUE in hook_variable_info()
- The variable values don't have token replacement, you may need to provide a 'build callback'

Still I don't think the content type form is supported by the i18n_variable module so we may need a better UI for setting these values.

jose reyero’s picture

Status: Active » Closed (duplicate)
joostpluijmers’s picture

I was bashing my head on the desk as well trying to solve a similar issue. My wish was to localize and integrate the "Available menus" in the node type settings page. I quikly found out that variable module only hooks in on forms containing the 'system_settings_form_submit' handler. The second issue and I think the reasoning behind why the variable module doesn't hook on other forms is that the variable name has to match the form field name.

I solved my problem by writing a small headless utilities module:

utilities.variables.inc:

<?php
function utilities_variable_info($options) {
  $variables = array();
  $variables['menu_options_[node_type]'] = array(
      'type' => 'multiple',
      'title' => t('Available menus', array(), $options),
      'repeat' => array(
          'type' => 'options',
          'default' => array('main-menu'),
          'options callback' => 'menu_get_menus',
      ),
      'description' => t('Available menus for the specific content type', array(), $options),
      'group' => 'menu_settings',
      'localize' => true
  );

  return $variables;
}
?>

utilities.module

<?php
function utilities_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['#submit']) && is_array($form['#submit']) && in_array('node_type_form_submit', $form['#submit']) ) {
    // Get node type object from form;
    $type = $form['#node_type'];

    // Clone the existing general purpose menu_options field to menu_options_[node_type] so it gets cought by the realm handler.
    $form['menu']['menu_options_'.$type->type] = $form['menu']['menu_options'];

    // Realign the field to the top.
    $form['menu']['menu_options_'.$type->type]['#weight'] = -1;

    // Unset the old menu_options
    unset($form['menu']['menu_options']);

    // Copy/paste from variable_form_alter();
    $form['#submit'] = str_replace('system_settings_form_submit', 'variable_settings_form_submit', $form['#submit']);
    foreach (module_implements('variable_settings_form_alter') as $module) {
      $function = $module . '_variable_settings_form_alter';
      $function($form, $form_state, $form_id);
    }
  }
}
?>

Ps. Jose Reyero I would like to express my gratitude to you for your work on the variable module. I recently started upgrading my commercial clients to Drupal 7 and I am certainly loving the new variables!