Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Working with String Overrides in Drupal 7

String Overrides is a pretty sweet module for getting the text on your site more exactly like the client wants.  In general it works with any t function – what I didn’t realize at first is that this means it’ll override variables embedded in the t function as well.

So I was looking for some text that was on the site and initially was doing a search for a pretty long string, not realizing that within the string were several variables that were to be replaced… so by shortening the search to a few words within the string – specifically grep with the flags -H (for the filename) and -r (for recursive search within the modules directory) I got the following

grep -H -r "entities with this value set" .*
./field_analytics/field_analytics.reports.inc:    $headers = array(t('Value'), t('Number of %bundle entities with this value set', $replacements), t('Percentage of total %bundle entities with this value set', $replacements));
../contrib/field_analytics/field_analytics.reports.inc:    $headers = array(t('Value'), t('Number of %bundle entities with this value set', $replacements), t('Percentage of total %bundle entities with this value set', $replacements));

So then it was obvious – the %bundle was actually pulling in a variable and thus doing the search for what seemed like the string was failing, however doing a string override with “Number of %bundle entities with this value set” worked beautifully

String overrides working with HTML and variables in t functions

String overrides working with HTML and variables in t functions

Anyhow, this may be old news to some, but it totally saved my weekend… Aloha

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web