What Is “printf” in BuddyPress?

There are “printf” statements all over the BuddyPress default theme. What do they mean?

Today, I decided to invest an hour into finding the answer to that question. Here is my answer.

In short, “printf” is php code used to help make themes display words and phrases from other languages. For a long answer and how-to, read this.

Here’s an example, in the BuddyPress default theme’s footer.php file, you will find the following line of code:

  
printf( __( '%s is proudly powered by WordPress and BuddyPress', 'buddypress' ), bloginfo('name') );

If you look at line #2963 in “buddypress –> bp-languages –> buddypress.pot”, you will see the same code as above.

Basically, these printf statements give us a central location to change certain “special” words and phrases across a BuddyPress website. For example, you might want to change all instances of “Login” to a different word (or language). You might want to change “Groups” to “Communities”, as the Custom Groups Name plugin does.

I am a beginner at this printf stuff, and that is as simple an answer as I can give right now. All you .pot and .mo gurus out there, please let me know if I misspoke at all. 🙂

Thanks!

4 Comments

  1. Julio Sepia on April 11, 2010 at 7:51 pm

    Actually, “printf” itself doesn’t do any language stuff. It’s just a PHP function that prints things on the screen, just like the “echo” function. Many programming languages have a “printf” function to output text.

    The function that allows for language translation is the one that goes inside the printf. Yes, that’s a function, the __() function. What it does is translate whatever text you put inside and feed it to the printf.

    The code you posted could also be written as:
    _e(‘my text’, ‘file);
    which translates and then prints ‘my text’.

    Here you can learn more about how internationalization works in WordPress/BuddyPress: http://codex.wordpress.org/I18n_for_WordPress_Developers

    About the .pot and .mo stuff, it’s not that hard; using a program like PoEdit to makes it really easy to work with language files.



  2. Toby on April 12, 2010 at 9:01 am

    Thanks for the clarification, Julio!



  3. John James Jacoby on April 22, 2010 at 1:23 am

    We primarily use the printf and sprintf functions to provide variables within the core BuddyPress phrases that we can later fill with dynamic data.

    Stuff like user names and page numbers are great examples. The string may be something like:
    %s and %s are now friends
    …and what we’ll do is figure out which two user names just became friends, and put a user name where each %s is.

    %s means string
    %d means integer

    Then, when a pomo needs to localize that string, it can turn it into:
    %s y %s son amigos
    …and not need to all sorts of text replacement surgery to do it.

    Hope that helps! 😀



  4. ZZTop on June 24, 2010 at 12:49 am

    Jes, but it faled to translate “Name” on my site…everything else is translated but when looking at his profile my user see plain old english “Name” in stead of correctly compiled translation from mo file….how to fix that?



RSS From Toby’s Blog

  • WordPress Maintenance Checklist: Keep Your Site Running Smoothly
    Discover the essential tasks for effective WordPress maintenance and ensure your website runs smoothly and securely with our comprehensive guide.
  • Why We Don’t Automate Our WordPress Hosting Business
    There are some great platforms out there to automate your website hosting biz: But we don’t use any of them. Here’s why: Hosting companies only get worse over time. Over the years, I’ve hosted websites on a bunch of platforms: All of these hosting companies share one thing in common: Over time, they all got…
  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…

More posts from themightymo.com

Reorganize Your WordPress 2.7 Admin Panel with Fluency 2.0

By | February 6, 2009

Yesterday I discovered the new Fluency 2.0 plugin for WordPress 2.7.  It does a fantastic job of cleaning up the admin interface and makes the back-end WordPress experience much better for users.

We Now Offer Search Engine Optimization!

By | February 2, 2009

We have just teamed up with one of the web’s finest search engine optimization gurus, Greg Cryns, and will now be offering his services to you, our customers! For you, our customer, this means that we now have added expertise in driving targeted traffic to your website. Greg has over a decade worth of search…

Adobe CS4 Flash MN Presentation at FlashMN

By | October 14, 2008

Below are my notes from tonight’s FlashMN meeting starring Dustin Tauer.  The presentation focused on the new features of Adobe Creative Suite 4. Illustrator CS4 Can create multiple art boards.  So, if I wanted to use artwork for the front and back of t-shirt, I would create 2 art boards (up to 100).  There are…

RSS From Toby’s Blog

  • WordPress Maintenance Checklist: Keep Your Site Running Smoothly
    Discover the essential tasks for effective WordPress maintenance and ensure your website runs smoothly and securely with our comprehensive guide.
  • Why We Don’t Automate Our WordPress Hosting Business
    There are some great platforms out there to automate your website hosting biz: But we don’t use any of them. Here’s why: Hosting companies only get worse over time. Over the years, I’ve hosted websites on a bunch of platforms: All of these hosting companies share one thing in common: Over time, they all got…
  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…