Hi,
Using file entity for a file with a "Download link" display, I realized that the link text was not proccessing for translation :
I changed the link text from "Download [file:name]" to a custom text.
In the translate interface pages, my custom string was available ans I filled it's traduction, but it was never shown in the node page.

I found that in the theme download link function, the default link text was passed through the t() function, but not the custom value.
I propose the correction below and I hope it will be updated in next release :

file_entity.theme.inc l.45

function theme_file_entity_download_link($variables) {
  $file = $variables['file'];
  $icon_directory = $variables['icon_directory'];

  $uri = file_entity_download_uri($file);
  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;

  // Provide the default link text.
  if (!isset($variables['text'])) {
-   $variables['text'] = t('Download [file:name]');
+  $variables['text'] = 'Download [file:name]';
  }
+$variables['text'] = t($variables['text']);

  // Perform unsanitized token replacement if $uri['options']['html'] is empty
  // since then l() will escape the link text.
  $variables['text'] = token_replace($variables['text'], array('file' => $file), array('clear' => TRUE, 'sanitize' => !empty($uri['options']['html'])));

  $output = '<span class="file">' . $icon . ' ' . l($variables['text'], $uri['path'], $uri['options']);
  $output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
  $output .= '</span>';

  return $output;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seren10pity13 created an issue. See original summary.

rakesh.gectcr’s picture

Same thing created as a patch.

kbrinner’s picture

This is not working for 7.x-2.0-beta3 when I change function theme_file_entity_download_link($variables) (line 57-60) to the following:

function theme_file_entity_download_link($variables) {
  $file = $variables['file'];
  $icon_directory = $variables['icon_directory'];

  $uri = file_entity_download_uri($file);
  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;

// Provide the default link text.
 if (!isset($variables['text'])) {
-   $variables['text'] = t('Download [file:name]');
+  $variables['text'] = 'Download [file:name]';
  }
+$variables['text'] = t($variables['text']);

  // Perform unsanitized token replacement if $uri['options']['html'] is empty
  // since then l() will escape the link text.
  $variables['text'] = token_replace($variables['text'], array('file' => $file), array('clear' => TRUE, 'sanitize' => !empty($uri['options']['html'])));

  $output = '<span class="file">' . $icon . ' ' . l($variables['text'], $uri['path'], $uri['options']);
  $output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
  $output .= '</span>';

  return $output;
}

If I implement this code change, my custom text for downloading a file is still not available at admin/config/regional/translate/translate. This is after I view a sample node that uses the file field in all languages, clear cache, refresh strings, confirm the field is translated - all things I have seen as gotchas in the past for strings not being available for translation.

That said, the workaround at 'Make download links translatable' does work. When I patch file_entity.field.inc per the patch provided at this other thread, the custom text for the download link is then available for translation via string translation.