Unable to translate field descriptions in other languages. Looks like t() function is not used where required.

CommentFileSizeAuthor
#2 unable-to-translate-2875247-2.patch689 bytesjadhavdevendra

Comments

jadhavdevendra created an issue. See original summary.

jadhavdevendra’s picture

StatusFileSize
new689 bytes

This fixed the problem.

yogeshmpawar’s picture

Status: Active » Needs review

Checking above mentioned patch.

  • Yogesh Pawar committed 1d10225 on 7.x-1.x
    Issue #2875247 by jadhavdevendra, Yogesh Pawar: Unable to translate...
yogeshmpawar’s picture

Status: Needs review » Fixed

Committed & pushed to 7.x-1.x branch.

odegard’s picture

Status: Fixed » Needs work

I'm afraid this must be reverted. You can't use the t function to translate variables.

This is how I solve this particular problem in local projects:

// These must be populated somehow.
$entity_type = 'node'; // usually, but not always.
$bundle = 'some_bundle';
$field_name = 'field_some_field';
$langcode = 'nb'; // target translation language code

// We need to get the label from this particular field instance.
// This will give the untranslated field info including label and description.
$instance = field_info_instance($entity_type, $field_name, $bundle);

// i18n_string_translate does the heavy lifting searching through the db for translations.
// It needs a string on this form.
$context_label = 'field:' . $field_name . ':' . $bundle . ':label';
$label = i18n_string_translate($context_label, $instance['label'], array('language' => $langcode));

$context_description = 'field:' . $field_name . ':' . $bundle . ':description';
$description = i18n_string_translate($context_description, $instance['description'], array('language' => $langcode));

With this, $label and $description is translated via the i18n module. I'm not sure if this is relevant if i18n is not used, but I'm sure some people use this module on monolingual sites, so the i18n_string_translate should be wrapped in module_exist('i18n_string') I guess.

I'm extremely busy but my ambition is to go over the module during the summer.

Feel free to test this out of course :)

I can't provide code right now, but I can help and guide if needed.

yogeshmpawar’s picture

Status: Needs work » Closed (works as designed)

I think this solution is working fine for multilingual sites. tested this locally.
some reference links -

  1. https://drupal.stackexchange.com/questions/268093/is-it-allowed-to-call-...
  2. https://drupal.stackexchange.com/questions/152726/translate-with-t-funct...