1

With Drupal 7, we have a custom module that displays a form that will work in both English and Spanish. Throughout the form we used t() to translate the text, and it works in all but two places. One is in the form when we declare a fieldset, and the other is the menu entry declaration (which isn't using t()). For the menu entry we have '[SiteName] Events' like this:

$items['sitename-events/register'] = array(
    'title' => 'SiteName Events',
    'page callback' => 'sitename_events_event_register',
    'access arguments' => array('view events'),
    'file' => 'public.events.inc',
    'type' => MENU_NORMAL_ITEM,
);

For the form, the element is declared like this:

// Personal Information
$form['personal'] = array(
    '#type' => 'fieldset',
    '#title' => t('Personal Information'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
);

Other pages are translating just fine, as well as other elements in the form, including the other field sets. What would cause these two entries to not translate, and is there a way that I can force them to translate since we're only going to support English and Spanish?

3
  • What modules are you using for translation support?
    – keithm
    Aug 8, 2011 at 18:49
  • Looks like we have 'translation' from core, and then 'i18ln_translation' in sites/all/modules, and then 'views' has its own translation set Aug 8, 2011 at 19:16
  • Thanks. It's been hell trying to find a solution to the faulty translation of modules. Even though the po-file contained the right translations, some text got translated, some not. UPDATE/ Sorry, wanted to comment on the previous answer but it seems I provided an answer instead. Donk!
    – user3714
    Oct 26, 2011 at 15:19

1 Answer 1

4

The literal strings that are passed to t() are not directly translated from the function; the function just searches the provided string in the databases used from the Locale module ("locales_source" and "locales_target"; see locale()). Before searching in that databases, t() checks the Drupal variable locale_custom_strings_<lang_code>, where <lang_code> is the language code for the language to which the strings are translated.

In the first case, the strings are imported from the translation files. In the second case, the Drupal variable can be set in the settings.php file.

As you want to have the translation for strings used by a custom module, the first method (creating a .po file, and then importing it) is probably too laborious, especially because it's a custom module for which localize.drupal.org cannot provide the translation files (the ones with extension .po). The only alternative is to use code similar to the following one in the settings.php file:

$conf['locale_custom_strings_es'][''] = array(
  'forum'      => 'foro',
  '@count min' => '@count minudos',
);

The strings I used are just an example (I hope I translated the strings in Spanish correctly ); the strings I used already have their translation in Spanish as part of the core translation.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.