Get a free advice now!

    Pick the topic

    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.

    Tags

    How to translate WooCommerce

    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:

    pluginlanguageenglish_namenative_namestatusupdateupdated
    woocommercearArabicالعربيةuninstallednone2021-07-28 16:54:09
    woocommercearyMoroccan Arabicالعربية المغربيةuninstallednone2021-01-19 17:30:04
    woocommercebg_BGBulgarianБългарскиuninstallednone2021-07-23 09:32:09
    woocommercebs_BABosnianBosanskiuninstallednone2021-02-25 00:10:40
    woocommercecaCatalanCatalàuninstallednone2021-07-28 08:24:08
    woocommercecs_CZCzechČeštinauninstallednone2021-07-23 11:07:36
    woocommerceda_DKDanishDanskuninstallednone2021-08-09 08:44:49
    woocommercede_CHGerman (Switzerland)Deutsch (Schweiz)uninstallednone2020-11-16 19:40:55
    woocommercede_CH_informalGerman (Switzerland, Informal)Deutsch (Schweiz, Du)uninstallednone2020-11-16 19:39:54
    woocommercede_DEGermanDeutschuninstallednone2021-08-11 17:16:34
    woocommercede_DE_formalGerman (Formal)Deutsch (Sie)uninstallednone2021-08-11 17:17:24
    woocommerceelGreekΕλληνικάuninstallednone2021-08-05 07:46:34
    woocommerceen_AUEnglish (Australia)English (Australia)uninstallednone2021-01-02 22:19:25
    woocommerceen_CAEnglish (Canada)English (Canada)uninstallednone2021-08-06 01:23:34
    woocommerceen_GBEnglish (UK)English (UK)uninstallednone2021-08-15 12:13:17
    woocommerceen_NZEnglish (New Zealand)English (New Zealand)uninstallednone2020-10-14 19:07:37
    woocommerceen_USEnglish (United States)English (United States)installednone
    woocommerceen_ZAEnglish (South Africa)English (South Africa)uninstallednone2021-07-23 11:41:10
    woocommerceeoEsperantoEsperantouninstallednone2020-10-14 19:07:43
    woocommercees_ARSpanish (Argentina)Español de Argentinauninstallednone2021-07-23 23:39:45
    woocommercees_CLSpanish (Chile)Español de Chileuninstallednone2018-12-20 16:13:04
    woocommercees_COSpanish (Colombia)Español de Colombiauninstallednone2021-07-30 16:21:20
    woocommercees_CRSpanish (Costa Rica)Español de Costa Ricauninstallednone2020-11-06 07:37:09
    woocommercees_ECSpanish (Ecuador)Español de Ecuadoruninstallednone2021-07-23 09:49:10
    woocommercees_ESSpanish (Spain)Españoluninstallednone2021-08-16 04:46:30
    woocommercees_MXSpanish (Mexico)Español de Méxicouninstallednone2021-07-23 13:00:58
    woocommercees_VESpanish (Venezuela)Español de Venezuelauninstallednone2021-07-23 09:50:04
    woocommerceetEstonianEestiuninstallednone2021-04-15 14:25:45
    woocommerceeuBasqueEuskarauninstallednone2021-03-09 21:48:02
    woocommercefa_IRPersianفارسیuninstallednone2021-08-01 05:21:25
    woocommercefiFinnishSuomiuninstallednone2021-08-10 08:44:04
    woocommercefr_BEFrench (Belgium)Français de Belgiqueuninstallednone2020-12-07 14:13:14
    woocommercefr_CAFrench (Canada)Français du Canadauninstallednone2021-07-18 18:38:39
    woocommercefr_FRFrench (France)Françaisuninstallednone2021-07-27 11:46:23
    woocommercegl_ESGalicianGalegouninstallednone2021-07-29 13:13:24
    woocommercehe_ILHebrewעִבְרִיתuninstallednone2021-07-29 12:54:56
    woocommercehrCroatianHrvatskiuninstallednone2021-08-08 13:44:51
    woocommercehu_HUHungarianMagyaruninstallednone2021-06-28 15:07:42
    woocommerceid_IDIndonesianBahasa Indonesiauninstallednone2021-07-30 08:54:13
    woocommerceit_ITItalianItalianouninstallednone2021-07-30 10:54:10
    woocommercejaJapanese日本語uninstallednone2021-07-31 06:13:13
    woocommerceka_GEGeorgianქართულიuninstallednone2019-06-14 13:14:54
    woocommerceko_KRKorean한국어uninstallednone2021-07-28 10:54:09
    woocommercelt_LTLithuanianLietuvių kalbauninstallednone2021-07-04 23:00:13
    woocommercelvLatvianLatviešu valodauninstallednone2021-06-10 10:47:27
    woocommercenb_NONorwegian (Bokmål)Norsk bokmåluninstallednone2021-07-25 08:47:24
    woocommercenl_BEDutch (Belgium)Nederlands (België)uninstallednone2021-08-15 18:25:51
    woocommercenl_NLDutchNederlandsuninstallednone2021-07-23 12:51:41
    woocommercenl_NL_formalDutch (Formal)Nederlands (Formeel)uninstallednone2021-08-17 10:31:42
    woocommerceociOccitanOccitanuninstallednone2017-10-12 14:47:42
    woocommercepl_PLPolishPolskiuninstallednone2021-08-16 07:39:17
    woocommercept_AOPortuguese (Angola)Português de Angolauninstallednone2021-06-03 19:01:11
    woocommercept_BRPortuguese (Brazil)Português do Brasiluninstallednone2021-06-08 17:42:34
    woocommercept_PTPortuguese (Portugal)Portuguêsuninstallednone2021-07-13 12:12:08
    woocommercept_PT_ao90Portuguese (Portugal, AO90)Português (AO90)uninstallednone2019-07-07 00:41:48
    woocommercero_RORomanianRomânăuninstallednone2021-08-15 14:28:42
    woocommerceru_RURussianРусскийinstallednone2021-08-06 18:24:42
    woocommercesk_SKSlovakSlovenčinauninstallednone2021-07-16 09:30:59
    woocommercesl_SISlovenianSlovenščinauninstallednone2020-10-14 19:10:03
    woocommercesqAlbanianShqipuninstallednone2021-07-30 10:11:53
    woocommercesr_RSSerbianСрпски језикuninstallednone2021-05-10 19:11:39
    woocommercesv_SESwedishSvenskauninstallednone2021-07-28 12:54:10
    woocommercethThaiไทยuninstallednone2021-07-13 12:12:59
    woocommercetr_TRTurkishTürkçeuninstallednone2021-08-10 07:18:06
    woocommerceukUkrainianУкраїнськаactiveavailable2021-08-11 12:24:15
    woocommerceuz_UZUzbekO‘zbekchauninstallednone2020-07-08 19:11:12
    woocommerceviVietnameseTiếng Việtuninstallednone2021-03-16 06:40:41
    woocommercezh_CNChinese (China)简体中文uninstallednone2021-07-27 14:54:09
    woocommercezh_HKChinese (Hong Kong)香港中文版uninstallednone2021-07-15 13:43:06
    woocommercezh_TWChinese (Taiwan)繁體中文uninstallednone2021-08-05 09:54:09

    That’s it for this tutorial. Make sure you follow us for other useful tips and guidelines.

    Comments
    0 response

    Add comment

    Your email address will not be published. Required fields are marked *

    Popular news

    Digital marketing without third-party cookies – new rules
    • Technology
    • Trends

    Digital marketing without third-party cookies – new rules

    February 21, 2024 by createIT
    eCommerce healthcheck
    • Services
    • Trends

    eCommerce healthcheck

    January 24, 2024 by createIT
    Live Visitor Count in WooCommerce with SSE
    • Dev Tips and Tricks

    Live Visitor Count in WooCommerce with SSE

    December 12, 2023 by createIT
    Calculate shipping costs programmatically in WooCommerce
    • Dev Tips and Tricks

    Calculate shipping costs programmatically in WooCommerce

    December 11, 2023 by createIT
    Designing a cookie consent modal certified by TCF IAB
    • Dev Tips and Tricks

    Designing a cookie consent modal certified by TCF IAB

    December 7, 2023 by createIT
    Understanding the IAB’s Global Vendor List (GVL)
    • Dev Tips and Tricks

    Understanding the IAB’s Global Vendor List (GVL)

    December 6, 2023 by createIT
    Effortlessly transform JSON data into a clear schema
    • Uncategorized

    Effortlessly transform JSON data into a clear schema

    December 5, 2023 by createIT
    Anatomy of WordPress malware: a technical deep dive
    • Dev Tips and Tricks
    • Technology

    Anatomy of WordPress malware: a technical deep dive

    December 4, 2023 by createIT
    Initializing CMP with the Stub Script and cmpapi.js
    • Dev Tips and Tricks

    Initializing CMP with the Stub Script and cmpapi.js

    November 29, 2023 by createIT

    Technology
    Be on the same page as the rest of the industry.

    Contact us