Localizing WordPress Themes and Plugins
It would be easy to assume that everyone on the internet speaks English. The majority of software is produced in English simply for the reason that doing so gives it a larger potential audience (or, maybe more appropriately, gives it access into the American market). However, you shouldn't assume this means everyone reads and writes English at the same level, or that non-native speakers wouldn't want software in their own language. There is a world of speakers outside of English and now is the time to tap into them.
This guide is another in the Inside WordPress series and will show how to prepare WordPress themes and plugins for localization. Not only will this open up your theme or plugin to more people, but it will contribute to the international reach of WordPress, and you'll receive the very satisfying feeling of seeing your own work in another language. A little extra effort at the start will soon pay off.
Some important points:
- You do not need to speak multiple languages yourself - localizing a theme or plugin just requires modifications to your code, not actual translation of words
- The localization process is relatively simple - there is no reason not to localize everything you create!
The guide will be written from a beginners perspective, but will take you through some fairly advanced concepts. As a theme or plugin creator it is assumed that you will be familiar with both HTML and PHP, although detailed explanations will be given at each stage.
If you are a translator you can read the sister article, Translating WordPress, which explains how to take an already prepared theme or plugin and translate it into another language.






Comments (page 2 of 3)
Jan 15, 2008 10:14 pm
Where did you get your gettext from? Are you giving the right command-line parameters to tell it to accept PHP?
Jan 11, 2008 10:20 am
John,
Thanks for the article--it got me started nicely on internationalising my plugins--but I very quickly hit a brick wall. I can't get xgettext to work on my Windows development machine. It doesn't seem to recognise PHP files at all. Someone told me the win versions were rather out of date. Do you know of any ways round this road-block? Thanks for your help.
Rob
Dec 18, 2007 6:40 pm
Thank you so much for sharing this. I would be grateful if you can cover also the bi-di languages (Arabic, Urdu, Farsi, Hebrew, etc) and how to flip and reverse the whole layout to be right to left. That would be great and I think it will add a lot to your efforts to reach broader audience.
Thanks again
Mohamed
Oct 14, 2007 9:13 am
Hello again, Jonh!
I'm making progress on the theme i18n, and it should be released soon. The almost universal
get_tips fixed most of my issues!Unfortunately, there' no
get_comments_rss_link; andget_comment_typedoesn't let us specify the strings for comment, pingback and trackback as comment_type does. I just discovered this functions (in WordPress source code) are quite simple, so I created similar ones to match my needs.I also made
sprintfand__ngettextwork together. I'll send you example code, as I believe the article could show it. I'll use the contact form, because the comment form restricts code.Oct 2, 2007 8:57 pm
About the suffix, I really can live without it. In Brazil we use it only for the first day of the month, even if (as far as I know) it's not a formal rule.
Thank you for your better-than-codex guidance! I'll try it as soon as I get some more time for the WordPress theme, and then I'll give you some feedback.
Oct 2, 2007 7:01 am
Leonard,
You were correct about the __ngettext example! The reason is that the % is being passed into a special WordPress function, not printf. The WordPress function requires % and not %d.
I don't believe WordPress translates the ordinal suffix at all, and even PHP itself says that the 'S' date modifier is for English suffixes only. It looks like you'll have to invent your own method to work around this!
Most WordPress functions have two versions - one that echos and one that returns. If you using the data inside printf then you need the return version. In the case of
comment_author_linkyou will need to useget_comment_author_link.Sep 28, 2007 10:31 pm
I'll place some extra spaces to preserve the code:
< ?php printf (__ ('%s Says:', 'aqLite'), ''.comment_author_link().'te>'); ? >And:
< ?php comment_author_link() <ci te></ci te> Says: ? >Sep 28, 2007 10:25 pm
Hello, that's me again. I'm having a hard time with the printf, because many template tags display the result directly, instead of returning to printf. In example:
'.comment_author_link().''); ?>In this line, we get comment_author_link then
' Says:'Sep 26, 2007 11:59 pm
In fact, WordPress does translate month names correctly in my blog, but not in my local test site (so that's my fault). But the "th" isn't properly translated, and neither does WordPress seem know the proper date format for each locale. Is there anything I can do about the two last issues?
Sep 24, 2007 9:44 pm
If you are using that function then WordPress should convert months. Is the locale actually being loaded? Does the locale translate the month strings?
Leave a comment