[英]How to implement Polylang functions in my theme's php file?
我正在翻译一个由其他人使用自定义主题创建的 Polylang 网站。 Polylang 找不到某些字符串,所以我需要手动注册它们以供 Polylang 看到。 现在,使用__()
可以很容易地翻译一些字符串:
$args = shortcode_atts([
'link' => 'service',
'text' => __('Get the code now!'),
'title' => __('Code'),
'id' => '',
'class' => 'width300',
], $args, '' );
但我不知道如何在这些情况下翻译字符串:
$popup = do_shortcode('[popup id="110" link="vacancy" class="" title="Code" text="Get the code now!!" ]');
或者这里的话详细信息,关闭
$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>';
或者
else:
$html = '<h4>No vacancy </h4>';
或者
<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.'
您需要使用 Polylang 的字符串翻译 API 。
// 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');
}
});
现在这些字符串将出现在 Languages > String translations 菜单中,在Hardcoded Theme Strings
的下拉菜单下
else:
$html = '<h4>' . pll_e( 'No vacancy' ) . '</h4>';
翻译此值时将使用您在字符串翻译菜单后端输入的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.