如何翻译WordPress插件

1.检查插件配置文件是否加载语言翻译文件及路径(以simple-location插件为便)

# 插件配置文件位置
index/wp-content/plugins/simple-location/simple-location.php

# 加载翻译文件的代码
add_action( 'plugins_loaded', function() {
load_plugin_textdomain( 'simple-location', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
});

2.制作po文件

msgid "Hello"
msgstr "你好"

msgid "Goodbye"
msgstr "再见"

3.将po文件转换成二进制的mo文件,WordPress主要识别mo文件进行翻译显示

可以用Ubuntu的msgfmt工具进行转换,用msgfmt可以对mo和po文件进行互相转换

msgfmt -o simple-location-zh_CN.mo simple-location-zh_CN.po
Tags:

发表回复

Your email address will not be published. Required fields are marked *.

*
*