We have a multi-language site and have tried to translate the button text through the "Translate Interface" page.

Texts do not appear them, are we doing something wrong or it's just unsupported?

Kind regards,

Comments

BassistJimmyJam’s picture

Title: Button Text cannot be translated through "Translate Interface" page. » Add I18n Support
Version: 6.x-1.0-beta2 » 6.x-1.x-dev
Assigned: Unassigned » BassistJimmyJam
Category: support » feature
Status: Active » Needs work

The button_field module does not currently support translations. I will add this to the list of requested features.

Enrique.Ruiz’s picture

Hello BassistJimmyJam. We are planning to add English and German languages to our site to the current Spanish, so it would be necessary to have this feature. Do you have any timeframe for adding this feature? Kind regards and thanks for this fantastic module.

emmene-moi’s picture

I may suggest the following update (sorry, no patch), for the latest 6.X-dev version:

in function theme_button_field_formatter_default($element)
Line 154, add:

$text = function_exists('i18nstrings') ? i18nstrings('cck:field:'.$node->type.'-'.$field['field_name'].':widget_text', $field['widget']['text']) : $field['widget']['text']; 

Then line 174, replace with:

      $return_value = '<button id="' . $name . '" name="' . $name . '" ' .
        'class="' . $class . '">' .
      $text . '</button>' . "\n";

And add the _locale compatibility:

/**
* Implementation of hook_locale().
*/
function button_field_locale($op = 'groups', $group = NULL) {
  switch ($op) {
	case 'groups':  // This is the standard hook_locale() as defined by Drupal core, to define 'text groups'
      return array('button_field' => t('Button Field'));
    case 'info':  // This is i18n extension, optional, to define additional properties
      // Optional refresh callback to update this module's strings at once
      $info['button_field']['refresh callback'] = 'button_field_locale_refresh';
      // This tells 'i18nstrings' that this module's strings have no input format applied
      $info['button_field']['format'] = FALSE;
      return $info;
  }
}

function button_field_locale_refresh() {
  foreach (content_types() as $content_type => $type) {
    // Localization of CCK fields.
    if (isset($type['fields'])) {
      foreach ($type['fields'] as $field_name => $field) {
        // Localize button text per content type.
        if (!empty($field['widget']['text'])) {
          i18nstrings_update('cck:field:'. $content_type .'-'. $field_name .':widget_text', $field['widget']['text']);
        }
      }
    }
  }
  return TRUE; // Meaning it completed with no issues
}

This is not perfect (need to check the field type in button_field_locale_refresh) but it works.

Enrique.Ruiz’s picture

Many thanks emmene-moi. I will be using it, please keep us updated.

Enrique.Ruiz’s picture

emmene-moi, would you please give an example on how to configure button_field_locale_refresh for each field type.
If I have three button fields called button_user, button_role and button_date. How would it be?

firfin’s picture

Triumphent’s picture

How about a patch/fix/suggestion for core version 7.xx?
Thanks.
:)

martin.l’s picture

Subscribing, we have the same requirement.

apaderno’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

I am closing this issue, as Drupal 6 is now not supported.