How to localize and translate a WordPress plugin – An in depth guide for plugin developers

How to localize and translate a WordPress plugin – An in depth guide for plugin developers

When developing a plugin, it’s always good idea to make it translation ready as it could additionally reach audiences who do not use English as their first language. If you were wondering how important a translation option is, you can check the repository and see that every single popular plugin is available for language localization. You will find this option is available with UpdraftPlus, MetaSlider, WP-Optimize, Contact Form 7 and WooCommerce, as well as many more. These are some of the most popular plugins available and are coded in a way that allows anyone to translate them easily into their native language.

The purpose of this blog is to demonstrate to our readers how they can code a plugin so that it will be localized and translated into any supported WordPress language. For example, if we wanted to translate a plugin into French, the following steps will allow plugin translation and also make it ready for all supported WordPress languages.

Getting Started

When creating a plugin, we should make sure that we load the plugin text domain. WordPress provides this function:

load_plugin_textdomain()

This code will load the plugin’s translated strings. It may seem a little confusing, but keep reading and we’ll explain how it works shortly.

First, let’s take a look at how to add this function to our plugin code. In your plugin folder, create a directory called ‘languages’. Next, add the below code to your plugin main file.

[php]
/**
* Load plugin textdomain.
*/
function plugin_load_textdomain() {
load_plugin_textdomain( ‘udp’, false, basename( dirname( __FILE__ ) ) . ‘/languages/’ );
}
add_action( ‘init’, ‘plugin_load_textdomain’ );
[/php]

In the above code, we keep the first parameter (domain) as ‘udp’. We should keep this domain name as per our name of the plugin. The second parameter defaults to false. The third parameter is the path of our ‘languages’ directory. This code keeps our translation files ready on the WordPress initialization.

Use of __() and _e() Methods

As we are aiming to make our plugin available in all languages, we should wrap all our plugin text inside either:

__() or _e() functions.

It is very easy to use these methods. Both methods work exactly the same but there is a rule for using both.

In our plugin code, we normally have two types of text. The first is wrapped in HTML directly and the second is displayed using PHP echo function. Below are examples of both types:

Type 1
[php htmlscript=true]

My Plugin Title

[/php]

Type 2
[php]

[/php]

The general rule is that if you are printing text using PHP echo then you should wrap text in the following code:

__()

If it is in HTML then use the code:

_e().

The above code should be written in the following way:

[php]

[/php]

and

Type 2
[php htmlscript=true]

[/php]

As can be seen in the above examples, the second parameter was written as ‘udp’, which is our plugin text domain. By using this domain, it will allow us to later translate our text into any language. This is how other plugins make their plugins translation ready.

If you wish, you can check our plugin:

UpdraftPlus

If you search for the text domain ‘updraftplus’, you will see how our plugin’s text is wrapped inside __() and _e() functions.

Create a Sample Plugin

The next stage is to create a sample plugin with the some text so we can test our translations. First, create an ‘udp’ folder in your plugin directory. Inside this folder create the file: udp.php and the folder languages. Next, add the below code to the plugin file.

udp.php

[php]

}
[/php]

Create the Translation Files

To generate our translation files, we will use the following translation editor software:

POEDIT

Translation files (.po and .mo) contain the string to translate and the translated string. While creating the .po file we need to save it in ‘{domain}-language code’ format. In this example, the file will be udp-fr_FR.po.

Next, install the POEDIT software on your system. This software is available for all platforms and can be installed on Windows, Linux or Mac.

Once installed, open POEDIT and go to File->New, where we will enter our language code in the window prompt.

Click on the ‘Save’ icon, after which, the file explorer will open. Head over to the plugins languages directory and save it as the following: udp-fr_FR.po.

Now we are able to add the French translation for our plugin text. To do so, click on the ‘Extract from sources’ section.

This will open a catalog properties popup. We now need to configure the three following tabs: Translation Properties, Source Paths and Source Keywords. In the Translation Properties tab, add our domain ‘udp’ as the project name. Source Paths will be our plugin folder and we will add ‘__ and _e’ inside Source Keywords.

If you have multiple folders inside the plugin, then we will need to choose each directory individually.

After selecting the plugin folder you should see ‘.’ in the Paths section. Repeat the same process for other folders inside your plugin directory if necessary.

Under the Source Keywords, click on the + icon and add ‘__’ and ‘_e’ as a keyword and click the OK button.

In the next window, under Source text, you will have all strings available to translate from your plugin. Choose the string one by one and add your French translation to the string.

Once you add all translations, click on the Save icon. This will automatically save all your string translation in your udp-ft_FR.po file. Your .po file will now contain the following code:

[php]
#: udp.php:24 udp.php:25
msgid “UDP Setting Page”
msgstr “Page de configuration UDP”

#: udp.php:37
msgid “My Plugin Title”
msgstr “Titre de mon plugin”
[/php]

Test Our Plugin Translation

We have now completed the task of creating .po and .mo files for our plugin. Now it’s time to test our plugin and check the French language translation.

First, download our language file from the following address:

WordPress Language repository.

For the French language, the path is as follows:

https://i18n.svn.wordpress.org/fr_FR/trunk/glotpress/.
fr_FR.mo and fr_FR.po

Download files from this link and store it in the wp-content/languages directory. Create the ‘languages’ folder, if it does not already exist.

Next, we need to change the default language of our WordPress installation. Open the wp-config.php file and add the language as follows:

[php]
define(‘WPLANG’, ‘fr_FR’);
[/php]

Now if you go to the dashboard, your plugin should be displaying in the French language.

In conclusion

Creating a localized translation for your WordPress plugin can seem a little daunting and complicated at first. However the potential benefits of offering large non English speaking countries like Brazil, France and Germany your plugin in their native language can help open your plugin up to a whole new, appreciate audience. While it may seem like a lot of work, the rewards could be considerable.

The post How to localize and translate a WordPress plugin – An in depth guide for plugin developers appeared first on UpdraftPlus. UpdraftPlus – Backup, restore and migration plugin for WordPress.

Getting the best from your support request

Looking for support?  Please go here: https://updraftplus.com/support

Can you remember the last time you had to contact customer support? It probably wasn’t the most thrilling experience. It’s bad enough when something goes horribly wrong and when you struggle to get the right kind of help you need, it can be very stressful.

So here are tips to make it all as painless and efficient as possible:

Find the Proper Channel

Make sure you are contacting the right place to get help. Firstly, make sure you read through the FAQ section, which address the most common concerns.

Failing that, double check that you have the correct phone number or e-mail address to save delays in getting help. For example, when seeking help with a WordPress plugin, you should submit a support request from the forum on the plugin page. But if you have the Premium version of the plugin, you should seek the Premium support channel. Posting about a paid plugin on the WordPress forums is against the community guidelines, which means we’re not able to help even if we wanted to.

Communicate Effectively

It’s vital to express your problem as clearly and concisely as possible. This isn’t easy when you’re stressed, but taking a few moments to plan out your message means your problem can be dealt with more efficiently, without the need for endless back-and-forth communications.

  1. Number your Points – If you have multiple issues, or need to explain what’s happening in order, number them in a list.
  2. Anticipate the Answer – Don’t wait for a reply if you can guess what the solution might be. Instead, tell the Support Member what you think might be causing the error and offer as much supporting information as possible.
  3. Be clear and concise – Use as few words as possible. Re-read your message before sending to ensure it’s clear and concise.

Create a Test Scenario

The easiest way to show support what is happening is to demonstrate it, either through a step-by-step description or through a screenshot/ screencast. If the issue is on your website, try creating a test page to isolate the specific issue- and don’t forget to share the link!

If you can’t share your website because it’s still in development, you could create a temporary site and share that with us. Poppy Life is a great resource for this.

Provide Technical Details

Finally, provide as much technical information as possible. Because your issue may be unique, the more we know, the more likely it is we can help you. Provide answers to as many of the relevant questions below:

  1. What operating system are you using? Windows? Linux? Mac?
  2. What browser are you using? Chrome? Firefox? Does it occur in different browsers?
  3. Do you see any errors? Usually you will see errors on screen or in a console window. Learn how to find errors. One place might be in the developer tools.
  4. Can you provide the PHP version, server information (Nginx or Apache?), and any other specifics about your server?

Keeping these tips in mind will hopefully save you time and frustration. Technical problems can be a headache, but submitting a decent support request can make all the difference to how efficiently and effectively they’re resolved.

Below are a couple different examples of support requests to give you an idea of what to aim for- make sure you aim for something like the second one!

Bad Example

Dear Support,

My site stopped working after the latest update. Can you fix it please? http://example.com/

A Better Example

Dear Support,

After the latest update, I notice that when I click on the button to save my settings I am see an error telling me that the settings aren’t saved. This happens after I log in and take the following actions:

  1. Login to the admin area
  2. Navigate to the settings page
  3. Click on “preview”
  4. Change a setting
  5. Save

Do you think this is because of the changes to the preview button? If so, maybe it’s not compatible with my “older” version of WordPress? I’ve attached a screencast of the error.

I’m using Chrome on MacOS and my server is running nginx and php 7.2. Let me know if you need any further details.

Article written by Kevin Batdorf, one of the UpdraftPlus’ developers.

 

The post Getting the best from your support request appeared first on UpdraftPlus. UpdraftPlus – Backup, restore and migration plugin for WordPress.

Support channels

Hopefully a helpful link for paying customers… please do bookmark our support page, here.

Some of you have gathered various UpdraftPlus.Com emails from our communications (purchase receipts, etc.). Please don’t directly email new support requests – email is not an official channel for raising new requests. When people email, it’s too easy to miss off some of the details that we’ll then want to then ask about (e.g. what version are you running?). This results in slower service for you and inefficiency for us.

Our proper support form will take from you all the details that will help us to give you the most efficient support that we can. Please do use it whenever you need help!

David Anderson (lead developer, founder, UpdraftPlus)

 

The post Support channels appeared first on UpdraftPlus. UpdraftPlus – Backup, restore and migration plugin for WordPress.

Trouble posting support requests?

If you had a problem posting a support request using our paid customers support request form over the last 24 hours, then we apologise – please try again now. It looks like our webserver was experiencing random failures on this particular page. We are still investigating the exact cause, but the form is now working again.

Also, if you find the support form not working, then there’s always the paid customers’ support forum.

David Anderson (founder, lead developer, UpdraftPlus)

The post Trouble posting support requests? appeared first on UpdraftPlus. UpdraftPlus – Backup, restore and migration plugin for WordPress.