存储网站的多种语言版本的最佳方式是什么?
我的网站(在 Linux 服务器上)需要支持多种语言。
拥有/存储同一网站的多种语言版本的最佳实践是什么?
我能想到的一些:
- 在数据库中存储
- 每种语言的不同视图文件
- gettex
- PHP 文件中的硬编码字(例如在 phpBB 中)
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:
- store in DB
- different view file for each language
- gettex
- hard coded words in PHP files (like in phpBB)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于网站,您实际上需要考虑几类内容进行本地化:
对于 1. 主要决定是是否使用 CMS。如果是,您绝对需要选择一种支持多种语言的语言。我不太了解 PHP CMS 的最新发展,但几个 Django CMS 应用程序(Django-CMS-2、FeinCMS)支持多语言内容。例如,不要忘记日期戳也需要本地化(或者您可以通过选择 ISO 日期来解决这个问题,尽管这可能并不总是可行)。如果您不使用 CMS,并且所有内容都在 HTML 文件中,那么
gettext
是最佳选择,并将 .mo 文件(以及离线 .po 文件)按语言保存在文件夹中。2.如果您的 CMS 具有良好的多语言支持,请在 CMS 中获得尽可能多的信息。原因是这些位确实会发生变化,并且您希望尽可能少地编辑模板。如果您自己编写代码,请考虑导出每种语言的所有 CMS 字符串的方法,以便将它们交给翻译人员。否则,再次
gettext
。主要问题是这些元素可能需要硬编码语言选择代码(if $language = X display content1 ...
)对于 3.,如果它在您的模板中,请使用
gettext
。对于图像,每种语言的文件夹会派上用场,并且看在上帝的份上,请选择可以自动生成的图像,否则您(或您的图形艺术家)会因为使用您所使用的语言的字符串编辑数百个自定义图像而发疯。不明白。对于 2. 和 3.,从语言选择中抽象可能有助于选择适当的块或内容目录(其中保存本地化图像或 .mo 文件)。
您绝对要避免的是保留一堆包含大量文本内容的 HTML 文件,这对维护来说将是一场噩梦。
编辑:有关 gettext、.po 和 .mo 文件的所有内容都在 GNU gettext 手册中(比你想知道的还要多)或稍微过时但更友好的教程。对于 PHP,有 PHP gettext 函数,还有 Zend 语言环境文档
With web sites, you really have several categories of content to consider for localization:
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.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 ...
)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.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).
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.
EDIT: 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
我建议使用 Zend_Translate 的 Gettext 适配器来解析 mo 文件。非常高效+缓存。您的调用将类似于
Which 会找到该指定字符串的区域设置特定键。
I recommend using Zend_Translate's Gettext adapter which parses mo files. Very efficient + caching. Your calls would be like
Which would find the locale specific key for that specified string.
查看 php 的 i18n 支持: http://php-flp.sourceforge.net/getting_started_english.htm
Check out i18n support for php: http://php-flp.sourceforge.net/getting_started_english.htm