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

  • How Digital Ocean Cost Us Thousands of Dollars in a Single Day
    Here’s the rub for me: My belief is that bad stuff happens, and you need to own it. Digital Ocean definitely did not own it in this case. I wonder how the original founders of Digital Ocean would have reacted had they been in charge… For example, wouldn’t it be nice if an actual human… […]
  • Where uncertainty exists, don’t order specific.
    4 Idiot Case Studies with 2 simple age-old business lessons. The post Where uncertainty exists, don’t order specific. appeared first on Toby Cryns, WordPress Trainer in Minneapolis, MN.
  • “Now THAT was a good meeting!”
    A single effective meeting can change the course of history for a company. Imagine if you could lead effective meetings EVERY DAY! You can, but it takes curiosity & practice. This article is a good place to start your journey to a more effective you. The post “Now THAT was a good meeting!” appeared first […]

More posts from themightymo.com

How to merge multiple csv files via command line

How to merge multiple .csv files via command line

By The Mighty Mo! Design Co. | May 17, 2023

Today I downloaded 29 csv files with tax information. I could import those files 1 at a time into WooCommerce, but wouldn’t it be nice if I could merge them first and then only import a single file? The unix command is simple – just navigate to the folder with all the csv files and…

WordPress Security Services

15 Best WordPress Support and Maintenance Services for 2023: Ensuring Your Website Stays in Top Shape

By The Mighty Mo! Design Co. | April 27, 2023

Small business owners and non-profit leaders know that keeping your website secure, fast, and fully-functional is critical to success.  Here’s the unspoken truth: You can either learn how to do all that tech maintenance and development stuff yourself, or hire someone else to do it. But let’s face it, doing it yourself isn’t always the…

how to set up Cloudflare whitelist for ip

How to Whitelist SEM Rush IPs in Cloudflare

By The Mighty Mo! Design Co. | April 24, 2023

Alright, I’m going to show you how to whitelist a set of IPs on CloudFlare. In our case we use SEMrush and we want to make sure the SEMrush has full access to our sites.

RSS From Toby’s Blog

  • How Digital Ocean Cost Us Thousands of Dollars in a Single Day
    Here’s the rub for me: My belief is that bad stuff happens, and you need to own it. Digital Ocean definitely did not own it in this case. I wonder how the original founders of Digital Ocean would have reacted had they been in charge… For example, wouldn’t it be nice if an actual human… […]
  • Where uncertainty exists, don’t order specific.
    4 Idiot Case Studies with 2 simple age-old business lessons. The post Where uncertainty exists, don’t order specific. appeared first on Toby Cryns, WordPress Trainer in Minneapolis, MN.
  • “Now THAT was a good meeting!”
    A single effective meeting can change the course of history for a company. Imagine if you could lead effective meetings EVERY DAY! You can, but it takes curiosity & practice. This article is a good place to start your journey to a more effective you. The post “Now THAT was a good meeting!” appeared first […]