Poedit Wordpress

broken image


Poedit needs to know what functions it must look for and get information from. In reality, gettext knows by itself what to look for in a.php file, but since WordPress uses its own wrapper functions to make our lives easier, this knowledge is no longer applicable. Fanatic web designer & photographer specialized in clean and modern Bootstrap & WordPress theme development. I continuously explore new stuff about web design and photo cameras and update MOOZ Blog on a regular basis with the useful content. The Pro version is a paid in-app upgrade that enhances Poedit with additional features and benefits: Save Time with Pre-translation; WordPress Themes and Plugins; Twig Templates; Word Count; Personal Support.

Localizing a WordPress plugin enables your plugin to reach widest possible audience. Fortunately, WordPress makes it rather simple for plugin authors (and theme authors) to ensure their work is available in many languages.

This post will go over the steps that are necessary from a plugin author's end to make it easy for others to translate a plugin. For those then wishing to translate, I will go over a program called poEdit, which will allow you to translate the plugin for your use and for others.

The Benefits of Localizing a Plugin

The more languages your plugin is in, the more people that can download and understand it.

If a plugin is popular enough, you'll have people volunteering to translate in order to adhere to a different part of the world. The hard way would be someone going through your code after each release and translating word for word. However, there is an easier and more portable way to translate: the .po file.

Poedit

With the .po file, anybody can translate your plugin as long as they are familiar with the original language. And if you make any changes to the plugin's source, a user doesn't have to dig through your code to re-translate. The translations are preserved in the .po file and all the user has to do is update the .po file in their language.

Preparing a Plugin for Localization

WordPress makes use of GNU gettext for translations. WordPress has two functions that can be called by plugin authors: _e, and __. Every time you output text to the user, you should use one of the two functions.

  • __($message, $domain) and _e($message, $domain)
  • Both the above functions take in a $message as the first argument and an optional $domain as the second. For plugin and theme authors, the second argument is not optional and should be a name unique to your plugin or theme. For example, if you have a plugin named WordPress Automatic Upgrade, you could probably use WPAU.

Best mac lip liner for velvet teddy. According to the WordPress Codex, the __ function should be used if text is going to be used in a calculation.

Loading the Localization File

After ensuring the text outputted to the user is ready for localization, you must also setup your plugin for loading in the appropriate .mo file. The .mo file is a compiled .po file, which poEdit automatically generates upon a save.

The code inside your plugin would look something like this:

  • load_plugin_textdomain($domain, $path)
  • The $domain variable is the same $domain variable you used in the __ and _e functions. The $path is relative to the ABSPATH variable as defined in your wp-config.php file. If your plugin doesn't have its own directory, you can leave the $path variable empty.

    One thing to note here is that any generated .mo files will have to have your domain as a prefix to the file. For example, if you plugin's domain is WPAU, then the .mo file would be named WPAU-de_DE.mo (assuming the translation is in German).

Using poEdit to Translate

There's already a good step-by-step tutorial on how to use poEdit to translate a plugin or theme, but I'm going to use a real-world plugin to show you the steps.

Step 1: Download poEdit

Head over the poEdit project page and download yourself a copy. The install is painless as well.

Step 2: Find a Plugin to Translate

Find your own (or another) plugin to translate. For this example, I'll be using a plugin I wrote called Ajax Edit Comments.

Step 3: Open up poEdit and go to File -> New catalog…

After the ‘Settings' dialog comes up, enter your project's name. In my case, my project is named WPAjaxEditComments. I also went ahead and gave it a UTF-8 charset.


You'll be presented with a Settings dialog after selecting File -> New catalog…

Step 4: Enter Your Plugin Path

While still having the ‘Settings' dialog open, go to the ‘Paths' tab and click the icon for new item. Assuming that your plugin resides in its own sub-directory and that you will save the .po in this sub-directory, enter '.' (this tells poEdit to scan that directory and all sub-directories for your plugin).

Step 5: Set up the Appropriate Keywords

Since WordPress uses the _e and __ functions for localization, you need to let poEdit know that is what it should look for. Click on the ‘Keywords' tab and input both _e and __ as keywords. To enter a keyword, click on the ‘New Item' icon.

Step 6: Click Okay and Let the Translating Begin

Click the 'Okay' button and save the .po within your plugin's directory. What you name the file right now is not important, but it will matter when it comes to translating.

After you have saved the .po file, a dialog will show showing all of the matches it has found.

If you do not plan on translating the plugin, you can go ahead and save the .po file and distribute along with your plugin to enable other translators.

Step 7: Translate the Plugin

Once all the matches are pulled in, it's time to translate the plugin. Simply find the text you want to translate, and add in your own language.

Poedit wordpress wpml

With the .po file, anybody can translate your plugin as long as they are familiar with the original language. And if you make any changes to the plugin's source, a user doesn't have to dig through your code to re-translate. The translations are preserved in the .po file and all the user has to do is update the .po file in their language.

Preparing a Plugin for Localization

WordPress makes use of GNU gettext for translations. WordPress has two functions that can be called by plugin authors: _e, and __. Every time you output text to the user, you should use one of the two functions.

  • __($message, $domain) and _e($message, $domain)
  • Both the above functions take in a $message as the first argument and an optional $domain as the second. For plugin and theme authors, the second argument is not optional and should be a name unique to your plugin or theme. For example, if you have a plugin named WordPress Automatic Upgrade, you could probably use WPAU.

Best mac lip liner for velvet teddy. According to the WordPress Codex, the __ function should be used if text is going to be used in a calculation.

Loading the Localization File

After ensuring the text outputted to the user is ready for localization, you must also setup your plugin for loading in the appropriate .mo file. The .mo file is a compiled .po file, which poEdit automatically generates upon a save.

The code inside your plugin would look something like this:

  • load_plugin_textdomain($domain, $path)
  • The $domain variable is the same $domain variable you used in the __ and _e functions. The $path is relative to the ABSPATH variable as defined in your wp-config.php file. If your plugin doesn't have its own directory, you can leave the $path variable empty.

    One thing to note here is that any generated .mo files will have to have your domain as a prefix to the file. For example, if you plugin's domain is WPAU, then the .mo file would be named WPAU-de_DE.mo (assuming the translation is in German).

Using poEdit to Translate

There's already a good step-by-step tutorial on how to use poEdit to translate a plugin or theme, but I'm going to use a real-world plugin to show you the steps.

Step 1: Download poEdit

Head over the poEdit project page and download yourself a copy. The install is painless as well.

Step 2: Find a Plugin to Translate

Find your own (or another) plugin to translate. For this example, I'll be using a plugin I wrote called Ajax Edit Comments.

Step 3: Open up poEdit and go to File -> New catalog…

After the ‘Settings' dialog comes up, enter your project's name. In my case, my project is named WPAjaxEditComments. I also went ahead and gave it a UTF-8 charset.


You'll be presented with a Settings dialog after selecting File -> New catalog…

Step 4: Enter Your Plugin Path

While still having the ‘Settings' dialog open, go to the ‘Paths' tab and click the icon for new item. Assuming that your plugin resides in its own sub-directory and that you will save the .po in this sub-directory, enter '.' (this tells poEdit to scan that directory and all sub-directories for your plugin).

Step 5: Set up the Appropriate Keywords

Since WordPress uses the _e and __ functions for localization, you need to let poEdit know that is what it should look for. Click on the ‘Keywords' tab and input both _e and __ as keywords. To enter a keyword, click on the ‘New Item' icon.

Step 6: Click Okay and Let the Translating Begin

Click the 'Okay' button and save the .po within your plugin's directory. What you name the file right now is not important, but it will matter when it comes to translating.

After you have saved the .po file, a dialog will show showing all of the matches it has found.

If you do not plan on translating the plugin, you can go ahead and save the .po file and distribute along with your plugin to enable other translators.

Step 7: Translate the Plugin

Once all the matches are pulled in, it's time to translate the plugin. Simply find the text you want to translate, and add in your own language.


From this screen, you can translate the plugin

Step 8: Save the Catalog

Telecharger Poedit Wordpress

Remember the $domain that was mentioned earlier in this post? What if, for example, I want to generate a Spanish translation file? I'll want to save a file with the $domain as a prefix, and the locale as a suffix. In this case, my domain is WPAjaxEditComments and my locale is es_ES. I would save my file as: WPAjaxEditComments-es_ES.

By saving the new file, I would automatically be generating a .po file that others can use, and a .mo file that can be read in through WordPress to localize the plugin.

Now if users have defined the appropriate WPLANG in their wp-config.php, their plugin's options and output text should be in their local language.


A German translation of Ajax Edit Comments (Thank you David May).

Conclusion

Localizing a WordPress plugin is a great way to reach out to a foreign audience. Localizing involves many people, including the plugin author to take the initial steps to ensure that the plugin can indeed be localized. Translators are required too, and their efforts to localize WordPress and WordPress plugins are tremendous.

References:

Poedit Wordpress Wpml

Related Reading:

Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.

Poedit 2 was released today after two years in development. The app has a refreshed interface for translating .PO files, which Poedit creator Václav Slavík said was created by a professional designer. It is also the first paid upgrade for Pro users since the app added support for WordPress theme and plugin translations in 2013.

Poedit 2 introduces direct connectivity support for WordPress, allowing developers to connect directly to the server instead of working with unpackaged plugins/themes locally.

Poedit Wordpress Tutorial


'Putting translation files on the server was the most common source of problems in Poedit (too many things can go wrong if you're not yet very familiar with WP) and this feature should help a lot with that,' Slavík said.

This release adds support for Twig templates and Timber. In the past, users had difficulty extracting strings from Twig templates, requiring some fragile workarounds. Slavík said some users resorted to setting up Poedit to treat them as Python files. Poedit 2 has a new built-in extractor for Twig.

Poedit 2 also introduces a new pre-translation feature that allows for batch pre-translation of the entire PO file at once using Poedit's online database and machine translation. After this has processed, users can then read through and correct any errors. Slavík said this feature saves a lot of time for many WordPress-related translations, such as themes, where a lot of strings are often repeated.

Poedit Wordpress Full

Poedit used to be available from the Mac App Store but is now distributed exclusively from the Poedit.net website. The latest release drops support for older operating systems and requires users to be on Windows 7 or newer, macOS 10.10 Yosemite, or a modern Linux distribution.





broken image