Drupal7做一个双语站

来源:互联网 发布:生活中的人工智能产品 编辑:程序博客网 时间:2024/04/28 15:57

本文主要讲解Drupal7做一个双语站:简体中文、英文。方法同样可以应用在Drupal6和Drupal8。

lixiphp drupal frontpage Drupal如何做一个双语站

步骤

1)建立一个Drupal站点的启用Locale 和 Content translation module模块。 
2)配置Drupal站点支持多语言,包括三种语言中文简体,中文繁体,英语(默认)。

drupal languages list 配置Drupal站点支持多语言,包括三种语言中文简体 中文繁体 英语

3)配置语言检测,激活检测方法“浏览器”(检测我的浏览器的语言设置的优先语言)。

drupal language detection selection 配置语言检测,激活检测方法“浏览器”

4)改变Firefox如何发送Accept-Language header头部信息。进入“首选项”,“内容”选项卡,然后在“选择…”按钮,通过“选择您显示页面的首选语言”。

 English language preferred 改变Firefox如何发送Accept-Language header? 
5)确认,语言能正确的检测到英语,并正确的使用英语显示页面,当使用英语作为默认的Accept-Language Header。

请求报头(Accept-Language 为en-us)

GET / HTTP/1.1Host: www.lixiphp.comUser-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.7.1Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip, deflateCookie: has_js=1; __utma=160924194.585573359.1364388874.1364388874.1364388874.1; __utmb=160924194.21.10.1364388874; __utmc=160924194; __utmz=160924194.1364388874.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Drupal.tableDrag.showWeight=0x-insight: activateConnection: keep-aliveIf-None-Match: "1364390561"

响应报头(自动跳转到http://www.lixiphp.com/en英语路径)

HTTP/1.1 301 Moved PermanentlyServer: nginx/0.8.49Date: Wed, 27 Mar 2013 13:23:00 GMTContent-Type: text/htmlTransfer-Encoding: chunkedConnection: keep-aliveKeep-Alive: timeout=20X-Powered-By: PHP/5.2.9Expires: Sun, 19 Nov 1978 05:00:00 GMTCache-Control: no-cache, must-revalidate, post-check=0, pre-check=0Etag: "1364390579"Location: http://www.lixiphp.com/en

6)确认,语言能正确的检测到简体中文,并正确的使用简体中文显示页面,当使用简体中文作为默认的Accept-Language Header。

请求报头(Accept-Language 为zh-cn)

GET / HTTP/1.1Host: www.lixiphp.comUser-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.7.1Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-cn,en-us;q=0.7,en;q=0.3Accept-Encoding: gzip, deflateCookie: has_js=1; __utma=160924194.585573359.1364388874.1364388874.1364388874.1; __utmb=160924194.22.10.1364388874; __utmc=160924194; __utmz=160924194.1364388874.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Drupal.tableDrag.showWeight=0x-insight: activateConnection: keep-aliveIf-None-Match: "1364390579"

响应报头(自动跳转到http://www.lixiphp.com/zh-hans简体中文路径)

HTTP/1.1 301 Moved PermanentlyServer: nginx/0.8.49Date: Wed, 27 Mar 2013 13:29:37 GMTContent-Type: text/htmlTransfer-Encoding: chunkedConnection: keep-aliveKeep-Alive: timeout=20X-Powered-By: PHP/5.2.9Expires: Sun, 19 Nov 1978 05:00:00 GMTCache-Control: no-cache, must-revalidate, post-check=0, pre-check=0Etag: "1364390977"Location: http://www.lixiphp.com/zh-hans

7)添加“语言切换器(用户界面文本)”区块在头部

如果需要一些修饰,可以在语言前面加上国旗,最后就会得到:

drupal language with flag 语言切换器

演示与说明

演示地址:http://www.lixiphp.com

如果你的浏览器默认是简体中文,自动会跳转到http://www.lixiphp.com/zh-hans

页面内容为:

欢迎光临 LixiPHP

首页无内容!

如果你的浏览器默认是英文,自动会跳转到http://www.lixiphp.com/en

页面内容为:

Welcome to LixiPHP

No front page content has been created yet.

赶紧入手尝试一下Drupal建立一个双语站吧!



0 0
原创粉丝点击