gpt4 book ai didi

php - Polylang:如何翻译自定义字符串?

转载 作者:可可西里 更新时间:2023-11-01 13:33:19 30 4
gpt4 key购买 nike

我的问题:我正在使用 Polylang 翻译我的网站,但我很难进行自定义字符串翻译。字符串不会显示在 WP 仪表板的“字符串翻译”菜单中。

重要提示:我对 PHP 了解不多,所以 pll_register_string 函数 让我很困惑。

引用自 Polylang 文档:

https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/

pll_register_string

Allows plugins to add their own strings in the “strings translation” panel. The function must be called on admin side (the functions.php file is OK for themes). It is possible to register empty strings (for example when they come from options) but they won’t appear in the list table.

Usage:

pll_register_string($name, $string, $group, $multiline); ‘$name’ => (required) name provided for sorting convenience (ex: ‘myplugin’) ‘$string’ => (required) the string to translate ‘$group’ => (optional) the group in which the string is registered, defaults to ‘polylang’ ‘$multiline’ => (optional) if set to true, the translation text field will be multiline, defaults to false

pll__

translates a string previously registered with pll_register_string Usage:

pll__($string); The unique parameter is required:

‘$string’ => the string to translate returns the translated string.

pll_e

Echoes a translated string previously registered with pll_register_string Usage:

pll_e($string); The unique parameter is required:

‘$string’ => the string to transla

最好的问候

最佳答案

您必须先注册所有这些字符串进行翻译。

例如,你在这样的模板文件中回显“Hello world”:

<?php pll_e('Hello world'); ?>

要在“字符串翻译”中显示字符串,请在您的 functions.php 中添加:

add_action('init', function() {
pll_register_string('mytheme-hello', 'Hello world');
});

将您要翻译的所有自定义字符串添加到此函数。

关于php - Polylang:如何翻译自定义字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46557981/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com