BLOG
Website Translation Best Practices

Ensure your website is accessible on a global scale

Use the tools built into WordPress

Translation can be a bit of a grey area in web development. You want your site to be as accessible as possible, but how do you go about it? Thankfully, WordPress comes with various tools to translate your site into just about as many languages as you want. Even if you only target users from a specific country, there can be value in taking the time to make your site readable to those who speak different languages within that country, or neighboring countries where your products or service may still be an option.

Text domains for plugins

Most big plugin and theme developers come with translations already included. They do this by combining the way they have their files display content, and a folder of files specifically designed to translate that content into different languages. Some of the biggest developers, like those for WooCommerce, have professional translations done for their solutions as well. But even a translation done through Google Translate is better than nothing, and can often suffice in smaller-scale projects especially.

This is ideal for performance, since the files live directly on the site and can interact with the user’s browser to serve the proper language. But what can you do if the developers don’t provide the language need? Good news: you can add your own files to the mix as well! Using a tool like Poedit empowers you to find these strings called out in the code, and either import or manually add translations on a per-line basis.

Adding these domains to custom plugins

Developing your own plugin, or just curious about how this is done? Plugins and themes allow you to set a “text domain” in their configuration. This lets programs like Poedit know how to categorize the text, and enables that same software to target the strings throughout the code.

All you have to do while developing is, whenever your code echos or renders readable content that appears on the frontend or admin, put that string inside a function that allows you to specify a text domain. There’s a WordPress function that’s just two underscores that allows you to specify a text domain for the content within, like:

echo __( 'Some custom text.' , 'customdomain');

There are other options for this that include security escaping, too. esc_attr__() and esc_html__() are a couple of examples, and there are even functions that specify that the content should be echoed like esc_attr_e(), esc_html_e(), and even just _e() if you don’t need any escaping done. Use whatever fits best for the content you want to call out for translation capabilites.

Other solutions, as well as page content

While the above methods with dedicated files are certainly ideal, they’re not always possible. There’s the chance that the developers of the solution you chose to use didn’t develop in this way. This method also doesn’t cover absolutely everything, as you may want the actual content or your pages or post to be translated as well. Thankfully, there are still solutions for translating this content as well!

While it’s not as smooth and light for performance, plugins like WP Translate and Loco Translate can target any string on the site whether it’s in a plugin or just the content on the site. If you’re opting for Google Translate, there’s even a plugin called GTranslate that can run essentially the entire frontend of your website through that handy tool, though it’s not as conducive for any manual corrections or entries. These plugins then allow you to translate that content, either automatically or manually, and serve the altered content depending on where your users are visiting your website from.

Need help translating getting your site translated? Don’t hesitate to reach out to us for assistance! We’ve worked with clients around the world, and would be happy to help make your site accessible to as many people around the globe as possible.

RELATED BLOG POST