Last week I had a theme customer who wanted to translate some words on their website. The changes they wanted to make were small, and so I wanted a simple plugin to make the changes.
I knew that from a technical point of view it could be done easily. A filter on the gettext
hook and a check for the string, so I could have fixed it easily. But what if the customer wanted to change something else in the future? I wanted it to be self service.
I had also had a need to do something similar myself. My sites are always in English, and themes and plugins are mostly in English, but sometimes I want to change the copy so it’s more appropriate or personal to me, so I started searching for a plugin.
I found quite a few translation plugins but most were too complex. They were for translating the entire site, or setting up a multi-language site, and that’s not what I wanted. I basically wanted a back-end for the filter I mentioned before.
The closest plugin I found was a plugin called WP Override Translations, but I felt it could be simpler still. So rather than use it and move on, I spent a day rewriting it as my own plugin.
Translate Words
I named my plugin Translate Words. It has a simple table that lets you enter the word/ phrase you want to change and what you want to change it to.
- It works on the front-end and the admin.
- It translates anything that goes through the
gettext
hook, including translations. - It’s quick! The front-end code is about 20 lines long with one autoloaded database request.
Use Cases
The obvious use case is translations, but you can also use it to change text. For example changing a title from ‘Recent Stories’ to ‘Recent Articles’. This is the sort of thing that you would normally create a child theme for, or filter somehow. But now it can be done quickly and easily.
It took me a day of work but my goal with plugins is always to create something simple that will save me time in the future. I’ve wanted this for myself in the past, and now I can share it with my customers so that they can tweak the text content on my themes to their tastes. The fact it works with translated content means users can use the translation files, and still override the copy to fit their site.
Win win I think!
Credit
I should add a note about credit. As I mentioned, I forked a plugin called WP Override Translations, and through a conversation on Twitter I found out that plugin is itself a fork of Gettext override translations.
Both plugins could be used instead of mine. Obviously I think my version is better because of it’s simplicity but they do offer a couple of extra features that might be useful to you.
Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).
Link to this page
Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.