Change default strings (text) without using full translation system
Last updated on
25 January 2018
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Methods
- Edit
settings.php
file - String Overrides module
- Use
hook_boot()
Method 1: Edit settings.php file
Pros
- A quick method for a small number of strings.
- Less accessible in cases where you want to retain some control even after granting administrator access.
Cons
- No admin pages require access to files on the server (FTP / SFTP / SSH). Difficult to delegate changes to non-developers.
Procedure
- 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 give you "write access". Be sure to take note of the permissions and change them back to what they were afterward.
- The default settings file is in
drupal_root_folder/sites/default/settings.php
- Look for this code at the bottom (Drupal 6):
# $conf['locale_custom_strings_en'] = array( # 'forum' => 'Discussion board', # '@count min' => '@count minutes', # );
- 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',
);
In order to override other languages, you can do it like below. Pay attention that the input string has to be English and the output the translated new string. Multiple languages can be placed below each other in one settings.php file.
$conf['locale_custom_strings_en'][''] = array(
...
);
$conf['locale_custom_strings_nl'][''] = array( // nl Is the Dutch language code
'Old English string 1' => 'New Dutch string 1',
'Old English string 2' => 'New Dutch 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.
- The possible performance hit and more difficult to deploy (stores replacements in the database).
- Uses access permissions. Harder to restrict changes when you have to give administrator access to others.
Procedure
- Install and enable the module.
- Follow the instructions/documentation for adding string replacements.
Method 3: hook_boot() (tested with d7)
Procedure
- Implement the hook_boot()
- Use the same array as in the
settings.php
.
/**
* Implements hook_boot().
*/
function mymodule_boot(){
global $conf;
$conf['locale_custom_strings_en'][''] = array(
'Old string 1' => 'New string 1',
'Old string 2' => 'New string 2',
);
}
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion