设置多语言网站最有效的方法是什么
我正在开发一个以不同语言提供的网站。它是一个 LAMP(Linux、Apache、MySQL、PHP)设置,它使用 Smarty,主要用于模板引擎。
我们目前的翻译方式是通过自己编写的smarty插件,它会识别HTML文件中的某些标签,并会在之前定义的语言文件中找到相应的标签。
HTML 可能如下所示:
<p>Hi, welcome to $#gamedesc;!</p>
语言文件可能如下所示:
gamedesc:Poing 2009$;
welcome:this is another tag$;
然后将输出
<p>Hi, welcome to Poing 2009!</p>
这个系统非常基本,但如果我想跟踪到目前为止已翻译的内容,或者授予某些用户仅翻译某些标签的权利,则很难控制。
我一直在寻找一些替代方法来解决这个问题,要么用可以存储一些额外元数据的 XML 文件替换文本文件,要么将所有文本存储在数据库中,然后在那里检索它。
我的问题是,使该系统既可维护又可在高用户流量下良好运行的最佳方法是什么?也许有我可以看一下的(轻量级)插件吗?
I'm developing a website that will be available in different languages. It is a LAMP (Linux, Apache, MySQL, PHP) setup, and it makes use of Smarty, mostly for the template engine.
The way we currently translate is by a self-written smarty plugin, which will recognize certain tags in the HTML files, and will find the corresponding tag in an earlier defined language file.
The HTML could look as follows:
<p>Hi, welcome to $#gamedesc;!</p>
And the language file could look like this:
gamedesc:Poing 2009$;
welcome:this is another tag$;
Which would then output
<p>Hi, welcome to Poing 2009!</p>
This system is very basic, but it is pretty hard to control, if I f.e. would like to keep track of what has been translated so far, or give certain users the rights to translate only certain tags.
I've been looking at some alternative ways to approach this, by either replacing the text-file with XML files which could store some extra meta-data, or by perhaps storing all the texts in the database, and retrieving it there.
My question is, what would be the best way to make this system both maintainable and perform well with high user-traffic? Are there perhaps any (lightweight) plugins I could take a look at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试 gettext。这是大多数 C/C++ Linux 应用程序的完成方式,它也是 PHP 的扩展。这个想法与您已经在做的事情没有太大不同,但是有一些工具可以简化翻译的维护(即 poedit )。
对于用户的翻译权限, gettext 不会有太大帮助,我认为您需要自己做,或者查看一些框架(如果它们有更智能的解决方案)。
You could give a shot at gettext. It is the way it is done in most C/C++ linux applications and it is an extension to PHP too. The idea is not very different from what you're already doing, but there are tools that ease the mantainance of translations (i.e. poedit).
For user rights to translations, gettext won't be of much help, I think you'll need to do it on your own or look at some frameworks if they have smarter solutions.
也许查看 gettext lib 可以帮助您获得一些提示 http://php.net /manual/en/book.gettext.php希望有帮助!
Maybe taking a look to gettext lib could help you get some hints http://php.net/manual/en/book.gettext.php hope it helps!
您的数据库中需要有一个表,可用于存储文本字符串,每个字符串都有一个复合 ID。复合ID将由语言ID和文本节点ID组成。
您需要让用户有机会选择首选语言。您应该确保您使用的每种语言都有一个默认的“尚未翻译”,或者您的整个网站都可以使用的默认语言。
对于网站中的每一个文本,而不是存储页面中的文本,您只需为其分配一个 ID。
提供页面时,查找文本节点 ID 和首选语言 ID 并加载该文本字符串或默认字符串。
You will need to have a table in your database that you can use to store strings of text, each with an composite ID. the composite ID will be made up of language ID and text node ID.
You will need to give the user a chance to select a preferred language. You should make sure that you either have a default "this has not been translated" for every language you use, or a default language that your entire site can be vied in.
For every bit of text with in your web site, rather then store the text with in the page, you just assign it an ID.
When serving the page, look up the text node ID and preferred language ID and load that string of text, or the string for the default.
在我们的项目http://pkp.sfu.ca/ojs中,我们使用XML文件来存储翻译键值对。浏览我们的代码:http://github。 com/pkp/pkp-lib/blob/master/classes/i18n/PKPLocale.inc.php
我们使用该类来读取每个语言环境的 XML 文件,在我们的代码中我们使用 Locale::translate('locale .key.name');。与 gettext 类似,但使用 XML 文件以便于更新。
in our project, http://pkp.sfu.ca/ojs, we use XML files to store translation key-value pairs. Browse our code: http://github.com/pkp/pkp-lib/blob/master/classes/i18n/PKPLocale.inc.php
We use that class to read the XML files for each locale and in our code we use Locale::translate('locale.key.name');. Similar to gettext, but using an XML file for easier updating.
今天浏览网络资料时,我发现了这个网站: http://translateth.is/
它看起来使用起来很简单...复制粘贴一些JavaScript。
Looking around at web stuff today I came across this website: http://translateth.is/
It looks simple to use... copy paste in some javascript.