存储网站的多种语言版本的最佳方式是什么? [英] What is the best way to store multiple language versions of a website?

查看:26
本文介绍了存储网站的多种语言版本的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站(在 Linux 服务器上)需要支持多种语言.
拥有/存储同一站点的多种语言版本的最佳做法是什么?
我能想到的一些:

My web site (on Linux servers) needs to support multiple languages.
What is the best practice to have/store multiple languages versions of the same site?
Some I can think of:

  1. 存储在数据库中
  2. 每种语言的不同视图文件
  3. gettex
  4. PHP 文件中的硬编码词(如 phpBB)

推荐答案

对于网站,您确实需要考虑几类内容以进行本地化:

With web sites, you really have several categories of content to consider for localization:

  1. 在许多情况下,您会在 CMS 中创建、编辑和发布的文章类型的内容元素.
  2. 每个页面(或页面子组)共有的较小的内容块,例如标语、简介、联系表单周围的文本,以及导入的内容,例如新闻摘要或广告和附属链接.其中一些可能仅针对一种语言出现(例如,如果您不在某些地区提供某些服务,或者没有,例如,特定语言的适合语言的导入内容:删除一个元素而不是向可能不会说英语的人提供英语会更好).
  3. 纯功能元素,例如单击此处发表评论"、更多..."、高级导航等,有时它们是模板的一部分.其中一些可能位于图像内部.
  1. The article-type content elements that you would in many cases create, edit and publish in a CMS.
  2. The smaller content blocks that are common to every page (or a sub-group of pages), such as tagline, blurb, text around a contact form, but also imported content such as a news ticker or ads and affiliate links. Some of these may only appear for one language (for example, if you don't offer some services in some regions, or don't have, say, language-appropriate imported content for a particular language: it can be better to remove an element rather than offering English to people who may not speak it).
  3. The purely functional elements, like "Click here to comment", "More...", high-level navigation, etc., which are sometimes part of your template. Some of these may be inside images.

对于 1. 主要决定是是否使用 CMS.如果是,您绝对需要选择一种支持多种语言的语言.我不了解 PHP CMS 的最新发展,但一些 Django CMS 应用程序(Django-CMS-2、FeinCMS)支持多语言内容.不要忘记,例如,日期戳也需要本地化(或者您可以通过选择 ISO 日期来解决这个问题,尽管这可能并不总是可行).如果您不使用 CMS,并且所有内容都在您的 HTML 文件中,那么 gettext 是可行的方法,并将 .mo 文件(和您的离线 .po 文件)按语言保存在文件夹中.

For 1. the main decision is using a CMS or not. If yes, you absolutely need to choose one that supports multiple languages. I'm not up-to-date with recent developments in PHP CMS's, but several of the Django CMS apps (Django-CMS-2, FeinCMS) support multi-language content. Don't forget that date stamps, for example, need to be localized, too (or you can get around this by choosing ISO dates, though that may not always be possible). If you don't use a CMS, and everything is in your HTML files, then gettext is the way to go, and keep the .mo files (and your offline .po files) in folders by language.

对于 2. 如果您有一个支持多语言的 CMS,请尽可能多地了解 CMS.原因是这些位确实发生了变化,您希望尽可能少地编辑模板.如果您自己编写代码,请考虑导出每种语言的所有 CMS 内字符串的方法,以便将它们交给翻译人员.否则,再次gettext.主要问题是这些元素可能需要硬编码语言选择代码(if $language = X display content1 ...)

For 2. if you have a CMS with good multi-lingual support, get as much as possible inside the CMS. The reason is that these bits do change, and you want to edit your template as little as possible. If you write code yourself, think of ways of exporting all in-CMS strings per language, to hand them to translators. Otherwise, again, gettext. The main issue is that these elements may require hard-coding language-selection code (if $language = X display content1 ...)

对于 3.,如果它在您的模板中,请使用 gettext.对于图像,每种语言的文件夹将派上用场,看在上帝的份上,请选择可以自动生成的图像,否则您(或您的图形艺术家)会发疯地编辑 100 多个带有字符串的自定义图像不明白.

For 3., if it's in your template, use gettext. For images, the per-language folders will come in handy, and for heaven's sake make choose images the generation of which can be automated, or you (or your graphic artist) will go mad with editing 100s of custom images with strings in languages you don't understand.

对于 2. 和 3.,从语言选择中提取可能有助于选择适当的块或内容目录(保存本地化图像或 .mo 文件的位置).

For both 2. and 3., abstracting from the language selection may help selecting the appropriate blocks or content directory (where localized images or .mo files are kept).

您绝对要避免的是保留一堆 HTML 文件,其中包含大量文本内容,这将是维护的噩梦.

What you definitely want to avoid is keeping a pile of HTML files with extensive text content in them that would be a nightmare to maintain.

关于 gettext、.po 和 .mo 文件的所有内容都在 GNU gettext 手册(比您想知道的还要多)或稍微过时但更友好的教程.对于 PHP,有 PHP gettext 函数,还有 Zend Locale 文档

Everything about gettext, .po and .mo files is in the GNU gettext manual (more than you ever wanted to know) or a slightly dated but friendlier tutorial. For PHP, there's are the PHP gettext functions, and also the Zend Locale documentation

这篇关于存储网站的多种语言版本的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆