Tip: Translating complex strings in WordPress

by

in

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:

4 responses to “Tip: Translating complex strings in WordPress”

  1. Rémy

    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 ?

    1. 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()

  2. kress

    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?

    1. Hey, yes i agree, POedit is undoubtedly the best solution to translate themes or plugins.

Leave a Reply