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
Comment #1
henk commentedI 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.
Comment #2
henk commentedEditing 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.
Comment #3
jose reyero commentedThe 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'...
Comment #4
webflo commentedOr we add a hook_module_implements_alter to i18n_variable. Please review.
Comment #5
jose reyero commentedAmazing, I didn't know that hook existed :-)
Comment #6
henk commentedThanks, for reply. Changing the module weight solved my problem.
Good to know about that hook!
Comment #7
jose reyero commentedThinking 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.
Comment #8
webflo commentedYou 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.
Comment #9
jose reyero commentedOk, fixed hook name in description and committed.
Thanks.