WooCommerce - Translate a word on the Checkout page

ぃ、小莉子 提交于 2019-12-10 17:42:30

问题


I'm trying to translate a word on the WooCommerce checkout page. My website is in the Dutch language, but they translated it poorly, so I want to use a different word.

What needs to be translated

It concerns the following line:

"Totaal €469,38 (Inclusief €79,38 Belasting)"

In English this says:

"Total €469,38 (Includes €79,38 tax)"

It's the line that sums up the total amount of the order. And I want to translate the word 'Belasting' to 'BTW'.

What I've tried

  1. Checked out settings in WooCommerce

  2. Installed the plugin Loco translator

  3. Searched for the word with FTP (Adobe Dreamweaver)

As I couldn't find the word 'Belasting' anywhere, I did find the php-file with the element of the line.

This I found in the PHP-document wc-cart-functions.php:

if ( ! empty( $tax_string_array ) ) {
        $value .= '<small class="includes_tax">' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
    }

And this is how the HTML part looks like:

<small class="includes_tax">
(inclusief 
<span class="amount">€79,38</span>
Belasting)
</small>

My Question

I presume it does print the word 'Belasting' with the '%s' variable. However I am unable to find the content for that variable anywhere.

So can anybody help me out by finding how to translate this word?

Thanks for reading and I'd appreciate the help.


回答1:


You can try using the gettext filter

Example

function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Related Products' :
            $translated_text = __( 'Check out these related products', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );



回答2:


WooCommerce uses gettext for translations, as described here there are several methods of updating the translation, the easies of which is editing the file in woocommerce/i18n/languages/




回答3:


The "Includes" part is translate-supported. i.e. you just need to add it to your translation file:

The translation file is in my case (danish): "../wp-content/languages/plugins/woocommerce-da_DK.po"

Open the file in your texteditor, e.g. Notepad++ and add these lines:

#: includes/class-wc-order.php:40 includes/wc-cart-functions.php:246
msgid "(Includes %s)"
msgstr "(Inkluderer %s)"

Now you need to compile the PO file to an MO file and you can use Poedit. Just open the PO file and save it, it will create a new MO file that you can upload and replace the current MO file (path: "../wp-content/languages/plugins/")

So fare so good!

In regards to the "Tax" part. This is controlled in the admin module:



来源:https://stackoverflow.com/questions/31559778/woocommerce-translate-a-word-on-the-checkout-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!