Translating custom database table fields How can I translate the fields for my custom database table which uses the following schema?


member_id: int
name: varchar(60)
i_prefer: varchar(50)


I need to translate the string that is displayed for the 'i_prefer' field. I know how I should represent this in template page (&lt;?php print t($query-&gt;i_prefer); ?&gt;), but the translated string will not appear until I provide the translation. I checked in 'Regional and language > Translate interface'; I can not see my text.

How can I do this?
The first argument of t() is a literal string, not a dynamic string. If you use a dynamic string, that will be translated only if it matched a literal string another module passes to t().

For example, if I use the following code, the string will be shown translated (when a translation for the currently enabled language exists), as 'E-mail address' is used as argument of t() from user_account_form().

  $label = 'E-mail address';

  $form['mail'] = array(
    '#type' =&gt; 'textfield', 
    '#title' =&gt; t($label), 
    '#maxlength' =&gt; EMAIL_MAX_LENGTH, 
    '#required' =&gt; TRUE, 
    '#default_value' =&gt; '',
  );


If the values contained in that database field are limited to specific values, then you can add the following code to the module you are using.

function mymodule_translated_strings() {
  $strings = array(
    t('first value used for the database field'),
    t('second value used for the database field'),
    t('third value used for the database field'),
  );
}


The function doesn't need to be called; it is required only to have a call to t() for each literal strings that contain one possible value of that database field. Clearly, this is convenient if the database field can assume values which are restricted to a small set of values. If the values assigned to the database field are input from users, then this approach is not possible, since the users can (theoretically) enter any value.

For the other cases, the Internationalization module could be helpful. As described in Translating user-defined strings (module developers), i18nstrings() is the function that should be used in this case.