Search code examples
phpwordpresswordpress-themingtranslationgettext

Translate theme texts in WordPress site not contained in .po file


I'm trying to add another language to a Wordpress site. Some of the translation is being handled by a plugin called Polylang, but I'm also using .po/.mo files to handle some of the text that Polylang can't access.

However, there is some text that isn't showing up even in the .po file that was supplied with the theme.

Here's an example.

There's a setting in the Theme Options to set the text associated with some links (title and description). The php in the theme template is this:

<div id="homeheadlinks" class="col-md-4">
        <a href="<?php echo $options['unf_firstlink']?>" class="headbutton bone"><i class="golink"></i><?php echo $options['unf_firstlinktitle']?> <em><?php echo $options['unf_firstlinkdesc']?></em></a>
        <a href="<?php echo $options['unf_secondlink']?>" class="headbutton btwo"><i class="golink"></i><?php echo $options['unf_secondlinktitle']?> <em><?php echo $options['unf_secondlinkdesc']?></em></a>
        <a href="<?php echo $options['unf_thirdlink']?>" class="headbutton bthree"><i class="golink"></i><?php echo $options['unf_thirdlinktitle']?> <em><?php echo $options['unf_thirdlinkdesc']?></em></a>
    </div>

The text can be changed via the theme's options, but there is no way to add a language other than the main one that way.

How could I add translations for the items like $options['unf_firstlinktitle'] and $options['unf_firstlinkdesc'].

Just to be clear, these items don't show up in Polylang's String Translations section.


Solution

  • So, here's what I did and it seemed to work. I decided to add something similar to what LoicTheAztec suggested.

    In each one of those links, I changed them to

    <a href="<?php pll_e('http://mydomainname.com/englishpage/', 'mytheme-child') ?>" class="headbutton bone"><i class="golink"></i><?php pll_e('Link text', 'mytheme-child') ?> <em><?php pll_e ('Link description', 'mytheme-child') ?></em></a>https://wordpress.org/plugins/polylang-theme-strings/
    

    Then I installed the plugin Polylang Theme Strings, which put all of the new strings I created with pll_e() into Polylang's String Translation tabs. From there I did the translations (after choosing Show All Languages in the menu bar at the top.)

    It works almost perfectly. I have one other issue, which I'll post about if I can't resolve it myself soon.