I have problem with translation of variable.

1. First I add some form

<?php
/*
* Implementation of hook_form_alter
*/
  
  function some_modules_form_alter(&$form, &$form_state, $form_id) {
       if('system_site_information_settings' == $form_id) {

          $form['site_information']['site_footer'] = array(
            '#type' => 'textfield',
            '#title' => t('Footer text'),
            '#default_value' => variable_get('site_footer', 'Default text'),
            '#description' => t('Some text'),
            '#required' => TRUE
            );
            
        }

        
        return system_settings_form($form);

  }
?>

2. Then I create variable definition

<?php

 /**
  * Implementation of hook_variable_info
  */ 
  
 function  some_modules_variable_info($options) {

     
 $variables['site_footer'] = array(
    'type' => 'string',
    'title' => t('Footer text', array(), $options),
    'default' => 'Default text',
    'description' => t('Some text', array(), $options),
    'required' => TRUE,
    'group' => 'site_information',
    );

     return $variables;
 }
?>

3. I saw 'Footer text' variable in Multilingual variable settings. I selected checkbox and I push submit form.

4. I returned to "Site information page", but still I don't have in description "This is a multilingual variable.", and variable is still the same for all language.

What I forgot to do?

Thanx for help,

Comments

henk’s picture

Category: support » bug
Status: Active » Needs review

I found bug.

When I go to page: admin/config/system/variable/edit/site_footer

I see that variable is multilingual and translation works ok. But in Site information form still don't have that information. After set all data field of multilingual variable in admin/config/system/variable, all translations works fine.

Maybe this is some bug, on my site works ok now.

henk’s picture

Status: Needs review » Active

Editing multilingual variable works ok in "admin/config/system/variable", but not in the "Site information page", where I added this to form. Still a see this problem.

jose reyero’s picture

Title: Variable translation problem » Variables added with form alter are not shown as translatable, needs better i18n_variable_form_alter()
Project: Variable » Internationalization
Version: 7.x-1.1 » 7.x-1.x-dev
Component: Code » Miscellaneous
Category: bug » feature

The problem is multilingual variables feature uses form_alter too so you need to add your variable before i18n_variable module kicks in.

The obvious solution is using module weights for that. But we could also think about using other hooks from i18n_variable, like form 'after build'...

webflo’s picture

Status: Active » Needs review
StatusFileSize
new1.13 KB

Or we add a hook_module_implements_alter to i18n_variable. Please review.

jose reyero’s picture

Status: Needs review » Reviewed & tested by the community

Amazing, I didn't know that hook existed :-)

henk’s picture

Thanks, for reply. Changing the module weight solved my problem.

Good to know about that hook!

jose reyero’s picture

Status: Reviewed & tested by the community » Needs work

Thinking more about this, though the patch is amazing, I am not sure we should implement that hook because this doesn't allow any other module to alter the form after i18n_string.

webflo’s picture

You mean "after i18n_variable". Right? I think it is okay because in most cases this is a simple Drupal settings form without heavy form alteration.

jose reyero’s picture

Status: Needs work » Fixed

Ok, fixed hook name in description and committed.

Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.