wordpress对使用的国外主题进行本地汉化

wordpress有非常多优秀与专业的主题,当然大多数是非中文的

这些主题本身总会有些无法通过wordpress admin后台来配置的在页面上的英文输出

此时你可以去对应的代码去改掉那些输出,不过这总有些麻烦和累赘,即便你会.

wordpress 自身有多国语言的版本 多国语言包, 同样的 wordpress的主题也有和wordpress类似的机制

wordpress 非常简便的开放了这套规则  借由一个第三方的开源编译工具poedit

你可以专注于主题里所有需要翻译过来的词汇,短句,顺带发挥自己的个性化创造和定制,而不用去关心去哪儿改,在哪个文件里改,这儿调用的和那儿的有什么关联,不用关注主题框架的结构.

具体的几个步骤记录下:

1.

WordPress语言设置,下载的中文版本默认为中文,不用再去设置什么,否则
加入 define('WPLANG', 'zh_CN');

2.

在wp-content/languages  放入zh_CN.mo(中文语言包)
.mo为机器可读的二进制文件 通过编译人可读的.po文件得到

此时wordpress本身便汉化了的.

3.

wordpress去找对应主题的语言包

 通过 对应主题的根目录下的

functions.php里 查找
 load_theme_textdomain('zeeDynamic_language', get_template_directory() . '/languages' );
 第一个参数是通常是主题名字 第二个参数是拼接好的主题要读的翻译文件的路径

4.

使用poedit编辑此主题配置好的路径下(主题根目录下的languages文件夹下) .po文件

翻译后编译另存为zh_CN.mo文件 放在此languages文件夹下

如果主题文件没提供 .po functions.php 也没有load....() 那就自己加并配置吧

.po 文件为纯文本格式 具体编写格式可以参照 wordpress自身的languages下的.po文件

note :zh_CN.po文件和语言的定义 需按照 Gettext 语言代码  Gettext 国别代码 的方式来命名,中国 便为 zh_CN.

# Translation of 4.2.x in Chinese (China)
# This file is distributed under the same license as the 4.2.x package.
msgid ""
msgstr ""
"PO-Revision-Date: 2015-06-28 14:22:11+0000
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
"Plural-Forms: nplurals=1; plural=0;
"
"X-Generator: GlotPress/1.0-alpha-1000
"
"Project-Id-Version: 4.2.x
"

#: wp-signup.php:716
msgid "The site you were looking for, <strong>%s</strong>, does not exist."
msgstr "您正在找的站点(<strong>%s</strong>)不存在。您可以用这个名字创建您自己的博客!"
#: wp-signup.php:714 
msgid "The site you were looking for, <strong>%s</strong>, does not exist, but you can create it now!"
msgstr "您正在找的站点(<strong>%s</strong>)不存在。您可以用这个名字创建您自己的博客!"

#: wp-signup.php:708 msgid "You are logged in already. No need to register again!" msgstr "您已登录,无需重新注册。"

# healthpress-theme主题里指明路径
#: 404.php:11 healthpress-theme/404.php:11
msgid "Apologies, The page you requested could not be found!"
msgstr ""

#: 404.php:12 healthpress-theme/404.php:12
msgid ""
"Please try Navigation at the top or Search box to find what you are looking "
"for!"
msgstr ""
 
原文地址:https://www.cnblogs.com/isdom/p/webtips011.html