How to translate WooCommerce Memberships
The default language for WooCommerce Memberships is English. As of November 2019, we also began shipping a Japanese translation. So what happens when your shop is en français or in italiano or auf Deutsch? Don’t worry: we’ve got a solution for you too. Here’s how to get WooCommerce Memberships to work for you in your language.
Like all SkyVerge plugins, WooCommerce Memberships can be translated. This is done with the use of a textdomain, which is a way for WordPress to know what piece of software you’re targeting for translation. We can target the text used by WooCommerce Memberships by using its textdomain: woocommerce-memberships.
Navigate to the plugin folder on your web server (wp-content/plugins/woocommerce-memberships) and find a folder called i18n. (“i18n” stands for internationalization, because it starts with i, ends with n, and has 18 letters in between.) Clicking on the i18n folder shows another folder called languages. Clicking on that, you’ll see that there’s a file called woocommerce-memberships.pot.
A .pot file is the template on which all translations will be based. The woocommerce-memberships.pot file contains all the text used by the Memberships plugin. We recommend using the free Poedit app to open, edit, and insert your own translations in a .pot file.
Translating the text
Open Poedit and then select Create New Translation.
Then, open up woocommerce-memberships.pot.
Next, select the language and locale for your translation. Let’s say you’d like to translate WooCommerce Memberships into French (from France, not Canada or any other variation). Select that language in the dropdown list. One selected, click on OK.
You’ll now see all the text strings from WooCommerce Memberships, then the (empty, for now!) translation section.
You can now start translating these strings. For example, Make a copy in French would be Faire une copie, so I typed that in the Translation box.
It’s important to note that Memberships has more than 1,000 strings of text to translate. You may not need to translate all of them. If all the site administrators are fluent (or proficient) in English, you may not want or need to translate strings related to the backend that are only visible to administrators.
Saving the file
Once you’ve finished translating, save the file using the plugin’s textdomain and the country and language code (known as the locale) for your specific version of that language. It’s important to include the textdomain, not just the locale default, so WordPress knows which plugin is affected by the translation.
I don’t want to save it just as this, which is the default in Poedit:
That wouldn’t work because I’m not using the textdomain to tell WordPress which plugin is being affected by this file.
So I need to first type in the textdomain. For WooCommerce Memberships, it’s woocommerce-memberships. You’ll also want to add a “–” (hyphen) after the text domain to separate it from the locale. So your filename should look like this:
If this translation were for French Canadian users, I’d save the file as woocommerce-memberships-fr_CA. (You can find more about locales here.) Note: It’s important that the locale matches your Site Language in WordPress.
The file you’re saving from Poedit should end in .po, so we should be saving it as woocommerce-memberships-fr_FR.po and it’ll automatically generate a woocommerce-memberships-fr_FR.mo to go along with it. You’ll need both of those files for the translation to be visible on your site. (Here’s a summary of the differences between .pot, .po., and .mo files, if you’re curious.)
Where should the files go?
You can save the files in the same spot you found the .pot file, so for our WooCommerce Memberships example, this would be in:
However, this has the possibility of being replaced when you update your plugin and that file could be overwritten in a future update! As such, you may want to keep all your translations in:
Because you’re using the plugin’s textdomain and locale, WordPress knows when to use the .po file you created and the .mo file that was generated for it, even if they’re not in the plugin’s folder. (Note: While saving your translation files in the plugins folder will work for all SkyVerge extensions, it may not work for every extension you encounter. Make sure to read up on whether your other extensions require translation files to go in the languages folder.)