Tip: Translating complex strings in WordPress
Posted on
This might be outdated!

Very often i see people that don’t really bother about translation when they work on a WordPress project (theme or plugin), and it’s really annoying when you want to use the code with another language. And what happen is that when people deal with internationalization, they don’t do it that well… So this little tip is just to remind you that when you need to translate strings that contain variable elements, there’s a way to it simply, just have a look at the code above:
About the author
Related Posts
4 comments
Leave a Reply
You must be logged in to post a comment.
How can we handle translated strings with html in it ? For example, a header title with a span inside to apply some styling for a part of the text ? Is it necessary to translate them separetely ?
Actually this is a bad practice, translatable strings shouldn’t contain HTML tags. I encourage you to have a look to these functions: esc_attr__(), esc_attr_e(), esc_html__() and esc_html_e()
Remi, what do you think about translating wordpress strings with localization tools? I would totally recommend https://poeditor.com/ as a good method to do it. Except for its user-friendly interface and helping features for translators, it also has a plugin for wordpress that allows you to transfer your translated strings directly on your website. What do you think?
Hey, yes i agree, POedit is undoubtedly the best solution to translate themes or plugins.