'How to implement Polylang functions in my theme's php file?
I am translating a site with Polylang that was created by someone else using a custom theme. Some strings couldn't be found by Polylang, so I need to manually register them for Polylang to see. Now, some of the strings were pretty easy to translate using __():
$args = shortcode_atts([
'link' => 'service',
'text' => __('Get the code now!'),
'title' => __('Code'),
'id' => '',
'class' => 'width300',
], $args, '' );
But I don't know how to translate strings in these scenarios:
$popup = do_shortcode('[popup id="110" link="vacancy" class="" title="Code" text="Get the code now!!" ]');
Or here words Details, Close
$script = '
<script>
$(document).ready(function(){
btn = $(\'.add_vakan_info\'),
popup = $(\'.add_popup\');
btn.click(function(){
var block_info = $(this).closest(\'.vacancy\').find(\'.content\');
if(block_info.hasClass(\'active\')){
block_info.removeClass(\'active\');
$(this).html(\'Details <i class="las la-angle-down"></i>\');
}else{
block_info.addClass(\'active\');
$(this).html(\'Close <i class="las la-angle-up"></i>\');
}
})
popup.click(function(){
var text = $(this).closest(\'.vacancy\').find(\'.title\').text(),
form = $(\'.vacancy_name\');
form.val(text);
})
FileInput();
})
</script>';
Or
else:
$html = '<h4>No vacancy </h4>';
Or
<div class="content col">
<div class="sp-20"></div>
<h4>Description</h4>
'.$description.'
<div class="sp-20"></div>
<h4>Requirements</h4>
'.$requirements.'
<div class="sp-20"></div>
<h4>Conditions</h4>
'.$conditions.'
Solution 1:[1]
You need to use Polylang's string translations API.
Step 1. Registering your strings.
// functions.php
add_action('init', function () {
$strings = array(
'no-vacancy' => 'No vacancy',
// Add more strings here...
);
foreach ($strings as $key => $string) {
pll_register_string('theme-' . $key, $string, 'Hardcoded Theme Strings');
}
});
Now these strings will appear in Languages > String translations menu, under the dropdown for Hardcoded Theme Strings
Step 2. Translate the Strings
else:
$html = '<h4>' . pll_e( 'No vacancy' ) . '</h4>';
The value you enter on the back-end in the string translations menu will be used when translating this value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Josh Bonnick |
