How to Make a WordPress Plugin Multilingual

You are here : Home / How to Make a WordPress Plugin Multilingual

Multilingual wordpress plugin development is super easy and increase your target audience. At flippercode, our developers strictly follow multilingual approach in any type of wordpress development.

Instead of defining ‘Internationalization’ or ‘Localization’ words theoretically , I’d like to develop a multilingual plugin from scratch so you can understand this perfectly.

Create “Hello World!” Multilingual Plugin

Assuming you have little idea about wordpress plugin development, to start off, below is simple plugin code which create two navigation and display a dummy output.

If you change your wordpress language using define(‘WPLANG’, ‘hi_IN’); in wp-config.php , this plugin doesn’t have any affect because its not multilingual compatible wordpress plugin.

Below are simple changes we’ll do in this plugin to make it multilingual.

    • Define Strings using __() or _e() Functions: Whenever you define a string or label of input element or paragraph, always use __() or _e() functions.To output a translated string, use _e($text,$domain) function, here $domain is the key which used to fetch translated string from languages files. This is known as ‘text domains’ which should be unique for a plugin.

      here our unique key is ‘text-domain’ which will be used throughout the plugin.

If you don’t want to output a translated string, use __($text,$domain) function.

So by using these two functions, we’re going to modify our plugin.

To make navigation multilingual, replace :

With :

To make contents multilingual, replace :

with:

  • Loading language files: When plugin loaded, we need to load the required language file according to selected languages in wp-config.php. WordPress handles this with help of load_plugin_textdomain() function.Use ‘plugins_loaded’ action and call load_plugin_textdomain() function when plugin loaded.

    Here assume that all languages files located in languages folder within plugin folder. So below is complete source to make above plugin a multilingual.

Create Languages Files in WordPress

To create languages files in wordpress, we use poedit software. Here are easy steps to create a .po file for your plugin on Creating POT Files.

Below is screenshot of .po files for english and hindi languages.

language files How to Make a WordPress Plugin Multilingual

Did you notice file names here? It should have {domain}-{language_code}_{country_code}.po format. Here our {domain} is ‘text-domain’, {language_code} is ‘hi’ (Hindi) and {country_code} in ‘IN’ (India) so file name is ‘text-domain-hi_IN.po’. Here is complete list of Languages Codes and Country Codes.

How to Test a Multilingual Plugin

‘English’ is default language for wordpress but you can change its language easily in following steps. Here we’re going to convert our default language to HINDI which locale code is ‘hi’ and country code is ‘IN’ .

    • Step #1 : Open wp-config.php, change define(‘WPLANG’,”) to define(‘WPLANG’,’hi_IN’)
    • Step #2 : Make sure ‘hi_IN.mo’ and ‘hi_IN.po’ exists in ‘wp-content/languages’ folder. If not exists, here you can download languages files

Note that your plugin language file located at ‘your-plugin-path/languages’ folder and wordpress translation file located at ‘wp-content/languages’

  • Step #3 : Refresh your wordpress page and you should see wordpress options in hindi language.

Conclusion

By applying some small steps, you can make your plugin or themes multilingual. First time, you create a english version .po file and distribute that to translator. You can place any number of languages files in your languages folder. More languages you’ll provide, more download you get on codecanyon or official repository.

 How to Make a WordPress Plugin Multilingual

Flipper Code

We have been building WordPress Plugins at flipper code since 2008. We follow wordpress coding standard that ensures we deliver the excellent wordpress plugins and services.

More Posts - Website

Follow Me:
twitter How to Make a WordPress Plugin Multilingualfacebook How to Make a WordPress Plugin Multilingualgoogleplus How to Make a WordPress Plugin Multilingual

Customize Product according to your requirements?

We will be glad to discuss any of your needs related to our wordpress plugins . if any of functionality you'd like to see in products, you can reach us by via email hello@flippercode.com.