How to translate WooCommerce
We would like to have an eshop with different languages set up. The main url will be using EN translations, the subsite /ru/ will be translated using Russian texts. To achieve this we’re going to configure the WordPress multisite, where each language will be set up as a separate subsite. Both subsites will be using the same plugins and theme, but translations will be fetched from po/mo files. The WooCommerce community has already prepared translations for most of the English phrases, so instead of translating everything from scratch, we’re going to enable built-in translations.
Setup the WooCommerce multisite
WordPress multisite installation creates additional database tables that will handle data for every subsite. The admin panel will now have a ‘Network Admin’ area where subsites can be configured. The first step to enable multisite configuration will be to add 1 line to the wp-config.php file:
// wp-config.php define('WP_ALLOW_MULTISITE', true);
Now log in to your Wp-admin panel and follow the instructions available in Tools / Network Setup. The instructions will include information about adding additional lines to wp-config.php and some changes in the .htaccess file. Now, the multisite setup is completed. What is left is to add new sites (subsites). Go to My Sites / Network Admin / Sites / Add New.
Choose proper language locale
The WordPress community is working on wp core and plugin translations. Site translate.wordpress.org is the place where newest language packages can be found. First, we have to determine country code (WP Locale). WP CLI will display all available translations:
wp language plugin list woocommerce
We can determine that Russian translations will be using the ‘ru_RU’ locale:
woocommerce ru_RU Russian Русский installed none 2021-08-06 18:24:42
Install predefined translations
We’re going to install the ‘default’ WordPress translations for Core WP and the WooCommerce plugin. Just use the following command line:
wp language core install ru_RU wp language plugin install woocommerce ru_RU
Proper .mo/.po files will be created in /wp-content/languages/ directory. Now we just need to enable a particular language via the wp-admin panel: Wp-admin / Settings / General – Site Language – select Russian from the list.
Wp-admin backend translation
It’s worth to mention that /wp-admin/ area language can be configured separately for every Administrator. This means that we can have frontend translated in Russian and the Backend Area in a different language. Every User with Admin permissions can change their ‘Admin Language’ in the user profile form ( /wp-admin/profile.php ) – the ‘Language’ option.
Customize translations using gettext
At this point we have a working WooCommerce Shop already translated into 2 languages (English and Russian). There might be a situation when we want to “overwrite” some default WooCommerce translations. As an example, we will take the string with textdomain ‘woocommerce’ ( wp-content/plugins/woocommerce/templates/checkout/form-billing.php )
<h3><?php esc_html_e( 'Billing details', 'woocommerce' ); ?></h3>
Currently, the text is already properly translated in the WooCommerce checkout view (it is using predefined po/mo translations from /wp-content/languages/). However, we would like to change the meaning of the text. Our goal is to translate ‘Billing details’ to the ‘Shipping details’ string (already translated). Here is the gettext filter that can “catch” text with a particular textdomain and replace it with a custom string.
/* * // functions.php * Custom 'woocommerce' translations * in multisite */ function ct_overwrite_translation( $translation, $text, $textdomain ) { if($textdomain == 'woocommerce'): $lang = 'ua'; $blog_id = get_current_blog_id(); if($blog_id == 2){ $lang = 'ru'; } // EN, UA, RU $translations = array( // change Billing details to 'Shipping details' 'Billing details' => array('ua' => 'Реквізити доставки','ru' => 'Детали доставки') ); if(array_key_exists($text, $translations)){ $translation = $translations[$text][$lang]; } endif; return $translation; } add_filter( 'gettext', 'ct_overwrite_translation', 10, 3 );
Using WooCommerce translations in PHP
When creating a WordPress theme or plugin we can utilize strings that are already translated. By doing this, our plugin will be already “compatible” with all the languages (over 60) that are a part of the WooCommerce core translations. First, check if the text is already translated → https://translate.wordpress.org/projects/wp-plugins/woocommerce/stable/ru/default/ . Use ‘Filter’ – search for ‘Pay for order’, confirm with ‘Apply Filters’. Success! Such translation already exists ( Added: 2015-09-15 20:35:21 UTC ). Using the translation helper function, we will add a button in our plugin. Text will be automatically translated (just change the Admin option ‘Site Language’ to see the change):
// PHP - custom plugin / wordpress theme echo '<a href="#">'. __('Pay for order', 'woocommerce') .'</a>';
Translations from database
Some Checkout texts might not be translated by default. The reason is that WooCommerce stores them in a database (instead of files). Those texts are available to be set up in plugin settings:
WooCommerce / Settings / Shipping / Shipping Zones
WooCommerce / Settings / Payments
WooCommerce / Settings / Accounts & Privacy
List of WooCommerce translations
The WooCommerce community has already translated core texts into over 60 languages. Here is a complete list of WooCommerce translations:
plugin | language | english_name | native_name | status | update | updated |
woocommerce | ar | Arabic | العربية | uninstalled | none | 2021-07-28 16:54:09 |
woocommerce | ary | Moroccan Arabic | العربية المغربية | uninstalled | none | 2021-01-19 17:30:04 |
woocommerce | bg_BG | Bulgarian | Български | uninstalled | none | 2021-07-23 09:32:09 |
woocommerce | bs_BA | Bosnian | Bosanski | uninstalled | none | 2021-02-25 00:10:40 |
woocommerce | ca | Catalan | Català | uninstalled | none | 2021-07-28 08:24:08 |
woocommerce | cs_CZ | Czech | Čeština | uninstalled | none | 2021-07-23 11:07:36 |
woocommerce | da_DK | Danish | Dansk | uninstalled | none | 2021-08-09 08:44:49 |
woocommerce | de_CH | German (Switzerland) | Deutsch (Schweiz) | uninstalled | none | 2020-11-16 19:40:55 |
woocommerce | de_CH_informal | German (Switzerland, Informal) | Deutsch (Schweiz, Du) | uninstalled | none | 2020-11-16 19:39:54 |
woocommerce | de_DE | German | Deutsch | uninstalled | none | 2021-08-11 17:16:34 |
woocommerce | de_DE_formal | German (Formal) | Deutsch (Sie) | uninstalled | none | 2021-08-11 17:17:24 |
woocommerce | el | Greek | Ελληνικά | uninstalled | none | 2021-08-05 07:46:34 |
woocommerce | en_AU | English (Australia) | English (Australia) | uninstalled | none | 2021-01-02 22:19:25 |
woocommerce | en_CA | English (Canada) | English (Canada) | uninstalled | none | 2021-08-06 01:23:34 |
woocommerce | en_GB | English (UK) | English (UK) | uninstalled | none | 2021-08-15 12:13:17 |
woocommerce | en_NZ | English (New Zealand) | English (New Zealand) | uninstalled | none | 2020-10-14 19:07:37 |
woocommerce | en_US | English (United States) | English (United States) | installed | none | |
woocommerce | en_ZA | English (South Africa) | English (South Africa) | uninstalled | none | 2021-07-23 11:41:10 |
woocommerce | eo | Esperanto | Esperanto | uninstalled | none | 2020-10-14 19:07:43 |
woocommerce | es_AR | Spanish (Argentina) | Español de Argentina | uninstalled | none | 2021-07-23 23:39:45 |
woocommerce | es_CL | Spanish (Chile) | Español de Chile | uninstalled | none | 2018-12-20 16:13:04 |
woocommerce | es_CO | Spanish (Colombia) | Español de Colombia | uninstalled | none | 2021-07-30 16:21:20 |
woocommerce | es_CR | Spanish (Costa Rica) | Español de Costa Rica | uninstalled | none | 2020-11-06 07:37:09 |
woocommerce | es_EC | Spanish (Ecuador) | Español de Ecuador | uninstalled | none | 2021-07-23 09:49:10 |
woocommerce | es_ES | Spanish (Spain) | Español | uninstalled | none | 2021-08-16 04:46:30 |
woocommerce | es_MX | Spanish (Mexico) | Español de México | uninstalled | none | 2021-07-23 13:00:58 |
woocommerce | es_VE | Spanish (Venezuela) | Español de Venezuela | uninstalled | none | 2021-07-23 09:50:04 |
woocommerce | et | Estonian | Eesti | uninstalled | none | 2021-04-15 14:25:45 |
woocommerce | eu | Basque | Euskara | uninstalled | none | 2021-03-09 21:48:02 |
woocommerce | fa_IR | Persian | فارسی | uninstalled | none | 2021-08-01 05:21:25 |
woocommerce | fi | Finnish | Suomi | uninstalled | none | 2021-08-10 08:44:04 |
woocommerce | fr_BE | French (Belgium) | Français de Belgique | uninstalled | none | 2020-12-07 14:13:14 |
woocommerce | fr_CA | French (Canada) | Français du Canada | uninstalled | none | 2021-07-18 18:38:39 |
woocommerce | fr_FR | French (France) | Français | uninstalled | none | 2021-07-27 11:46:23 |
woocommerce | gl_ES | Galician | Galego | uninstalled | none | 2021-07-29 13:13:24 |
woocommerce | he_IL | Hebrew | עִבְרִית | uninstalled | none | 2021-07-29 12:54:56 |
woocommerce | hr | Croatian | Hrvatski | uninstalled | none | 2021-08-08 13:44:51 |
woocommerce | hu_HU | Hungarian | Magyar | uninstalled | none | 2021-06-28 15:07:42 |
woocommerce | id_ID | Indonesian | Bahasa Indonesia | uninstalled | none | 2021-07-30 08:54:13 |
woocommerce | it_IT | Italian | Italiano | uninstalled | none | 2021-07-30 10:54:10 |
woocommerce | ja | Japanese | 日本語 | uninstalled | none | 2021-07-31 06:13:13 |
woocommerce | ka_GE | Georgian | ქართული | uninstalled | none | 2019-06-14 13:14:54 |
woocommerce | ko_KR | Korean | 한국어 | uninstalled | none | 2021-07-28 10:54:09 |
woocommerce | lt_LT | Lithuanian | Lietuvių kalba | uninstalled | none | 2021-07-04 23:00:13 |
woocommerce | lv | Latvian | Latviešu valoda | uninstalled | none | 2021-06-10 10:47:27 |
woocommerce | nb_NO | Norwegian (Bokmål) | Norsk bokmål | uninstalled | none | 2021-07-25 08:47:24 |
woocommerce | nl_BE | Dutch (Belgium) | Nederlands (België) | uninstalled | none | 2021-08-15 18:25:51 |
woocommerce | nl_NL | Dutch | Nederlands | uninstalled | none | 2021-07-23 12:51:41 |
woocommerce | nl_NL_formal | Dutch (Formal) | Nederlands (Formeel) | uninstalled | none | 2021-08-17 10:31:42 |
woocommerce | oci | Occitan | Occitan | uninstalled | none | 2017-10-12 14:47:42 |
woocommerce | pl_PL | Polish | Polski | uninstalled | none | 2021-08-16 07:39:17 |
woocommerce | pt_AO | Portuguese (Angola) | Português de Angola | uninstalled | none | 2021-06-03 19:01:11 |
woocommerce | pt_BR | Portuguese (Brazil) | Português do Brasil | uninstalled | none | 2021-06-08 17:42:34 |
woocommerce | pt_PT | Portuguese (Portugal) | Português | uninstalled | none | 2021-07-13 12:12:08 |
woocommerce | pt_PT_ao90 | Portuguese (Portugal, AO90) | Português (AO90) | uninstalled | none | 2019-07-07 00:41:48 |
woocommerce | ro_RO | Romanian | Română | uninstalled | none | 2021-08-15 14:28:42 |
woocommerce | ru_RU | Russian | Русский | installed | none | 2021-08-06 18:24:42 |
woocommerce | sk_SK | Slovak | Slovenčina | uninstalled | none | 2021-07-16 09:30:59 |
woocommerce | sl_SI | Slovenian | Slovenščina | uninstalled | none | 2020-10-14 19:10:03 |
woocommerce | sq | Albanian | Shqip | uninstalled | none | 2021-07-30 10:11:53 |
woocommerce | sr_RS | Serbian | Српски језик | uninstalled | none | 2021-05-10 19:11:39 |
woocommerce | sv_SE | Swedish | Svenska | uninstalled | none | 2021-07-28 12:54:10 |
woocommerce | th | Thai | ไทย | uninstalled | none | 2021-07-13 12:12:59 |
woocommerce | tr_TR | Turkish | Türkçe | uninstalled | none | 2021-08-10 07:18:06 |
woocommerce | uk | Ukrainian | Українська | active | available | 2021-08-11 12:24:15 |
woocommerce | uz_UZ | Uzbek | O‘zbekcha | uninstalled | none | 2020-07-08 19:11:12 |
woocommerce | vi | Vietnamese | Tiếng Việt | uninstalled | none | 2021-03-16 06:40:41 |
woocommerce | zh_CN | Chinese (China) | 简体中文 | uninstalled | none | 2021-07-27 14:54:09 |
woocommerce | zh_HK | Chinese (Hong Kong) | 香港中文版 | uninstalled | none | 2021-07-15 13:43:06 |
woocommerce | zh_TW | Chinese (Taiwan) | 繁體中文 | uninstalled | none | 2021-08-05 09:54:09 |
That’s it for this tutorial. Make sure you follow us for other useful tips and guidelines.