Polylang:如何翻译自定义字符串? [英] Polylang: How to translate custom strings?

查看:282
本文介绍了Polylang:如何翻译自定义字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My problem: I'm translating my website using Polylang but I'm having a hard time with custom strings translation. The strings won't show up in the "Strings translation" menu in the WP dashboard.

重要:我对PHP不太了解,所以 pll_register_string函数对我来说很混乱.

Important: I don't know much about PHP so the pll_register_string function is very confusing for me.

引自Polylang文档:

Quoted from the Polylang doc:

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

pll_register_string

允许插件在字符串翻译"中添加自己的字符串 控制板.该函数必须在管理员端调用(functions.php 文件适合主题).可以注册空字符串(对于 例如它们来自选项),但它们不会出现在列表中 桌子.

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.

用法:

pll_register_string($ name,$ string,$ group,$ multiline); ‘$ name’=> (必填)提供名称以便于排序(例如:"myplugin") ‘$ string’=>(必填)用来翻译‘$ group’=>(可选)的字符串 注册字符串的组,默认为"polylang" "$ multiline" =>(可选),如果设置为true,则翻译文本字段 将为多行,默认为false

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 __

转换先前在pll_register_string中注册的字符串 用法:

translates a string previously registered with pll_register_string Usage:

pll __($ string);唯一参数是必需的:

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

‘$ string’=>要翻译的字符串返回翻译后的字符串.

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

pll_e

回显先前在上注册的翻译字符串 pll_register_string用法:

Echoes a translated string previously registered with pll_register_string Usage:

pll_e($ string);唯一参数是必需的:

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

"$ string" =>要翻译的字符串

‘$string’ => the string to transla

最诚挚的问候

推荐答案

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

You must first register all these strings for translation.

例如,您在某些模板文件中回显"Hello world":

For example you echo "Hello world" in some template file like this:

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

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

To show string in the "Strings translation" add in your functions.php:

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

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

Add all custom strings you want to translate to this function.

这篇关于Polylang:如何翻译自定义字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆