WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Polylang] How to use String Translation? (2 posts)

  1. Nikk
    Member
    Posted 1 year ago #

    I'm using the Polylang plugin for a multilingual website, but I can't figure out how to use
    the string translation functionality for translating custom lines.

    I added this line to my functions.php:

    pll_register_string('Test Textblock', $testtextblock);

    And I put this line in my page template:

    <?php pll__('Test Textblock'); ?>

    But yet nothing shows up in the 'Strings Translation' tab of the Polylang plugin.
    I'd like to add more strings to the Strings Translation tab, to make the whole website multilingual. I hope someone here can help me out with this, thanks!

  2. Chouby
    Member
    Posted 1 year ago #

    Are you sure that $testtextblock contains a non empty string?

    <?php pll__('Test Textblock'); ?> won't work. The original string that will be translated is the second parameter of the pll_register_string function. The first parameter is provided only for convenience to sort strings in the translations list table. Moreover pll__ does not echo the string. Either use echo pll__(...) or pll_e(...).

    Example:

    if (is_admin())
      pll_register_string('custom translation', 'my string to translate');
    else
      echo pll__('my string to translate');

Topic Closed

This topic has been closed to new replies.

About this Topic