Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

zh-cn:多语言的 WordPress 站点

WordPress 并不支持原生开箱即用的双语或多语站点。然而,WordPress社区已经开发了多款插件帮您轻松地构建多语言站点。

简单来说,创建多语言博客就是指安装多种语言的WordPress,并使用插件在语言之间切换。多数插件都会需要您手工安装 .mo 语言文件,请参阅 zh-cn:使用您的母语安装WordPress 了解详情。

WPGlobusPolylangqTranslatexili-language 都是可在单一 WordPress 网站副本中安装的插件。对于多站点 WordPress (即每个语言一个站点),你需要尝试 Multisite Language SwitcherZantoMultilingual Press, 也可以选择购买 WPML.

不同种类的多语插件

可选多语言插件存在不少版本:

  1. 每种语言一个帖子的管理方式(例如: WPML - 收费,xili-languagePolylangBogo)各语种的翻译彼此链接,从而表示出某贴是另一帖的翻译。
  2. 在同一个帖子中存储所有可选语言(比如: qTranslateWPGlobus
  3. 在生成的页面而不是帖子里管理翻译。(比如: Transposh 以及 Global Translator
  4. 使用外部机翻服务的插件(比如: Google AJAX Translation
  5. 还有像 Multisite Language SwitcherMultilingual Press 以及 Zanto 这样,把几个不同语言的独立 WordPress 副本组成网络的(类似站群效果)。


每个帖子一种语言

指需要每个帖子设定一种语言的多语插件。用户需要选择给帖子制定一种语言,并将新语种的翻译作为新帖(页面,标签或类别也是一样)发布。

这样相同内容的不同版本被连接到一起组成一个多语种的集合。通过这种分组来帮助用户在多种显示语言之间切换。

优点:

  1. 数据库中的内容始终不曾被修改(易于安装与卸载)
  2. Everything gets translated by default. If a post includes custom fields, they're attached to that post, so they are already associated with the language.
  3. Some plugins use - for theme's displayed terms - the language files (.mo) delivered with localizable themes. In WordPress, localization is based in GNU gettext technology. So when a single post is in french, plugin switch all the terms of the theme in the same language (here french). The files can be completed with the specific terms of the site (categories titles, widget, links...). No need to re-translate all, just add specific terms and translations in target languages.
  4. 其他需要分析内容的插件 (比如相关帖子的插件) 也可以继续正常工作。

缺点:

  1. 更加复杂的构架。插件需要引用许多 WordPress 的功能,并且过滤掉不相干的内容,从而只返回语言相匹配的帖子。
  2. 部分插件需要额外的表——通常用于存储翻译的分组信息。一些新的插件则更倾向于使用自定义的分类逻辑,或者帖子的元数据来代替。
  3. 可能导致过分的数据库膨胀,并最终导致性能的下降。举例而言,一个基于 WooCommerce 的网站,要存储5种不同的语言版本,那么十万条产品记录可能就需要存储50万条记录。还没提产品的元数据呢(可能每种产品有十条元数据,并且临时数据也会冗余,结果嘛当然是超大的数据库咯)

同一个帖子包含所有语言

将所有语言的翻译保存在相同的帖子内,并使用语言元数据标签区分不同语言的内容的多语插件。在显示帖子的时候,它会先预处理一些帖子,并只保留当前激活语言的内容。

优点:

  1. 并排编辑变得很容易实现。
  2. 会打破更少的东西。比如无需额外的表,在 WordPress 中也少了很多需要修改的东西。
  3. 不管你用哪种语言的关键词来搜的,搜索引擎始终返回相同的帖子。
  4. 数据库里的记录数保持不变

缺点:

  1. 卸载会很麻烦滴。因为需要清理到数据库里的多语言内容。

在生成页中管理翻译版本

Multilingual plugins that use the content pages generated by WordPress and perform translation on those pages. When any page is displayed on WordPress the plugin (either offline or online) attempts to create a translated version of the page using machine translation. Later on that translation can be manually changed or modified.

优点:

  1. Installation is simple and translation for any content on the page is provided.
  2. Editing the translation can be done with ease.

缺点:

  1. Automatic translation is not good enough and pages on the site might be badly translated.
  2. There's a strong coupling between content and translation, and changes in the original content might break the translation.

引用外部翻译服务的插件

Those Multilingual plugins are normally used to create a widget that creates a shortcut for using online translation services (such as Google Translate). The content is auto translated on demand by the third party engine.

优点:

  1. Installation is simple and translation for any content on the page is provided.
  2. It is quite clear that the translation process is automated, so the users expectations are lowered.

缺点:

  1. 自动翻译总是不够好,站点内的页面可能被翻译地很渣。
  2. Without the ability to change the translation those plugins limit the ability of the content publisher to provide quality translated content.

每种语言都安装各自的副本

为你想要提供翻译的每一种语言都创建一个独立站点(举例而言 WordPress Multisite比如)。所有站点都需要运行相同的主题和插件。When a translation is saved source posts get pinged by translation posts and the system keeps a separate table with the translation relationships.

优点:

  1. Each language site is a regular WordPress install with regular posts (postmeta and external db is used for translation data)
  2. If you turn off the plugin the content continues to work fine, albeit without knowledge of its sources/translations.

缺点:

  1. 分离站点会导致网站管理工作量的增加,这可不是我们想要的。

Language negotiation

Language negotiation means how to determine the language in which users see the site.

Regardless of the solution for storing multilingual contents, multilingual plugins also need to be able to choose which language to display in.

Normally, the URL indicates the display language. Different URL strategies for encoding language information are:

  • Add the language name as a parameter: example.com/?lang=en or example.com/?lang=es
  • Add virtual 'directories' as language names: example.com/en/ or example.com/es/
  • Use different domains for different languages: www.example.com or es.example.com

如何选择适合你的多语方案

Choosing the most suitable multilingual Plugin for your needs will take some time. See the WordPress Plugin Directory for a list of multilingual Plugins.

There is not only one way but a way adapted to the content strategy, the data-model, the number of posts and pages, and the behavior/experience expected by visitors. And for WordPress Network (multisite), a good knowledge of server administration is required.

In any case, installing a multilingual plugin is a big change for any site. It would be a good idea to first create a test site and verify that everything works correctly between all the required plugins and the theme and only then install.

Since many multilingual plugins change the database significantly, doing a database backup is required before experimenting.

相关