我们在开发WordPress主题开发中,会需要用到多语言的版本。
网上已经有很多介绍 WordPress 多语言的插件了,比如 Polylang 和 WPML 等强大的多语言插件,但是只是介绍,很快都是能掌握怎么使用。今天我们要说的是如何使用 Polylang 插件来实现主题选项中字段的翻译。
WordPress多语言插件WPML在Polylang之前就已经创建了,因此对于一些插件和主题集成很好。WPML语言配置文件 wpml-config.xml已经可以翻译主题选项中的字段,Polylang 也支持 wpml-config.xml 文件的配置,而且 Polylang 的工作效率几本可以完成很多主题或者插件的翻译工作,所以我们创建一个 wpml-config.xml,添加以下代码到文件中:
<wpml-config> <custom-fields> <custom-field action="copy">quantity</custom-field> <custom-field action="translate">custom-title</custom-field> </custom-fields> <custom-types> <custom-type translate="1">book</custom-type> <custom-type translate="1">DVD</custom-type> </custom-types> <taxonomies> <taxonomy translate="1">genre</taxonomy> </taxonomies> <admin-texts> <!--my_themes_options 为主题选项的全局变量名--> <key name="my_themes_options"> <!--其中其它名称则是选项的 ID--> <key name="option_name_1" /> <key name="option_name_2" /> <key name="options_group_1"> <key name="sub_option_name_11" /> <key name="sub_option_name_12" /> </key> </key> <key name="simple_string_option" /> </admin-texts> </wpml-config>

将wpml-config.xml文件放在主题或者 Polylang 插件的根目录,再前台插件后台『语言——字符串翻译』中进行翻译即可,如下图:
