在用Drupal 7搭建新网站时,根据具体情况可以添加多语言及手机版,我记录在博文《Drupal的多语言系列网站搭建和设置》中。
在对更早使用Drupal 6已经搭建起来的网站进行扩充添加多语言及手机版的时候,过程也类似,只是稍微有些不同,下面我也记录一下过程:
初期准备:
- 模块:如果是系列网站,可以做一个统一的模块,包含各站通用的block等,并且指定此模块的翻译文件,便于以后的翻译更新;
- 翻译:48种语言的翻译文件统一做,覆盖系列网站所需要的各种单词、短语、句子,用l10n_update来导入、更新;
- 目录:sites目录下添加手机版站点目录及settings.php文件,可以修改电脑版的settings.php,其中自行判断网址来确定是否启用nokia mobile皮肤,然后手机版目录就只需要软链接到电脑版目录;
- 模块:设置模块,关闭不需要的模块,下载和安装需要的模块,特别是多语言支持所用的i18n及部分子模块(最初是多数都打开,后来改为只有需要的几个打开)、l10n_update翻译自动更新模块、nokia mobile皮肤等,添加48种语言(一个站添加后,其它站复制其数据库的languages表),都可以通过drush来进行设置;
- 缓存:可以关闭boost cache功能,以免添加50种语言后生成的缓存文件过多过大;
修改设置:
- 翻译:可以将各个站不同的分类词等翻译做成一个po文件,目前主要是中文地名,导入翻译库,以后可以考虑每个站增加一个专门的模块,对应专门的几十种语言地名翻译文件;
- 名称:修改content type, content fields, vocabulary taxonomy里面的name,将以前中英文双语改为英文,以便翻译能够有效;
- 菜单:修改菜单设置,Home、Contact Us可以去掉,其它的尽量用views生成的,少用专门做的page;
- 查询:修改views,将views名称、标题、显示字段的label都由中英文双语改为英文,每行显示数量、每页显示数量更加具体情况进行调整,以便手机版显示清晰,header, footer根据需要来进行修改;
修改程序:
- 模板:修改显示模板,可以将contemplate从数据库转移到磁盘文件的形式,在sites/xxx下创建contemplates目录,放置node-typename-body.tpl.php,更改后便于保存历史版本,注意手机版可以通过软连接指向同一个模板文件,在文件中再进行判断、处理,改用磁盘文件方式后,电脑版、手机版都需要在后台管理页面中刷新,以便contemplate更改生效;
- 首页:修改首页,去掉首页网址别名,增加misson显示,修改site information中的首页链接为node/xxx,去掉Mission和Footer message内容;
- 区块:修改block设置,电脑版、手机版中都显示语言切换、电脑/手机切换,以前的header, footer改用统一模块中的header, footer,对分类页顶部、底部的block根据具体情况进行修改或替换,检查电脑版、手机版的各种页面显示,根据需要来调整顺序、是否需要添加顶部/底部广告等;
网站地图:
- 添加:检查xml sitemap的设置,首页更新周期从weekly改为monthly,最早的default改为en,然后添加其它的48种语言,这个添加的过程手工太慢,可以直接用phpMyAdmin修改数据库中的xmlsitemap_sitemap表,用INSERT INTO `xmlsitemap_sitemap` (`smid`, `context`, `updated`, `links`, `chunks`, `max_filesize`) VALUES ('LZa-7jhy2SBG0FuW3jja03SHjgSZ8QIoG3AnsQoOmy8', 'a:1:{s:8:"language";s:2:"af";}', 0, 0, 0, 0),('LKmx_ZVMy7dOYfDz0RjgPeF1gGWia54MlPtIrVIOgjA', 'a:1:{s:8:"language";s:2:"cy";}', 0, 0, 0, 0);这样的语句批量添加;
- 生成:用drush xmlsitemap-regenerate或者drush xmlsitemap-rebuild来重新生成49种语言的站点地图;
- 提交:用程序调用google webmaster tools api提交站点地图到webmaster tools中去,有电脑版、手机版共98个。
后续收尾:
- 跳转:根据需要来修改.htaccess文件,实现自动判断用户终端类型,手持终端自动跳转到手机版本;
- 链接:修改以前的博客文章(jamesqi.com)、各相关网站(youbianku.com)、各系列网站(postcodebase.com,mingluji.com,bizdirlib.com)的相关页面,添加到多语言手机版的链接。
从上面的步骤来看,这个过程还是相当复杂的,做起来需要费不少时间,重点是做各种检查:首页、分类页、views页、内页、菜单,电脑版、手机版,多种语言,页面显示内容、源代码keywords/description、microdata等,这还只是做多语言、手机版的扩展,更深入的各个站数据分析、优化排列导航等可以留待今后再进行,真是改进无止境啊!
评论3
英文以外的48种语言xmlsitemap添加代码
在MySQL中直接执行以下代码,以便快速添加:
INSERT INTO `xmlsitemap_sitemap` (`smid`, `context`, `updated`, `links`, `chunks`, `max_filesize`) VALUES ('LZa-7jhy2SBG0FuW3jja03SHjgSZ8QIoG3AnsQoOmy8', 'a:1:{s:8:"language";s:2:"af";}', 0, 0, 0, 0), ('R4VND5L097ddYE6wDXaN5Jl7CqlrRkI227laTrqdQzI', 'a:1:{s:8:"language";s:2:"sq";}', 0, 0, 0, 0), ('3QWhCTe7KQ0ZR-MqzkhYgq7PkekhXoahRK0-ktC9198', 'a:1:{s:8:"language";s:2:"ar";}', 0, 0, 0, 0), ('rEA7Ume326CMKb7huj3-iZNj8dgxwytUE_QKafGPoS8', 'a:1:{s:8:"language";s:2:"hy";}', 0, 0, 0, 0), ('_FuRjiXoiaiYVERsV6LaopM3QXdVIco8fTq4juua7dA', 'a:1:{s:8:"language";s:2:"az";}', 0, 0, 0, 0), ('Ws6Pk8Ccl-kGwmsqzRfJRYC5u0_rI4DDI11AQdPNhTY', 'a:1:{s:8:"language";s:2:"bg";}', 0, 0, 0, 0), ('aNkRiCzjfJQdg8nBocBcXhm1bm6WLTXsKRTh-yDHMc8', 'a:1:{s:8:"language";s:2:"ca";}', 0, 0, 0, 0), ('3QuYVMoAVDdMUmwuEdFhwSFxLtcBNDrxIy91p4VzGdY', 'a:1:{s:8:"language";s:7:"zh-hans";}', 0, 0, 0, 0), ('gNQigJ8V6aUMKO8U3wkd4y04rttp_RCe6uGO4kXyQnU', 'a:1:{s:8:"language";s:7:"zh-hant";}', 0, 0, 0, 0), ('igVpPQY_QVAMYlftsuIhWLnR9NOb52mZ9URjmMzBHqk', 'a:1:{s:8:"language";s:2:"hr";}', 0, 0, 0, 0), ('JqsSZ0ACA-VztmE3q054r5qUF8LYCLshZpXn9ZWOgYo', 'a:1:{s:8:"language";s:2:"cs";}', 0, 0, 0, 0), ('87mlCzCcgPXzQvm2qE3Is2lMA7b3UyFAJgnINaSi04Y', 'a:1:{s:8:"language";s:2:"da";}', 0, 0, 0, 0), ('VYOTF4bQdgrfTJyQddsbQTYCd13NBvx-ifXqmOhuH9w', 'a:1:{s:8:"language";s:2:"nl";}', 0, 0, 0, 0), ('I9T_cIxer-FMIaMXxRrx5-bnxgj16Z55dELZHsSb0SQ', 'a:1:{s:8:"language";s:2:"eo";}', 0, 0, 0, 0), ('4Cb0X8hFMUkO3ED6IxmWAWSWup0KInr0U1kPzHui9xY', 'a:1:{s:8:"language";s:2:"et";}', 0, 0, 0, 0), ('PYgq5vYzAuvYMcuKajN7voJEvUlYuPXv7goZjmMJ8Fk', 'a:1:{s:8:"language";s:2:"fi";}', 0, 0, 0, 0), ('2e9ZfIfLFCC0V-PbcDKUTb1Wk22XgjzJ6f-b16CFlPE', 'a:1:{s:8:"language";s:2:"fr";}', 0, 0, 0, 0), ('V6W10nlwnkf_N8uu4GwUpZ_dbf-e66z8IcMdkWyzUQM', 'a:1:{s:8:"language";s:2:"gl";}', 0, 0, 0, 0), ('FY_-EiR_oa31k2g2U3tQi1FdUv4LT0KDDxOamtSjyi8', 'a:1:{s:8:"language";s:2:"ka";}', 0, 0, 0, 0), ('oWx2Pl033k1XFmYJFOs7sO0G3JasH0cjDbduvDwKuwo', 'a:1:{s:8:"language";s:2:"de";}', 0, 0, 0, 0), ('XYbrhwAOg0sH5tuc45W4YgKnq1SObpmzxm9kN1Dy3QI', 'a:1:{s:8:"language";s:2:"el";}', 0, 0, 0, 0), ('Q-DnbT83L1sy4kAX_nYRCyT4AJOTpg30-XEPI1hmyNg', 'a:1:{s:8:"language";s:2:"hu";}', 0, 0, 0, 0), ('QLefgmOMHyi_NiinQJa9AKCQNccFfPrNIdRGIqQJXXo', 'a:1:{s:8:"language";s:2:"is";}', 0, 0, 0, 0), ('G11UQ93ugnrx9ZOPe8RHDN4OJ7uYSZCYtF9EOrlEQlA', 'a:1:{s:8:"language";s:2:"ga";}', 0, 0, 0, 0), ('o1lnqD7hynYmesOfRQVh_UIPswJqoj5Mjjb0krTsxBI', 'a:1:{s:8:"language";s:2:"it";}', 0, 0, 0, 0), ('4vXFu1xAuZ1nftmnnfowGaQ0yrARIcSvgyG5T7cqg04', 'a:1:{s:8:"language";s:2:"ja";}', 0, 0, 0, 0), ('zqY91BRIiHW3IzuCP7ygvlayDVv_LsCV3gx5oYyZM0c', 'a:1:{s:8:"language";s:2:"ko";}', 0, 0, 0, 0), ('2KhpMoaeN8AdO8hifieREj7vkzINMolX97tRzkIQ3BQ', 'a:1:{s:8:"language";s:2:"lv";}', 0, 0, 0, 0), ('kkE2MTArkFb4S-r2Nve1rlFEv86OTmedrSd0DhgfCtE', 'a:1:{s:8:"language";s:2:"lt";}', 0, 0, 0, 0), ('qaKz2M8Q1Hx-usBG6hz7uJXmOAF1PVvM3WmgLsQE62Y', 'a:1:{s:8:"language";s:2:"mk";}', 0, 0, 0, 0), ('ehIYDa6eZtWBG9ofuU3JJwe7ePsWdnOwkygkE_8UlIk', 'a:1:{s:8:"language";s:2:"ms";}', 0, 0, 0, 0), ('caOAq7WZXTCbDsMfG81QIbCf0bkLMDWBxOrYdWgeMMU', 'a:1:{s:8:"language";s:2:"mt";}', 0, 0, 0, 0), ('JujatUJ6eea9-3GLZFmBcT7CgN2qXYl-odpyftFpjYI', 'a:1:{s:8:"language";s:2:"fa";}', 0, 0, 0, 0), ('h_Rziqj_J13oB-imJ4qIG8ksKWXWZ_Hynp5POSsd07k', 'a:1:{s:8:"language";s:2:"pl";}', 0, 0, 0, 0), ('cJKZwij0C3MEWV1FN_hbRiNhXls614wbansVqEAuRc4', 'a:1:{s:8:"language";s:5:"pt-pt";}', 0, 0, 0, 0), ('GI3xOGu1J_C9ymceu4SPSzs6JE8tv61AEnpI3lzXVW0', 'a:1:{s:8:"language";s:2:"ro";}', 0, 0, 0, 0), ('_KyYVoP1pMRSEJD8cDQst9Nj-h1vo7ZVPnvdm5RCdy4', 'a:1:{s:8:"language";s:2:"ru";}', 0, 0, 0, 0), ('s0XnmLCtZcWgnQ7ZFew1Fhtbt9EQ38Ddg7J87BGJ2ys', 'a:1:{s:8:"language";s:2:"sr";}', 0, 0, 0, 0), ('40Vfh2LHqOFN8RF3OKzRCh_w_cwudpGkr0xa3V2yFqY', 'a:1:{s:8:"language";s:2:"sk";}', 0, 0, 0, 0), ('x6B8OtrKWrEaGY6P503gk4XvAlmc1lRjZsZKbrZZp2Y', 'a:1:{s:8:"language";s:2:"sl";}', 0, 0, 0, 0), ('t9UQ7FvqR0wMQMnd5n2XukH0kM9liAM9wOhfSLRl2qw', 'a:1:{s:8:"language";s:2:"es";}', 0, 0, 0, 0), ('7p_cwXvUFez4aPn5SewMmsgoJ2J6qRNN2mgf8hEe3mU', 'a:1:{s:8:"language";s:2:"sw";}', 0, 0, 0, 0), ('t16K-LvlM4dINVHfcxC__57flE1iMIVnUezIVBDDZfE', 'a:1:{s:8:"language";s:2:"sv";}', 0, 0, 0, 0), ('5x3-O5uUfArK1LK8i29anopPRkWTuhyFnzYWdcyBrso', 'a:1:{s:8:"language";s:2:"th";}', 0, 0, 0, 0), ('4t2LDT2-5kkWXwt0FTm6JNAFOdzcz7Fs55mzMuovLmc', 'a:1:{s:8:"language";s:2:"tr";}', 0, 0, 0, 0), ('T43qaxwUQWS5cOCpwG2tGLGOF5UzykA0K-mCFL6oRhs', 'a:1:{s:8:"language";s:2:"uk";}', 0, 0, 0, 0), ('uIMIDC5eEaw7jcWdnI3wjc67eo8miZwUihIKzFid2oA', 'a:1:{s:8:"language";s:2:"vi";}', 0, 0, 0, 0), ('LKmx_ZVMy7dOYfDz0RjgPeF1gGWia54MlPtIrVIOgjA', 'a:1:{s:8:"language";s:2:"cy";}', 0, 0, 0, 0); 另外一个bel中有的暂不加: ('Cnvxov87lqV5zVrYi_CjzUuzdaJJjXuMgGom6z2VYXo', 'a:1:{s:8:"language";s:2:"nb";}', 0, 0, 0, 0),
插入languages表来添加48种语言
不用上面的MySQL插入表办法,而是在Drush中运行PHP的办法如下:
避免Nokia Mobile过滤Javascript的问题
最近在进行多语言扩展的时候,手机版的语言选择Language Switcher Drop Down是有的,但却不跳转,检查了很长时间,其实2年前就有类似这样的问题,当时是修改sites/all/themes/nokia_mobile/template.php来去掉判断的,这次再这样设置就可以了,唉白白又浪费了N多个小时!