Last updated January 15, 2013. Created by kentr on July 17, 2009.
Edited by ghazlewood, rafamd. Log in to edit this page.

Methods

  1. Edit settings.php file
  2. String Overrides module

Method 1: Edit settings.php file

Pros

  • Quick method for small number of strings.
  • Less accessible in cases where you want to retain some control even after granting administrator access.

Cons

  • English only.
  • No admin pages, requires access to files on server (FTP / SFTP / SSH). Difficult to delegate changes to non-developers.

Procedure

  1. Edit settings.php for the site in question.
    • You'll need to either download the file, edit it, and re-upload it, or edit it in place on the server. Of course, make a backup.
    • Either way, you'll probably need to temporarily change the permissions of the file and its containing folder to to give you "write access". Be sure to take note of the permissions and change them back to what they were afterwards.
    • The default settings file is in drupal_root_folder/sites/default/settings.php
  2. Look for this code at the bottom (Drupal 6):

    # $conf['locale_custom_strings_en'] = array(
    #   'forum'      => 'Discussion board',
    #   '@count min' => '@count minutes',
    # );
  3. Remove the comment marks ('#') and add string replacement assignments:

    $conf['locale_custom_strings_en'] = array(
       'Old string 1'      => 'New string 1',
       'Old string 2'      => 'New string 2',
    );

For Drupal 7 the code is the same except for an additional set of square brackets:

$conf['locale_custom_strings_en'][''] = array(
   'Old string 1'      => 'New string 1',
   'Old string 2'      => 'New string 2',
);

Method 2: String Overrides module

(http://drupal.org/project/stringoverrides)

Pros

  • Admin page for managing string replacements.
  • Uses access permissions. Easier to delegate management of replacements.

Cons

  • Yet another module to install, update, and administer.
  • Possible performance hit and more difficulty to deploy (stores replacements in the database).
  • Uses access permissions. Harder to restrict changes when you have to give administrator access to others.

Procedure

  1. Install and enable the module.
  2. Follow the instructions / documentation for adding string replacements.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Can method 1 be used with wild cards for string that contain Variable output?

'Sign up for %node_type.' => 'Sign up to get email reminders for %node_type.',
or
'Sign up for *' => 'Sign up to get email reminders for *.',
or something like that????

What is the secret sauce to making this work

--
Greg

Try placing it in settings.php exactly as it is in the code.

I discovered that the String Overrides module will work this way in one case:

Code for the specific call to t() (from the Profile Privacy module):

t('Display !field publicly', array('!field' => $form[$category][$key]['#title']))

String that I entered in the String Overrides "Original" field (exact match :-):

Display !field publicly

I used method number 1, and even after deleting the overrides, the overrides remain. Any suggestions?

Thanks

on D6, that's at admin/settings/performance.

Reason: variables in general are cached, these may be as well.

Suppose all authenticated users have Full HTML, which does not include the <i> tag.

I am trying to discourage use of italics on the site, so <em> would be styled in CSS as if it were <strong>.

We have a special trademark SFpark in which the italicized portion is not for emphasis but is purely decorative.

Would the following in settings.php produce the desired results?

<?php
  $conf
['locale_custom_strings_en'][''] = array(
  
'SFpark'      => 'SF<i>park</i>',
  
'SF<em>park</em>'      => 'SF<i>park</i>',
);
?>

or even

<?php
  $conf
['locale_custom_strings_en'][''] = array(
  
'SFpark'      => 'SF<span style="font-style:italic;">park</span>',
  
'SF<em>park</em>'      => 'SF<span style="font-style:italic;">park</span>',
);
?>

Charles Belov
SFMTA Webmaster
http://www.sfmta.com/

Hi Charles,

I'm trying to do a very similar thing on a Drupal 7 site - change a string to the italicised version wherever it appears on the site automatically (as a branding thing).

I tried the above but it didn't work, as I suspected, as it only works on interface strings (surrounded by the t() function) not content ones. Did you find another way to get this functionality?

Cheers,
Drew Robinson
@ocean

From my testing it seems that a third method is available: variable_set().

This method has the benefit of not requiring edits to settings.php, and doesn't require the use of a separate module. It also allows you to change strings programatically.

<?php
$custom_strings
= variable_get('locale_custom_strings_en', array());
$custom_strings['']['Old string'] = 'New string';
variable_set('locale_custom_strings_en', $custom_strings);
?>

This code:
  1. Gets an array of existing custom strings, or creates an empty array if no custom strings exist
  2. Adds a new custom string to the array (in this example it changes 'Old string' to 'New string')
  3. Saves the new custom strings array to the 'locale_custom_strings_en' variable

Hopefully others find this method useful.