1. Home
  2. Knowledge Base
  3. WooCommerce Product Table
  4. Advanced Usage
  5. Translating WooCommerce Product Table into other languages

Translating WooCommerce Product Table into other languages

At the present time, WooCommerce Product Table provides translations for:

  • French
  • Spanish
  • Italian
  • German (both formal and informal)
  • Dutch
  • Polish
  • Greek
  • Swedish
  • Norweigan

If your language is shown in the above list, simply set your site language under the Settings > General menu and your tables should display in that language. No further action required.

If your language is not listed above, you may want to translate the plugin yourself. To do this you will need to follow the steps below.

Creating your translation

In order to translate the plugin into your chosen language, you will need to create three files:

  1. A .po file, e.g. woocommerce-product-table-it_IT.po
  2. A .mo file, e.g. woocommerce-product-table-it_IT.mo
  3. A .json file, e.g. Italian.json

The .mo file is a machine-readable version of the .po file. This is created from the .po file, and if you use software such as PoEdit to create your translation, the .mo file is automatically generated when you save the .po file.

The PO and MO file

The .pot file for the plugin is provided in the languages folder:
/woocommerce-product-table/languages/woocommerce-product-table.pot.

You use this file to translate the plugin into your chosen language. We would recommend PoEdit for making your translation, but you can of course use an alternate method.

Once you have made your translation, save the file as woocommerce-product-table-<locale>.po, replacing <locale> with the locale for your language. For example, the main locale for Italian is it_IT, so the file name would be: woocommerce-product-table-it_IT.po.

Your .mo file should have the same format, e.g. woocommerce-product-table-it_IT.mo.

The JSON file

The plugin also requires a .json file, which provides the translations for the jQuery DataTables library that WooCommerce Product Table relies on. You can see an example translation file here:

https://datatables.net/plug-ins/i18n/Italian

In this example we’re translating to Italian. So create a file called Italian.json and copy the translations in this format into the file.

Uploading the files

Upload all three the files to this location:

<your site root>/wp-content/languages/plugins/

Adding code to your theme or child theme

Finally, you need to add some code to your theme’s functions.php file to register the JSON file with the plugin. This is done using the wc_product_table_supported_languages filter.

Important: You must use the correct locale for your language in the $langs array used in this code. The locale is a two or four letter code – for example 'pt_BR' is Brazilian Portuguese whereas 'pt_PT' is just Portuguese. In the example below, we use the 'it_IT' locale for Italian.

function wcpt_supported_languages( $langs ) {
    $langs['it_IT'] = 'http://example.com/wp-content/languages/plugins/Italian.json';
    return $langs;
}
add_filter( 'wc_product_table_supported_languages', 'wcpt_supported_languages' );

Contributing your translation to the plugin

If you create a translation for a language we don’t currently support, we would love to add it to the plugin.

Please send us an email and attach your files so we can add them to a future release.

Was this article helpful?

Related Articles