Support » Plugin: Polylang » Translate string in functions.php

  • Hello
    How to translate a string from custom code in functions.php. of child theme?
    Thanks
    Greetings
    Davide

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    For example in you want to translate the string ‘Tous droits réservés’ in french to “All rights reserved’ in English in your footer.

    In functions.php code :
    if (function_exists(‘pll_register_string’))
    {
    pll_register_string(‘Footer’, ‘Tous droits réservés’);
    }

    In footer.php code
    <?php if (function_exists(‘pll__’)) echo pll__(‘Tous droits réservés’); ?>

    Now you can translate the string ‘Tous droits réservés’ in Language/String translation in the WP dashboard.

    Catherine.

    Hello
    That work!
    But I need to translate my snippet code added in functions.php, for example customize woocommerce, like:

    function function bbloomer_display_sold_out_loop_woocommerce() {
    global $product;

    if ( !$product->is_in_stock() ) {
    echo ‘<span class=”soldout”>’ . __(‘VENDUTA’, ‘woocommerce’) . ‘</span>’;
    }
    }
    add_action( ‘woocommerce_before_single_product_summary’, function() {
    globaL $product;
    if ( !$product->is_in_stock() ) {
    echo ‘<span class=”soldout”>VENDUTA</span>’;
    }
    });display_sold_out_loop_woocommerce() {
    global $product;

    if ( !$product->is_in_stock() ) {
    echo ‘<span class=”soldout”>’ . __(‘VENDUTA’, ‘woocommerce’) . ‘</span>’;
    }
    }
    add_action( ‘woocommerce_before_single_product_summary’, function() {
    globaL $product;
    if ( !$product->is_in_stock() ) {
    echo ‘<span class=”soldout”>VENDUTA</span>’;
    }
    });

    I need to translate ‘VENDUTA’ in “SOLD OUT” for english version

    Thanks

    It seems that you have the string VENDUTA internationalized with __() in your code. So you can translate it with po/mo files.

    Add or edit with the poedit tool the English translation po file of woocommerce and see if you find the VENDUTA string and translate into SOLD OUT

    I do not find it … that string VENDUTA was added by me in functions.php.
    I Have added you code but that string do not appear in language / string translation. ..
    Maybe I need to add:
    echo pll_ in functions.php?

    Maybe. Try this :

    Register VENDUTA string
    if (function_exists(‘pll_register_string’)) pll_register_string(‘mysnipet’, ‘VENDUTA’);

    translate the string ‘VENDUTA’ by ‘SOLD OUT’in Language/String translation in the WP dashboard.

    replace in your code __(‘VENDUTA’, ‘woocommerce’) by if (function_exists(‘pll__’)) echo pll__(‘VENDUTA’);

    Ok Thanks
    That work
    I have just changhe in:
    __(pll__(‘VENDUTA’), ‘woocommerce’)
    Greetings
    Davide

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Translate string in functions.php’ is closed to new replies.