Translating the plugin to other languages
Table of contents:
- When do you need to change plugin text?
- How to translate plugin text?
- Case #1: Changing the 'Zip' and 'State' form labels
When do you need to change plugin text?
WP Full Pay displays labels and messages in US English by default.
You might need to translate the labels for many reasons, just to name a few:
- You’d like to use the plugin in a different English-speaking region (UK for example)
- You’d like to use the plugin in a different language
- Your area of expertise uses a different terminology
Does the verb “translate” sound confusing?
We refer to “translate” even when you change some US English labels to their regional counterparts, like changing Zip (US) to Postcode (UK).
There are two ways to change plugin labels:
Change the labels in the program code directly
This is not recommended as your changes would be overwritten by plugin updates.
Creating a resource file for your translations
This is the recommended way to translate plugin text. The resource file is independent of the plugin installation so it will survive your plugin updates intact.
This article describes how you can translate plugin labels by creating a resource file.
How to translate plugin text?
You need to complete the following steps to translate plugin text:
- Copy and rename the template resource file included with the plugin.
- Add your translations to the resource file.
- Convert the resource file to binary format.
- Copy the binary resource file to the plugin directory.
1. Copy and rename the template resource file
You can find the template resource file called wp-full-stripe.pot
in:
- The
languages/
folder of the plugin .zip file; or - The
wp-content/plugins/wp-full-stripe/languages/
folder of your Wordpress installation.
Copy and rename the file to wp-full-stripe-[language]_[country].po
, where:
- [language] is the two-letter ISO language code
- [country] is the two-letter ISO country code
2. Add your translations to the resource file
You can edit the .po file in a text editor, or you can use the free version of POEdit for a better user experience.
The .po file is composed of lines grouped together, each group representing the source text and translated text on a separate line. The source text is identified by “msgid”, and the translated text is identified by “msgstr”.
As an example, imagine the following .po file snippet that we’d like to translate to Italian:
msgid "Hello" msgstr "" msgid "Home" msgstr "
This is how the translation would look like:
msgid "Hello" msgstr "Ciao" msgid "Home" msgstr Casa"
If you’d like to translate only a few labels, you can delete the rest of the file. For the deleted labels, the plugin will display their default US English counterparts.
3. Convert the resource file to binary format
You have to convert the plain text .po file to a binary .mo file which will be used by Wordpress.
You can use the po2mo online tool to convert.
Make sure to correct the file name after conversion (po2mo spoils the file name).
Alternatively, you can use the msgfmt command line tool (part of the gettext distribution) to do the conversion:
msgfmt -cv -o wp-full-stripe-it_IT.mo wp-full-stripe-it_IT.po
4. Copy the binary resource file to the plugin directory
The last step is to copy the wp-full-stripe-[language]_[country].mo
file to the
wp-content/plugins/wp-full-stripe/languages/
folder of your Wordpress installation.
Case #1: Changing the ‘Zip’ and ‘State’ form labels for a UK-based website
1. Create the .po file with your translations
You’d create the following .po file with the translations. Please note that all other labels are removed since we don’t need to translate them:
msgid "Zip" msgstr "Postcode" msgid "State" msgstr "County"
2. Convert the .po file to .mo file
You can use the po2mo online tool to convert.
3. Copy the binary resource file to the plugin directory
The next step is to copy the wp-full-stripe-en_GB.mo
file to the
wp-content/plugins/wp-full-stripe/languages/
folder of your Wordpress installation.
4. Verify your language settings in WP admin
Make sure that site language is set to “English (UK)”. You can verify it on the “Settings -> General” page in WP admin: