One of the great things about using an out-of-the-box solution like WordPress is that you can get something up and running pretty quickly. That’s been one of WordPress’ strengths over the years. However, if you’re building sites for other people then sometimes parts of the generic-ness seep through and detract from the overall feel of the solution. Specifically – terminology that is great in a generic solution isn’t always helpful in a custom, or specific solution.
None of this is a criticism of WordPress, but as you start building larger, or more complex sites you’ll probably want to start smoothing off some of these rough edges, and make sure the language of the site (frontend or admin side) makes sense in the specific context of the site you’re working on.
That’s something I come across frequently in my day job as a Drupal developer. Fortunately Drupal has the excellent String Overrides module. This lets you specify the current string, and a replacement, and will change the text whenever that string is used, with the caveat that the original string has to be passed through Drupal’s translation function t().
When someone recently asked me how to change some text in one of my own WordPress plugins – my first suggestion was this exact same approach. After all, all of my Premium plugins use translatable strings, and suggesting to someone that they should create a translation file just to change one or two strings for their needs has always seemed a bit excessive. So – I had a hunt around the WordPress.org repo for something similar, but couldn’t really find anything that did the job.
Figuring it’d be something fairly simple to achieve I set out to knock up a plugin that did the job. So next time you need to quickly change a string in WordPress, or a plugin you’re using – don’t hack it in the plugin – or in WordPress core, leaving your client unable to upgrade, give “Say What?” a go:
February 19, 2014 at 2:24 pm
This plugin is just what I needed. Thanks! I think a lot of people could probably benefit from it, but perhaps it doesn’t rank in searches because of the creative name?
February 19, 2014 at 10:39 pm
Hi Ken,
Glad you’re finding it useful – you’re probably right about the name – I’ll see if I can’t add something into that.
February 26, 2014 at 9:02 am
Hello,
Great plugin !
I’m testing the plugin, and I would like to know if we can translate the new strings ?
After adding some strings, they do appear on front at the right places, but I can’t see them in my WPML string translation panel. (and thinking about it, it seems quite normal, since we don’t have the __() call in a specicic template) …
Would you know how to replace a specific string AND its translation ?
Thank you !
February 26, 2014 at 9:33 pm
Hi,
I’m a bit confused by your comments. The plugin will only work with translatable strings, it won’t work if your strings aren’t wrapped in __(), _e() or one of the other translation functions. Can you give me some more details on precisely what you’re trying to achieve?
March 13, 2014 at 10:08 pm
Thank you for your answer.
Let’s say I have a translatable string in a template :
__(“my friends”)
I can translate this string in french with .mo files and I do it :
mes contacts
Now, I would like to replace “friend” with “my contacts” in english too.
But when I use your plugin, I end up with “my contacts” in english AND in french.
Is this normal ?
Thank you again !
March 14, 2014 at 10:00 am
Hi,
If you’re comfortable preparing .mo files then I’d suggest just doing that for en_us. That said I’m not sure why you’d get a translated string AND a replaced one – you should get one or the other.
March 14, 2014 at 12:08 pm
Yep, I’ll try the .mo file, that was my next move planned, thanks for the hint 🙂
About the need, I don’t know, it seems obvious to me that I should be able to actually translate the string that I just changed, otherwise I see no reason to use a translating system.
March 14, 2014 at 8:10 pm
I guess I’m a bit confused about why you’d want to change the string twice? You’re either “translating” it – in which case you can translate it how you like, or you want to change the original. I’m a bit confused about why you’d want to “change” the original, and then “translate” the changed string?
March 2, 2014 at 6:31 am
Hi Lee,
I am very hopeful that your Say What? plugin will solve my third-party-plugin-text-change woes. As an example, I am trying to change the string “Input your name here” in the following plugin function.php code:
array(esc_html(Class_Project::getInstance()->conf(“seo_step_1”)), __(“Input your name here”, “classboard”)),
I wrote the string “Input your name here” in the “Original string” field in your Say What? plugin (i.e. on the text changes page). I then entered “Please type your name here” (i.e. the new text that I wish to use) in the “Replacement string” field. I left the domain field blank because I wasn’t entirely sure what to input. After clicking the “Add” button, I didn’t notice any corresponding changes on my test website. I suspect that I am not using your cool plugin correctly. Can you provide me with some guidance on the proper inputs for the “Original string” and “Replacement string” fields?
Many thanks,
Sean
March 2, 2014 at 9:06 am
Hi,
In the example you quoted, you need to set the domain to ‘classboard’ (without the quotes) for it to be picked up.
March 2, 2014 at 4:34 pm
It worked! Absolutely amazing! Your plugin has saved me countless hours of editing.
Many thanks,
Sean
March 2, 2014 at 6:26 pm
Great, glad to hear it. If you’ve got five minutes, please consider leaving a review on WordPress.org:
http://wordpress.org/support/view/plugin-reviews/say-what
March 2, 2014 at 9:25 pm
Absolutely! I just finished posting the review on WordPress.org. Thanks again for your help.
March 14, 2014 at 8:12 am
Lee,
First of all great work. I do Drupal development as well and I’ve used the String Overrides module a bunch of times. So I was excited to find somebody implementing a similar plugin with WordPress.
That said, it appears that your plugin doesn’t support multi-byte character sets.
If I enter Original String – “Post Comment”, Replacement String – “??????” (Japanese), I get a string of question marks as the new string after saving.
Is this simple to fix?
Thanks.
March 14, 2014 at 8:17 am
btw
I can use Japanese text elsewhere on the site without any problem.
March 14, 2014 at 9:57 am
Hi Paul,
The honest answer is that I have no idea! The plugin doesn’t do anything specific that should stop it working – but maybe there’s something extra I need to do to enable them?
If someone has any pointers happy to take a look.
March 14, 2014 at 10:08 am
Usually with this kind of problem (aka mojibake) it’s because the code (or maybe database schema) hasn’t been set up as UTF-8.
March 18, 2014 at 12:26 am
The code doesn’t do anything to force a specific encoding. Does the data that gets saved to the database look correct? Does changing the collation of the database help?
March 17, 2014 at 2:31 pm
I’ve tried a bunch of different ways to replace tax with fees and no luck (a range of different domains, strings and replacements.) Any ideas would be appreciated
March 18, 2014 at 12:24 am
Hi,
You’ll need to find the original string in the code – and check what the string is, and what the domain is. There’s some examples of the sort of thing you’re looking for here:
http://wordpress.org/support/topic/how-exatly-to-use-the-plugin#post-5284099
or here:
http://wordpress.org/plugins/say-what/faq/
December 24, 2015 at 12:21 am
Thank you very much!!
This is What I need for my WordPress ?
Greetings from Barcelona