Home

Lullabot

Lullabot Ideas

We know stuff. We empower you to know stuff too.

On Site Drupal Training

We'll come to you! Graduate from your own on-site courses and become Drupalistas!

Replace any string in Drupal (5/6), without Locale module

Article by Nate HaugFebruary 2, 2008 - 1:48am

During a recent Lullboat podcast we mentioned a new feature in Drupal 6 that allows you replace any string in Drupal without using Locale module (thanks Moshe!). Faithful podcast listener Rob Loach took it upon himself to write the String Overrides module that lets you accomplish this task with ease in Drupal 6.

While Lullabots were lamenting the fact that this feature was never in Drupal 5, we realized that it actually could be accomplished. An hour after undertaking the project, the patch was submitted to the String Overrides queue and committed shortly afterwards.

String Overrides accomplishes this in Drupal 5 by imitating the Locale module, and without hitting the database (since variables are cached and pulled up on every request anyway). Since this essentially a hack for Drupal 5, you cannot combine it with Locale module or languages other than English. Here's the key code that makes this possible:

<?php
/**
* Fake the locale function.
*/
if (!function_exists('locale')) {
  function
locale_supported_languages($reset = FALSE, $getall = FALSE) {
    return array(
     
'name' => array('xx' => 'String Overrides'),
     
'formula' => array('xx' => ''),
    );
  }

  function
locale($string) {
    static
$strings = array();
   
$strings = variable_get('locale_custom_strings_en', array());
    if (
$strings[$string]) {
        return
$strings[$string];
    }
    else {
        return
$string;
    }
  }
}
?>

Basically String Overrides pretends that it is Locale module and does the translation without hitting the database. Because it uses the same variable format as the Drupal 6 core feature, when the site upgrades to Drupal 6 the hack is no longer necessary and the site becomes compatible with Locale module again. For anyone needing to change just a few words on their Drupal site, String Overrides is a great solution.

In Action

stringoverrides1.png

stringoverrides2.png

Comments

moshe Weitzman (not verified) on February 2, 2008 - 6:49am

nice one

thats wicked clever. very nice work.

Joshua_cohen (not verified) on February 2, 2008 - 12:14pm

Awesome!

Thank You Thank You Thank You!!!! No more core/module hacking needed to alter a simple line of text.

Josh

Matt V. (not verified) on February 2, 2008 - 5:30pm

Excellent Timing!!!

Just last night, I turned off the computer frustrated at how hard it was turning out to be to change "Comments" to be called "Reviews". I was debating between the Locale module route, versus using the Node comments module, versus setting up a CCK/Viewfield solution. I just tested the String Overrides module and changed everything I needed in about 30 seconds. Thank you!

fajerstarter (not verified) on February 4, 2008 - 7:13am

Clever indeed!

That's such a cool idea.

peach - all drupal themes (not verified) on February 4, 2008 - 8:06am

nice little hack. I always

nice little hack. I always thought the locale module + custom language was overkill to just change a few textsnippets.

Herb (not verified) on March 3, 2008 - 6:18pm

Thank You!!

I was using the locale module with a custom language and almost considered disabling it to improve response times. Your module does everything I needed, with a lot less overhead!

merde (not verified) on June 4, 2008 - 9:59pm

Good

I just tested the String Overrides module and changed everything I needed in about 30 seconds. Thank you! merde

Anonymous (not verified) on June 23, 2008 - 6:52am

Where does this code go? In

Where does this code go? In a template.php file? Thanks very much.

Anonymous (not verified) on July 25, 2008 - 9:03am

String overrides

Just beautiful.Needs to be in core no matter what!

spunkz25 (not verified) on September 2, 2008 - 4:50pm

Damn!

Good Job dude...

Max_Headroom (not verified) on September 15, 2008 - 9:54am

Kudos!

One of those small-but-so-handy modules.
Thank you!

will hall (not verified) on December 13, 2008 - 10:19pm

wow

wow that is the coolest module i have ever come across. thanks to the author and for spreading the word about it.

Andy Laken (not verified) on March 7, 2009 - 11:57pm

O HAI! Iz imitatin teh lo-cal mod00lz! An not eated dem!

Im in ur dr00ple 5, imitatin ur localz, overraidin ur stringz, srlsy! wtf!

kthxbai!

fallecs (not verified) on March 18, 2009 - 7:24pm

Love it

BRILLIANT!

thank you

That concludes this comment.

JeniferTucker (not verified) on March 30, 2009 - 4:11pm

Using stringoverride for translating language

Is it possible to use stringoverride to change a menu from "About us" to "Sobre nosotros"? I can translate menu items, but not the main menu block heading. Have tried just about everything and unable to solve this problem. I've got Drupal 6 installed with Locale, menutranslation all plugged in, but still no joy :-(

Example

About us
* Who we are
* How to find us

swtich to Spanish and the menu stays the same with the items changing

About us
* Quienes somos
* Cómo llegar

Anyone have any advice?

azhar (not verified) on April 7, 2009 - 3:11am

need help for string override

Hi,

I have a local menu task called products i want to check

if ($node->category =='restaurant'){
print 'Restaurant';
}else{
Print 'Products';
}

i want to use this if in string override can any one tell me how can i do this ....

Thanks,

Architeck (not verified) on August 11, 2009 - 1:26pm

I am looking to do something

I am looking to do something very similar.

I have submitted a feature request to the sting overrides project
http://drupal.org/node/541154

Not sure how to add this functionality,

Maybe the lullabots will lend a helping hand on this one!

Thanks

About this 'bot

Nate Haug

Nate Haug adds a dash of design to Lullabot. He received degrees in both a Fine Arts and Computer Science from Truman State University, creating the perfect bridge between the technical and aesthetic. Detail is his obsession, so if you know what you want, Nate will deliver your desire.

Nate joined Drupal development in 2005,...

more

Recent

Drupal Voices 160: Moshe Weitzman on Page Rendering in Drupal 7

Podcast 9.02.2010

Drupal Voices 159: John Albin Wilkins on Drupal 7 Theming

Podcast 9.01.2010

Drupal Voices 158: Emma Jane Hogbin on PHP for Designers

Podcast 8.31.2010

Command Line Basics: More Editing with Vi/Vim

Video 8.31.2010

Lullabot's Back to School Sale

Blog 8.30.2010

Popular

Drupal Voices 159: John Albin Wilkins on Drupal 7 Theming

Podcast 9.01.2010

Drupal Voices 160: Moshe Weitzman on Page Rendering in Drupal 7

Podcast 9.02.2010

Drupal Voices 158: Emma Jane Hogbin on PHP for Designers

Podcast 8.31.2010

Announcing BeautyTips, a jQuery Tooltip Plugin

Article 10.20.2008

Install a Local Web Server on Mac OSX

Video 7.15.2007
 
  • Home
  • Services
  • Events
  • Ideas
  • Store

Connect the Bots:

Twitter Facebook YouTube blip.tv All Posts Newsletter
  • Ideas
  • Blog
  • Podcasts
  • Videos
  • About
  • Contact
  • Jobs
  • Services
    • Training
  • Events
    • Training Workshops
    • Other Events
    • Conferences
    • Calendar
  • Products
    • Videos
    • Books
    • Swag
  • Ideas
    • Blog
    • Podcast
    • Videos
  • About
    • Philosophy
    • Team
    • Presskit
  • Contact
    • General
    • Work Inquiries
    • Mailing List