初始化 I18N 版本

增加可翻译版本
This commit is contained in:
feng 2021-10-18 15:59:25 +08:00
parent 3819e3d7fb
commit 917b4e8488
4 changed files with 116 additions and 75 deletions

Binary file not shown.

View file

@ -0,0 +1,40 @@
msgid ""
msgstr ""
"Project-Id-Version: WP Chinese Switcher\n"
"POT-Creation-Date: 2021-10-18 15:45+0800\n"
"PO-Revision-Date: 2021-10-18 15:46+0800\n"
"Last-Translator: 薇晓朵 <support@weixiaoduo.com>\n"
"Language-Team: 薇晓朵 <support@weixiaoduo.com>\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.0\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: wpchinese-switcher.php\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.min.js\n"
#. Plugin Name of the plugin/theme
msgid "WP Chinese Switcher"
msgstr "文派中文切换器"
#. Description of the plugin/theme
msgid ""
"Adds the language conversion function between Chinese Simplified and Chinese "
"Traditional to your WP Website."
msgstr "将中文简体和中文繁体之间的语言转换功能添加到您的WP网站。"
#. Author of the plugin/theme
msgid "WenPai.org"
msgstr "文派"
#. Author URI of the plugin/theme
msgid "https://wenpai.org"
msgstr "https://WenPai.org/"

View file

@ -98,11 +98,11 @@ class wpcs_Admin {
if ( ! empty($_POST['wpcso_uninstall_nonce'])) {
delete_option('wpcs_options');
update_option('rewrite_rules', '');
echo '<div class="wrap"><h2>WP Chinese Switcher Setting</h2><div class="updated">Uninstall Successfully. 卸载成功, 在您可以到<a href="plugins.php">插件菜单</a>里禁用本插件.</div></div>';
echo '<div class="wrap"><h2>WP Chinese Switcher Setting</h2><div class="updated">Uninstall Successfully. 卸载成功, 在您可以到<a href="plugins.php">插件菜单</a>里禁用本插件.</div></div>';
return;
} else if ($this->options === false) {
echo '<div class="wrap"><h2>WP Chinese Switcher Setting</h2><div class="error">错误: 没有找到配置信息, 可能由于Wordpress系统错误或者您已经卸载了本插件. 您可以<a href="plugins.php">尝试</a>禁用本插件后再重新激活.</div></div>';
echo '<div class="wrap"><h2>WP Chinese Switcher Setting</h2><div class="error">错误: 没有找到配置信息, 可能由于WordPress系统错误或者您已经卸载了本插件. 您可以<a href="plugins.php">尝试</a>禁用本插件后再重新激活.</div></div>';
return;
}
@ -158,7 +158,7 @@ class wpcs_Admin {
<div class="error" style=""><p><?php echo $this->message; ?></p></div>
<?php } ?>
<p>版本 <?php echo wpcs_VERSION; ?>. <a href="https://wenpai.org/" title="文派开源" target="_blank">文派开源</a> | <a
href="https://wpchineseswitcher.com" target="_blank" title="插件主页">插件主页</a></p>
href="https://wpchinese.cn" target="_blank" title="插件主页">插件主页</a></p>
<div style="padding-top:20px;padding-bottom:20px;"><b>单击选项名查看帮助!</b></div>
<form id="wpcso_form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"><input type="hidden"
name="wpcso_submitted"
@ -191,7 +191,7 @@ class wpcs_Admin {
value="<?php echo ! empty($this->options[$value[1]]) ? esc_html($this->options[$value[1]]) : ''; ?>"/><br/>
<?php } ?><!--wpcs_NC_END-->
<div id="wpcs_help_uls" style="display: none;">未选中的中文语言将不被使用,此项设置为全局设置.您应该选中至少一种中文语言,否则本插件全部功能都不会工作.
在每个复选框后的文本输入框里可以输入该语言自定义名称, 如果留空会使用默认值. <!--wpcs_NC_START-->("简体中文", "中文"...)
在每个复选框后的文本输入框里可以输入该语言自定义名称, 如果留空会使用默认值. <!--wpcs_NC_START-->("简体中文", "中文"...)
<!--wpcs_NC_END--></div>
</td>
</tr>
@ -212,13 +212,13 @@ class wpcs_Admin {
仅当中文语言不是"不转换"时开启(默认值)
</option>
</select>
<div id="wpcs_help_sc" style="display: none;">本选项将增强Wordpress搜索功能, 使其对中文关键词繁简统一处理.
<div id="wpcs_help_sc" style="display: none;">本选项将增强WordPress搜索功能, 使其对中文关键词繁简统一处理.
例如搜索"<!--wpcs_NC_START--><code>网络</code><!--wpcs_NC_END-->", 数据库里含有"
<!--wpcs_NC_START--><code>网络</code><!--wpcs_NC_END-->",
"<!--wpcs_NC_START--><code>網路</code><!--wpcs_NC_END-->" "<!--wpcs_NC_START--><code>網絡</code>
"<!--wpcs_NC_START--><code>网络</code><!--wpcs_NC_END-->" "<!--wpcs_NC_START--><code>网络</code>
<!--wpcs_NC_END-->"的文章都会放到搜索结果里返回.
支持多个中文词语搜索, 如搜索"<!--wpcs_NC_START--><code>简体 繁体</code><!--wpcs_NC_END-->",
含有"<!--wpcs_NC_START--><code>簡體</code><!--wpcs_NC_END-->""<!--wpcs_NC_START--><code>繁</code>
含有"<!--wpcs_NC_START--><code>简体</code><!--wpcs_NC_END-->""<!--wpcs_NC_START--><code>繁</code>
<!--wpcs_NC_END-->"两个词的文章也会被返回.
(此功能将增加搜索时数据库负担)
</div>
@ -242,15 +242,15 @@ class wpcs_Admin {
</select> <input type="checkbox" name="wpcso_auto_language_recong" id="wpcso_auto_language_recong"
value=""<?php echo $this->options['wpcs_auto_language_recong'] == 1 ? ' checked="checked"' : ''; ?> /><label
for="wpcso_auto_language_recong">允许繁简语系内部通用.</label>
<div id="wpcs_help_ua" style="display: none;"><b>本项设置不会应用于搜索引擎.</b> 如果本选项设置不为"关闭", 将识别访客浏览器首选中文语言.
如果设置为"跳转到对应繁简版本页面", 将302重定向到当前页面的访客浏览器首选语言版本.
如果设置为"直接显示对应繁简版本内容",将直接显示对应中文转换版本内容而不进行重定向. <b>如果本选项设置为"直接显示对应繁简版本内容",
<div id="wpcs_help_ua" style="display: none;"><b>本项设置不会应用于搜索引擎.</b> 如果本选项设置不为"关闭", 程将识别访客浏览器首选中文语言.
如果设置为"跳转到对应繁简版本页面", 程将302重定向到当前页面的访客浏览器首选语言版本.
如果设置为"直接显示对应繁简版本内容",程将直接显示对应中文转换版本内容而不进行重定向. <b>如果本选项设置为"直接显示对应繁简版本内容",
必须把下一个选项"使用Cookie保存并识别用户语言偏好"关闭或也设置为直接显示对应繁简版本,否则本插件只会在浏览器第一次访问时直接显示,
其他情况跳转.</b>.<br/><br/>关于"<b>允许繁简语系内部通用</b>"复选项说明: 只有当"识别浏览器动作"选项不为"关闭"时该复选框才有效. 具体说明,
假如您在本页第一项设置里禁用了部分中文,如zh-hk, 么浏览器里语言设置里只有"<!--wpcs_NC_START--> 港澳繁體<!--wpcs_NC_END--> "的用户访问时默认不会被识别;
但如果选中了此复选框,只要您开启了"<!--wpcs_NC_START--> 繁中文<!--wpcs_NC_END--> ", "<!--wpcs_NC_START--> 台灣正體
假如您在本页第一项设置里禁用了部分中文,如zh-hk, 幺浏览器里语言设置里只有"<!--wpcs_NC_START--> 港澳繁体<!--wpcs_NC_END--> "的用户访问时默认不会被识别;
但如果选中了此复选框,只要您开启了"<!--wpcs_NC_START--> 繁中文<!--wpcs_NC_END--> ", "<!--wpcs_NC_START--> 台湾正体
<!--wpcs_NC_END--> "
"<!--wpcs_NC_START--> 港澳繁<!--wpcs_NC_END--> " 中任一种语言, 浏览器使用这三种语言的用户都会被本插件识别并根据选项做出动作.
"<!--wpcs_NC_START--> 港澳繁<!--wpcs_NC_END--> " 中任一种语言, 浏览器使用这三种语言的用户都会被本插件识别并根据选项做出动作.
(但此时页面被转换后的语言可能并不是用户浏览器设置的那种, 而是您开启的那种繁体语言). 简体语系同理.<br/></div>
</td>
</tr>
@ -274,7 +274,7 @@ class wpcs_Admin {
当用户通过 "<?php echo $this->options['wpcs_use_permalink'] ?
esc_html(trailingslashit(wpcs_link_conversion(get_option('home') . '/', 'zh-tw'))) :
esc_html(wpcs_link_conversion(get_option('home') . '/', 'zh-tw')); ?>"
这个链接访问了您博客的台湾繁体版本时,程序将保存信息到Cookie中. 如果该用户重启浏览器并通过 "<?php echo get_option('home'); ?>/" 再次访问您博客,
这个链接访问了您网站的台湾繁体版本时,进程将保存信息到Cookie中. 如果该用户重启浏览器并通过 "<?php echo get_option('home'); ?>/" 再次访问您网站,
则会被自动跳转到台湾繁体版本的地址. 如果设置为"直接显示对应繁简版本",则不会进行跳转.
(参见上一项的说明)<br/><br/><b>本选项和上一项"识别浏览器"选项与缓存插件不兼容</b>.如果您使用了WP Super Cache/ Hyper Cache之类Cache插件,
请把这两项设置均设为"关闭",否则这两个功能不但不会正常工作, 而且可能造成缓存异常.<br/></div>
@ -307,9 +307,9 @@ class wpcs_Admin {
<label for="wpcso_no_conversion_ja">(默认关闭)</label>
<div id="wpcs_help_nc_ja" style="display: none;">如果选中此选项, 文章内容中用 lang="ja" 标记为日本语的html tag将不进行繁简转换,
保持原样输出.
例如: "<!--wpcs_NC_START--><code lang="ja">&lt;span lang="ja"&gt;あなたを、お連れしましょうか? この町の願いが叶う場所に。&lt;/span&gt;</code>
例如: "<!--wpcs_NC_START--><code lang="ja">&lt;span lang="ja"&gt;あなたを、お连れしましょうか? この町の愿いが叶う场所に。&lt;/span&gt;</code>
<!--wpcs_NC_END-->"
中的CJK汉字<!--wpcs_NC_START--><code lang="ja"></code><!--wpcs_NC_END--><!--wpcs_NC_START--><code
中的CJK汉字<!--wpcs_NC_START--><code lang="ja"></code><!--wpcs_NC_END--><!--wpcs_NC_START--><code
lang="ja"></code><!--wpcs_NC_END-->将不会进行繁简转换.
如果遇到html错误, 请关闭此选项.
</div>
@ -318,18 +318,18 @@ class wpcs_Admin {
<tr>
<td valign="top" width="30%"><a title="单击查看帮助" style="cursor: pointer;"
onclick="toggleVisibility('wpcs_no_conversion_qtag');">不转换HTML中任意容TAG:</a>
onclick="toggleVisibility('wpcs_no_conversion_qtag');">不转换HTML中任意容TAG:</a>
</td>
<td>
<!--wpcs_NC_START--><code>&lt;!--wpcs_NC_START--&gt;爱与正义, 與魔法, 光榮與夢&lt;!--wpcs_NC_END--&gt;</code>
<!--wpcs_NC_START--><code>&lt;!--wpcs_NC_START--&gt;爱与正义, 与魔法, 光荣与梦&lt;!--wpcs_NC_END--&gt;</code>
<!--wpcs_NC_END--><br/>
<input type="checkbox" name="wpcso_no_conversion_qtag"
id="wpcso_no_conversion_qtag" <?php echo ! empty($this->options['wpcs_no_conversion_qtag']) ? ' checked="checked"' : ''; ?> />
<label for="wpcso_no_conversion_qtag">在Wordpress文章html编辑器中添加"不转换中文"的Quick tag</label>
<label for="wpcso_no_conversion_qtag">在WordPress文章html编辑器中添加"不转换中文"的Quick tag</label>
<div id="wpcs_no_conversion_qtag" style="display: none;">
HTML中所有位于 <code>&lt;!--wpcs_NC_START--&gt;</code> <code>&lt;!--wpcs_NC_END--&gt;</code>之间的内容将不会进行繁简转换,
保持原样输出.
您可以在模板或post内容中使用这个标签.<br/>您可以选择在Wordpress的文章编辑器(html模式)工具栏中插入一个按钮(显示为"wpcs_NC"), 方便快速在文章中插入这个标签.
您可以在模板或post内容中使用这个标签.<br/>您可以选择在WordPress的文章编辑器(html模式)工具栏中插入一个按钮(显示为"wpcs_NC"), 方便快速在文章中插入这个标签.
</div>
</td>
</tr>
@ -351,7 +351,7 @@ class wpcs_Admin {
<div id="wpcs_help_pl" style="display: none;">更改此项设置前,<b>请仔细阅读下面的说明:</b><br/>本项设置决定插件生成的繁简转换页面Permalink.
默认的形式为您原始Permalink后加上?variant=zh-tw参数.(zh-tw为当前请求的语言代码) .您可以修改这个permalink形式.本插件提供两种非默认的Permalink格式:
您原始的Permalink后加上/zh-tw /zh-tw/; /zh-tw后加上您原来Permalink. 两种区别在于中文语言代码(zh-tw)附加在您原来Permalink的末尾或开头.
URL末尾是否有 / 取决于您的Wordpress永久链接末尾是否有/. <b>首页的繁简转换版本URL末尾永远有 "/"</b> . 如果您的Wordpress未开启永久链接,
URL末尾是否有 / 取决于您的WordPress永久链接末尾是否有/. <b>首页的繁简转换版本URL末尾永远有 "/"</b> . 如果您的WordPress未开启永久链接,
本项设置只能选择第一种URL形式.
</div>
</td>
@ -365,7 +365,7 @@ class wpcs_Admin {
name="wpcso_use_fullpage_conversion"<?php echo $this->options['wpcs_use_fullpage_conversion'] == 1 ? ' checked="checked"' : ''; ?> />
<label for="wpcso_use_fullpage_conversion">(默认开启)</label>
<div id="wpcs_help_ob" style="display: none;">
开启此选项后,插件将对Wordpress输出的全部页面内容进行中文整体转换(使用ob_start和ob_flush函数),
开启此选项后,插件将对WordPress输出的全部页面内容进行中文整体转换(使用ob_start和ob_flush函数),
这将极大提高页面生成速度并减少资源使用.但也可能造成意想不到问题.如果遇到异常(包括中文转换错误, HTML页面错误或php错误等),请关闭此选项.
</div>
</td>
@ -476,7 +476,7 @@ class wpcs_Admin {
function navi() {
$variant = ! empty($_GET['variant']) ? $_GET['variant'] : '';
$str = '<span><a title="默认/ 默" href="' . $this->url . '" ' . (! $variant ? 'style="color: #464646; text-decoration: none !important;"' : '') . ' >默认/ 默</a></span>&nbsp;';
$str = '<span><a title="默认/ 默" href="' . $this->url . '" ' . (! $variant ? 'style="color: #464646; text-decoration: none !important;"' : '') . ' >默认/ 默</a></span>&nbsp;';
if ( ! $this->options['wpcs_used_langs']) {
return $str;
}

View file

@ -10,8 +10,10 @@
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/*
Copyright (C) 2009-2013 Ono Oogami, https://oogami.name/ (ono@oogami.name)
Copyright 2012-2021 WenPai (http://wenpai.org)
Developer: WenPai
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -30,15 +32,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* WP Chinese Switcher Plugin main file
*
* 為Wordpress增加中文繁簡轉換功能. 轉換過程在服務器端完成. 使用的繁簡字符映射表來源于Mediawiki.
* 为Wordpress增加中文繁简转换功能. 转换过程在服务器端完成. 使用的繁简字符映射表来源于Mediawiki.
* 本插件比较耗费资源. 因为对页面内容繁简转换时载入了一个几百KB的转换表(ZhConversion.php), 编译后占用内存超过1.5MB
* 如果可能, 建议安装xcache/ eAccelerator之类PHP缓存扩展. 可以有效提高速度并降低CPU使用,在生产环境下测试效果非常显.
* 如果可能, 建议安装xcache/ eAccelerator之类PHP缓存扩展. 可以有效提高速度并降低CPU使用,在生产环境下测试效果非常显.
*
* @package WPCS
* @version see wpcs_VERSION constant below
* @TODO 用OO方式重寫全部代碼, 計劃1.2版本實現.
* @TODO 用OO方式重写全部代码, 计划1.2版本实现.
* @link http://wordpress.org/plugins/wpchinese-switcher Plugin Page on wordpress.org, including guides and docs.
* @link https://oogami.name/project/wpcs/ Plugin Homepage
*
*/
@ -48,7 +49,7 @@ define('wpcs_VERSION', '1.0');
$wpcs_options = get_option('wpcs_options');
// /**********************
//初始化所有全局量.其实不初始化也没关系,主要是防止某些古董php版本register_globals打开可能造成意想不到问题.
//初始化所有全局量.其实不初始化也没关系,主要是防止某些古董php版本register_globals打开可能造成意想不到问题.
$wpcs_admin = false;
$wpcs_noconversion_url = false;
$wpcs_redirect_to = false;
@ -57,16 +58,16 @@ $wpcs_langs_urls = array();
$wpcs_target_lang = false;
// ***************************/
//您可以更改提示文,如"简体中文","繁体中文".但是不要改动其它.
//您可以更改提示文,如"简体中文","繁体中文".但是不要改动其它.
//不要改键值的语言代码zh-xx, 本插件一些地方使用了硬编码的语言代码.
$wpcs_langs = array(
'zh-cn' => array('zhconversion_cn', 'cntip', '简体中文', 'zh-CN'),
'zh-tw' => array('zhconversion_tw', 'twtip', '繁中文', 'zh-TW'),
'zh-tw' => array('zhconversion_tw', 'twtip', '繁中文', 'zh-TW'),
/*
'zh-hans' => array('zhconversion_hans', 'hanstip', '简体中文','zh-Hans'),
'zh-hant' => array('zhconversion_hant', 'hanttip', '繁中文','zh-Hant'),
'zh-hk' => array('zhconversion_hk', 'hktip', '港澳繁','zh-HK'),
'zh-mo' => array('zhconversion_hk', 'motip', '澳門繁體','zh-MO'),
'zh-hant' => array('zhconversion_hant', 'hanttip', '繁中文','zh-Hant'),
'zh-hk' => array('zhconversion_hk', 'hktip', '港澳繁','zh-HK'),
'zh-mo' => array('zhconversion_hk', 'motip', '澳门繁体','zh-MO'),
'zh-sg' => array('zhconversion_sg', 'sgtip', '马新简体','zh-SG'),
'zh-my' => array('zhconversion_sg', 'mytip', '马来西亚简体','zh-MY'),
*/
@ -389,9 +390,9 @@ class wpcs_Widget extends WP_Widget {
*
* @return converted string
*
* 这是本插件繁简转换页使用的基本中文转换函数. 例如, 如果访客请求一个"灣正體"版本页面,
* 这是本插件繁简转换页使用的基本中文转换函数. 例如, 如果访客请求一个"湾正体"版本页面,
* $wpcs_conversion_function被设置为'zhconversion_tw',
* 本函数调用其把字符串转换为"灣正體"版本
* 本函数调用其把字符串转换为"湾正体"版本
*
*/
function zhconversion($str, $variant = null) {
@ -498,8 +499,8 @@ function zhconversion_safe($str, $variant = null) {
*
* @return array converted strings array
*
* Example: zhconversion('網絡');
* Return: array('網路', '网络');
* Example: zhconversion('网络');
* Return: array('网络', '网络');
*
*/
function zhconversion_all($str, $langs = array('zh-tw', 'zh-cn', 'zh-hk', 'zh-sg', 'zh-hans', 'zh-hant')) {
@ -526,7 +527,7 @@ function zhconversion_deep($value) {
}
/**
* 对输入字符串进行有限中文转换. 不转换<!--wpcs_NC_START--><!--wpcs_NC_END-->的中文
* 对输入字符串进行有限中文转换. 不转换<!--wpcs_NC_START--><!--wpcs_NC_END-->的中文
*
* @param string $str string inputed
* @param string $function conversion function for current requested chinese language
@ -555,7 +556,7 @@ function limit_zhconversion($str, $function) {
/**
* 中文轉換函數. (zhconversion_hans轉換字符串為簡體中文, zhconversion_hant轉換字符串為繁體中文, zhconversion_tw轉換字符串為臺灣正體, 依次類)
* 中文转换函数. (zhconversion_hans转换字符串为简体中文, zhconversion_hant转换字符串为繁体中文, zhconversion_tw转换字符串为台湾正体, 依次类)
*
* @param string $str string to be converted
*
@ -563,7 +564,7 @@ function limit_zhconversion($str, $function) {
*
* 对于zh-hans和zh-hant以外中文语言(如zh-tw),Mediawiki里的做法是 先array_merge($zh2Hans, $zh2TW),再做一次strtr. 但这里考虑到内存需求和CPU资源,采用两次strtr方法.其中$zh2TW先做,因为其中项目可能覆盖zh2Hant里的项目
*
* 注意: 如果您想在其他地方(如Theme)里使用下面中文轉換函數, 請保證首先調用一次wpcs_load_conversion_table(); , 因為出于節省內存需求, 本插件僅在繁簡轉換頁面才會載入中文轉換.
* 注意: 如果您想在其他地方(如Theme)里使用下面中文转换函数, 请保证首先调用一次wpcs_load_conversion_table(); , 因为出于节省内存需求, 本插件仅在繁简转换页面才会加载中文转换.
*
*/
function zhconversion_hant($str) {
@ -699,14 +700,14 @@ function _wpcs_permalink_preg_callback($matches) {
}
/**
* 修改繁簡轉換頁面WP內部鏈
* 修改繁简转换页面WP内部链
*
* @param string $link URL to be converted
*
* @return string converted URL
*
* 如果訪客請求一個繁簡轉換頁面, 本函數把該頁的所有鏈接轉換為對應中文語言版本的
* 例如把分類頁鏈接轉換為 /category/cat-name/zh-xx/, 把Tag頁鏈接轉換為 /tag/tag-name/zh-xx/
* 如果访客请求一个繁简转换页面, 本函数把该页的所有链接转换为对应中文语言版本的
* 例如把分类页链接转换为 /category/cat-name/zh-xx/, 把Tag页链接转换为 /tag/tag-name/zh-xx/
*
*/
function wpcs_link_conversion($link, $variant = null) {
@ -756,12 +757,12 @@ function wpcs_link_conversion_auto($link, $variant = null) {
}
/**
* 獲取當前頁面原始URL
* 获取当前页面原始URL
* @return original permalink of current page
*
* 本函數返回當前請求頁"原始版本" URL.
* 即如果前URL是 /YYYY/mm/sample-post/zh-tw/ 形式的臺灣正體版本,
* 返回 /YYYY/mm/sample-post/ 的原始(進行中文轉換)版本鏈.
* 本函数返回当前请求页"原始版本" URL.
* 即如果前URL是 /YYYY/mm/sample-post/zh-tw/ 形式的台湾正体版本,
* 返回 /YYYY/mm/sample-post/ 的原始(进行中文转换)版本链.
*
*/
function wpcs_get_noconversion_url() {
@ -773,7 +774,7 @@ function wpcs_get_noconversion_url() {
$tmp = trim(strtolower(remove_query_arg('variant', $tmp)));
if (preg_match('/^(.*)\/(' . $reg . '|zh|zh-reset)(\/.*)?$/', $tmp, $matches)) {
$tmp = user_trailingslashit(trailingslashit($matches[1]) . ltrim($matches[3], '/')); //为什这样写代码? 是有原因的- -(众人: 废话!)
$tmp = user_trailingslashit(trailingslashit($matches[1]) . ltrim($matches[3], '/')); //为什这样写代码? 是有原因的- -(众人: 废话!)
if ($tmp == get_option('home')) {
$tmp .= '/';
}
@ -783,16 +784,16 @@ function wpcs_get_noconversion_url() {
}
/**
* 復繁簡轉換頁分頁鏈
* 复繁简转换页分页链
*
* @param string $link URL to be fixed
*
* @return string Fixed URL
*
* 本函數修復繁簡轉換頁面 /.../page/N 形式的分頁鏈接為正確形式. 具體說明略.
* 本函数修复繁简转换页面 /.../page/N 形式的分页链接为正确形式. 具体说明略.
*
* 您可以在本函數內第一行加上 'return $link;' 然后訪問您博客首頁或存檔頁的繁體或簡體版本,
* 會發現"上一頁"(previous posts page)"下一"(next posts page)的鏈接URL是錯誤.
* 您可以在本函数内第一行加上 'return $link;' 然后访问您博客首页或存盘页的繁体或简体版本,
* 会发现"上一页"(previous posts page)"下一"(next posts page)的链接URL是错误.
* 本函数算法极为愚蠢- -, 但是没有其它办法, 因为wordpress对于分页链接的生成策略非常死板且无法更多地通过filter控制
*
*/
@ -825,10 +826,10 @@ function wpcs_pagenum_link_fix($link) {
* @return string Fixed URL
*
* 本插件会添加 post_link钩子, 从而修改繁简转换页单篇文章页永久链接, 但WP的很多内部链接生成依赖这个permalink.
* (为什加载在post_link钩子上而不是the_permalink钩子上? 有很多原因,这里不说了.)
* (为什加载在post_link钩子上而不是the_permalink钩子上? 有很多原因,这里不说了.)
*
* 举例而言, 本插件把 繁简转换页的文章permalink修改为 /YYYY/mm/sample-post/zh-tw/ (如果您原来的Permalink是/YYYY/mm/sample-post/)
* WP生成的该篇文章评论Feed链接是 /YYYY/mm/sample-post/zh-tw/feed/, 出错
* WP生成的该篇文章评论Feed链接是 /YYYY/mm/sample-post/zh-tw/feed/, 出错
* 本函数把这个链接修复为 /YYYY/mm/sample-post/feed/zh-tw/ 的正确形式.
*
*/
@ -855,15 +856,15 @@ function wpcs_fix_link_conversion($link) {
}
/**
* "取消"繁简转换后页面部分内部链接轉換.
* "取消"繁简转换后页面部分内部链接转换.
*
* @param string $link URL to be fixed
*
* @return string Fixed URL
*
* 本函數作用與上面的wpcs_fix_link_conversion類似, 不同的是本函數"取消"而不是"修復"繁簡轉換頁內部鏈
* 舉例而言, 對繁簡轉換頁面而言, WP生成的單篇文章trackback地址 /YYYY/mm/sample-post/zh-tw/trackback/
* 本函數把它修改為 /YYYY/mm/sample-post/trackback/的正形式(即去除URL中 zh-xx字段)
* 本函数作用与上面的wpcs_fix_link_conversion类似, 不同的是本函数"取消"而不是"修复"繁简转换页内部链
* 举例而言, 对繁简转换页面而言, WP生成的单篇文章trackback地址 /YYYY/mm/sample-post/zh-tw/trackback/
* 本函数把它修改为 /YYYY/mm/sample-post/trackback/的正形式(即去除URL中 zh-xx字段)
*
*/
function wpcs_cancel_link_conversion($link) {
@ -900,11 +901,11 @@ function wpcs_rel_canonical() {
/**
* 返回w3c標準的當前中文語言代碼, zh-CN, zh-Hans
* 返回值可以用在html元素的 lang=""標籤裡
* 返回w3c标准的当前中文语言代码, zh-CN, zh-Hans
* 返回值可以用在html元素的 lang=""标签里
*
* @since 1.1.9
* @link http://www.w3.org/International/articles/language-tags/ W3C關於language attribute文章.
* @link http://www.w3.org/International/articles/language-tags/ W3C关于language attribute文章.
*/
function variant_attribute($default = "zh", $variant = false) {
global $wpcs_langs;
@ -919,7 +920,7 @@ function variant_attribute($default = "zh", $variant = false) {
}
/**
* 返回當前語言代碼
* 返回当前语言代码
* @since 1.1.9
*/
function variant($default = false) {
@ -953,9 +954,9 @@ function wpcs_output_navi($args = '') {
$noconverttip = $wpcs_options['nctip'];
} else {
$locale = str_replace('_', '-', strtolower(get_locale()));
if (in_array($locale, array('zh-hant', 'zh-tw', 'zh-hk', 'zh-mo'))) //zh-mo = 澳門繁體, 目前與zh-hk香港繁體轉換表相同
if (in_array($locale, array('zh-hant', 'zh-tw', 'zh-hk', 'zh-mo'))) //zh-mo = 澳门繁体, 目前与zh-hk香港繁体转换表相同
{
$noconverttip = '不轉換';
$noconverttip = '不转换';
} else {
$noconverttip = '不转换';
}
@ -1008,15 +1009,15 @@ function wpcs_output_navi2() {
}
$output = "\n" . '<div id="wpcs_widget_inner"><!--wpcs_NC_START-->' . "\n";
$output .= ' <span id="wpcs_original_link" class="' . ($wpcs_target_lang == false ? 'wpcs_current_lang' : 'wpcs_lang') . '" ><a class="wpcs_link" href="' . esc_url($default_url) . '" title="不轉換">不轉換</a></span>' . "\n";
$output .= ' <span id="wpcs_original_link" class="' . ($wpcs_target_lang == false ? 'wpcs_current_lang' : 'wpcs_lang') . '" ><a class="wpcs_link" href="' . esc_url($default_url) . '" title="不转换">不转换</a></span>' . "\n";
$output .= ' <span id="wpcs_cn_link" class="' . ($wpcs_target_lang == 'zh-cn' ? 'wpcs_current_lang' : 'wpcs_lang') . '" ><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-cn']) . '" title="大陆简体" >大陆简体</a></span>' . "\n";
$output .= ' <span id="wpcs_tw_link" class="' . ($wpcs_target_lang == 'zh-tw' ? 'wpcs_current_lang' : 'wpcs_lang') . '"><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-tw']) . '" title="台灣正體" >台灣正體</a></span>' . "\n";
$output .= ' <span id="wpcs_tw_link" class="' . ($wpcs_target_lang == 'zh-tw' ? 'wpcs_current_lang' : 'wpcs_lang') . '"><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-tw']) . '" title="台湾正体" >台湾正体</a></span>' . "\n";
/*$output .= ' <span id="wpcs_more_links" class="wpcs_lang" >
<span id="wpcs_more_links_inner_more" class="'. ( ( $wpcs_target_lang == false || $wpcs_target_lang == 'zh-cn' || $wpcs_target_lang == 'zh-tw' ) ? 'wpcs_lang' : 'wpcs_current_lang' ) . '"><a class="wpcs_link" href="#" onclick="return false;" >其它中文</a></span>
<span id="wpcs_more_links_inner" >
<span id="wpcs_hans_link" class="' . ( $wpcs_target_lang == 'zh-hans' ? 'wpcs_current_lang' : 'wpcs_lang' ) . '" ><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-hans']) . '" title="简体中文" >简体中文' . '</a></span>
<span id="wpcs_hant_link" class="' . ( $wpcs_target_lang == 'zh-hant' ? 'wpcs_current_lang' : 'wpcs_lang' ) . '" ><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-hant']) . '" title="體中文" >繁體中文' . '</a></span>
<span id="wpcs_hk_link" class="' . ( $wpcs_target_lang == 'zh-hk' ? 'wpcs_current_lang' : 'wpcs_lang' ) . '"><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-hk']) . '" title="港澳繁" >港澳繁體</a></span>
<span id="wpcs_hant_link" class="' . ( $wpcs_target_lang == 'zh-hant' ? 'wpcs_current_lang' : 'wpcs_lang' ) . '" ><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-hant']) . '" title="体中文" >繁体中文' . '</a></span>
<span id="wpcs_hk_link" class="' . ( $wpcs_target_lang == 'zh-hk' ? 'wpcs_current_lang' : 'wpcs_lang' ) . '"><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-hk']) . '" title="港澳繁" >港澳繁体</a></span>
<span id="wpcs_sg_link" class="' . ( $wpcs_target_lang == 'zh-sg' ? 'wpcs_current_lang' : 'wpcs_lang' ) . '" ><a class="wpcs_link" rel="nofollow" href="' . esc_url($wpcs_langs_urls['zh-sg']) . '" title="马新简体" >马新简体</a></span>
</span>
</span>';*/
@ -1172,13 +1173,13 @@ function wpcs_apply_filter_search_rule() {
* @return string WHERE sentence have been processed
*
* 使用方法: add_filter('posts_where', 'wpcs_filter_search_rule');
* 原理说明: 假设访客通过表单搜索 "简体 繁 中文", Wordpress生成的sql语句条件$where中一部分是这样的:
* 原理说明: 假设访客通过表单搜索 "简体 繁 中文", Wordpress生成的sql语句条件$where中一部分是这样的:
*
* ((wp_posts.post_title LIKE '%简体%') OR (wp_posts.post_content LIKE '%简体%')) AND ((wp_posts.post_title LIKE '%繁%') OR (wp_posts.post_content LIKE '%繁%')) AND ((wp_posts.post_title LIKE '%中文%') OR (wp_posts.post_content LIKE '%中文%')) OR (wp_posts.post_title LIKE '%简体 繁 中文%') OR (wp_posts.post_content LIKE '%简体 繁 中文%')
* ((wp_posts.post_title LIKE '%简体%') OR (wp_posts.post_content LIKE '%简体%')) AND ((wp_posts.post_title LIKE '%繁%') OR (wp_posts.post_content LIKE '%繁%')) AND ((wp_posts.post_title LIKE '%中文%') OR (wp_posts.post_content LIKE '%中文%')) OR (wp_posts.post_title LIKE '%简体 繁 中文%') OR (wp_posts.post_content LIKE '%简体 繁 中文%')
*
* 本函数把$where中的上面这部分替换为:
*
* ( ( wp_posts.post_title LIKE '%簡體%') OR ( wp_posts.post_content LIKE '%簡體%') OR ( wp_posts.post_title LIKE '%简体%') OR ( wp_posts.post_content LIKE '%简体%') ) AND ( ( wp_posts.post_title LIKE '%繁体%') OR ( wp_posts.post_content LIKE '%繁体%') OR ( wp_posts.post_title LIKE '%繁%') OR ( wp_posts.post_content LIKE '%繁%') ) AND ( ( wp_posts.post_title LIKE '%中文%') OR ( wp_posts.post_content LIKE '%中文%') ) OR ( wp_posts.post_title LIKE '%簡體 繁體 中文%') OR ( wp_posts.post_content LIKE '%簡體 繁體 中文%') OR ( wp_posts.post_title LIKE '%简体 繁体 中文%') OR ( wp_posts.post_content LIKE '%简体 繁体 中文%') OR ( wp_posts.post_title LIKE '%简体 繁 中文%') OR ( wp_posts.post_content LIKE '%简体 繁 中文%')
* ( ( wp_posts.post_title LIKE '%简体%') OR ( wp_posts.post_content LIKE '%简体%') OR ( wp_posts.post_title LIKE '%简体%') OR ( wp_posts.post_content LIKE '%简体%') ) AND ( ( wp_posts.post_title LIKE '%繁体%') OR ( wp_posts.post_content LIKE '%繁体%') OR ( wp_posts.post_title LIKE '%繁%') OR ( wp_posts.post_content LIKE '%繁%') ) AND ( ( wp_posts.post_title LIKE '%中文%') OR ( wp_posts.post_content LIKE '%中文%') ) OR ( wp_posts.post_title LIKE '%简体 繁体 中文%') OR ( wp_posts.post_content LIKE '%简体 繁体 中文%') OR ( wp_posts.post_title LIKE '%简体 繁体 中文%') OR ( wp_posts.post_content LIKE '%简体 繁体 中文%') OR ( wp_posts.post_title LIKE '%简体 繁 中文%') OR ( wp_posts.post_content LIKE '%简体 繁 中文%')
*
*/
function wpcs_filter_search_rule($where) {
@ -1188,7 +1189,7 @@ function wpcs_filter_search_rule($where) {
}
if ( ! preg_match("/^([" . chr(228) . "-" . chr(233) . "]{1}[" . chr(128) . "-" . chr(191) . "]{1}[" . chr(128) . "-" . chr(191) . "]{1}){1}/", $wp_query->query_vars['s']) && ! preg_match("/([" . chr(228) . "-" . chr(233) . "]{1}[" . chr(128) . "-" . chr(191) . "]{1}[" . chr(128) . "-" . chr(191) . "]{1}){1}$/", $wp_query->query_vars['s']) && ! preg_match("/([" . chr(228) . "-" . chr(233) . "]{1}[" . chr(128) . "-" . chr(191) . "]{1}[" . chr(128) . "-" . chr(191) . "]{1}){2,}/", $wp_query->query_vars['s'])) {
return $where;
}//如果搜索关键字中不含中文符, 直接返回
}//如果搜索关键字中不含中文符, 直接返回
wpcs_load_conversion_table();
@ -1286,7 +1287,7 @@ function wpcs_admin_init() {
*
* @param object $query 'parse_request' filter' argument, the 'WP' object
*
* @todo 彻底重写本函数目前是一团浆糊。使用Wordpress原生的query var系統讀/寫variant參數, 1.2版本實現.
* @todo 彻底重写本函数目前是一团浆糊。使用Wordpress原生的query var系统读/写variant参数, 1.2版本实现.
* Core codes of this plugin
* 本函数获取当前请求中文语言并保存到 $wpcs_target_lang全局变量里.
* 并且还做其它一些事情.
@ -1522,7 +1523,7 @@ function wpcs_body_class($classes) {
add_filter("body_class", "wpcs_body_class");
/**
* 動修改html tag lang=""標籤為當前中文語
* 动修改html tag lang=""标签为当前中文语
* @since 1.0
*
*/