1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【JavaScript】让你的网站支持简体繁体切换

Posted at

具体实现:

  1. 首先,点击这里右键另存下载简繁字体切换所需的tw_cn.js文件,上传到自己的网站空间。
  2. 其次,修改模板,在你想要显示简繁转换按钮的地方加上下面一段代码,正常情况添加到header.php或者siderbar.php就可以了。
<a id="translateLink" href="javascript:translatePage();">繁體</a>
最后,在footer.php添加下面代码,记得更改cookieDomain这一项。
<script type="text/javascript" src="http://achillessatan.github.io/js/tw_cn.js"></script>
<script type="text/javascript">
  var defaultEncoding = 2; //网站编写字体是否繁体,1-繁体,2-简体
  var translateDelay = 0; //延迟时间,若不在前, 要设定延迟翻译时间, 如100表示100ms,默认为0
  var cookieDomain = "http://achillessatan.github.io/"; //Cookie地址, 一定要设定, 通常为你的网址
  var msgToTraditionalChinese = "繁體"; //此处可以更改为你想要显示的文字
  var msgToSimplifiedChinese = "简体"; //同上,但两处均不建议更改
  var translateButtonId = "translateLink"; //默认互换id
  translateInitilization();
</script>

这就基本完成了简体繁体切换功能,不管你是hexo,jelly,Octopress等静态博客,还是wordpress,typecho,emlog,Z-Blog等动态的,都可以用上。具体的演示效果可以点击我博客底部简体中文切换字体,至于简体繁体切换按钮嘛,文字和样式可以按个人喜好自行更改。

原文地址: http://www.arao.me/2015/hexo-support-jian-fan-language/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?