编写多语言网站 - 如何根据语言有效地输出字符串 [英] Writing multilingual site - how to effectively output strings depending on language

查看:49
本文介绍了编写多语言网站 - 如何根据语言有效地输出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算用几种语言写网站。出于这个原因,我试图找到最方便的输出字符串的方法,取决于他们的

唯一ID。至于我打算翻译相当多的字符串,我很担心在服务器上任何方法可能有
的性能问题。也许有人已经解决了那种问题,可以分享他/她在这件事上的经验。

解决方案

ro********@gmail.com 写道:
< blockquote class =post_quotes>
我打算用几种语言写网站。出于这个原因,我试图找到最方便的输出字符串的方法,取决于他们的

唯一ID。至于我打算翻译相当多的字符串,我很担心在服务器上任何方法可能有
的性能问题。也许有人已经解决了那种问题,可以分享他/她在这件事上的经验。



我用过两种方法:

1. http ://ca.php.net/manual/en/ref.gettext.php

2.我自己的图书馆到数据库中的翻译表


-david-


我个人把每种语言的文本放到一个单独的文件中,然后加载

那个在每个脚本的开头将文件存入内存。因此从内存中取出每个字符串

。因为

整个文件只有一个磁盘I / O,而不是每一段文本,所以速度非常快。


这是记录在
http://www.tonymarston.net/php-mysql ... alisation.html


HTH


-

Tony Marston http://www.tonymarston.net
http://www.radicore.org


< ro ** ****** @ gmail.com写信息

新闻:11 ********************* @ h48g2000cwc.googlegro ups。 com ...


>我打算用几种语言写网站。出于这个原因,我试图找到最方便的输出字符串的方法,取决于他们的

唯一ID。至于我打算翻译相当多的字符串,我很担心在服务器上任何方法可能有
的性能问题。也许有人已经解决了那种问题,可以分享他/她在这件事上的经验。



< blockquote>
ro********@gmail.com 写道:


我打算用几种语言写网站。出于这个原因,我试图找到最方便的输出字符串的方法,取决于他们的

唯一ID。至于我打算翻译相当多的字符串,我很担心在服务器上任何方法可能有
的性能问题。也许有人已经解决了那种问题,可以分享他/她在这件事上的经验。



GetText是标准方法。有一个PHP扩展。你写了

字符串,如


_(''Hello bob'')


然后提取通过一些gettext命令行工具。这个

然后产生一个.po文件,可以分发给翻译。当翻译完成后,你运行另一个命令行工具,创建

a .mo文件,由php用来进行翻译。


当您在_('''')中更改文本或添加新文本时,您可以

创建一个新的.po文件并将其与旧的.po文件合并将
生成第三个.po文件,它告诉翻译者什么是新的,什么

只改变了一点(fzzy匹配)或者是什么与last?br />
时间。这减少了他们的工作量。


如果不在代码中使用消息ID,您可以在代码中用自己的

语言编写,并立即知道消息是你想要的那个
。你不必交叉参考知道

计划的内容。


问候

Fletch


I plan to write site on a few language. For this reason I''m trying to
find the most convenient way to output strings depending on their
unique ID. As far as I plan to have pretty much strings translated, I''m
concerned about the performance issues any of the approaches may have
on the server. Perhaps someone has already solved that of kind of
problems and can share his/her experience in this matter.

解决方案

ro********@gmail.com wrote:

I plan to write site on a few language. For this reason I''m trying to
find the most convenient way to output strings depending on their
unique ID. As far as I plan to have pretty much strings translated, I''m
concerned about the performance issues any of the approaches may have
on the server. Perhaps someone has already solved that of kind of
problems and can share his/her experience in this matter.

I''ve used two approaches:
1. http://ca.php.net/manual/en/ref.gettext.php
2. my own library to a translation table in the database

-david-


I personally put the text for each language into a separate file, then load
that file into memory at the start of each script. Each individual string is
therefore taken from memory. Because there is only one disk I/O for the
whole file, not each piece of text, it is very fast.

This is documented at
http://www.tonymarston.net/php-mysql...alisation.html

HTH

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

<ro********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...

>I plan to write site on a few language. For this reason I''m trying to
find the most convenient way to output strings depending on their
unique ID. As far as I plan to have pretty much strings translated, I''m
concerned about the performance issues any of the approaches may have
on the server. Perhaps someone has already solved that of kind of
problems and can share his/her experience in this matter.




ro********@gmail.com wrote:

I plan to write site on a few language. For this reason I''m trying to
find the most convenient way to output strings depending on their
unique ID. As far as I plan to have pretty much strings translated, I''m
concerned about the performance issues any of the approaches may have
on the server. Perhaps someone has already solved that of kind of
problems and can share his/her experience in this matter.

GetText is the standard method. there is a php extension. You write
strings such as

_(''Hello bob'')

which is then extracted by some of the gettext commandline tools. This
then produces a .po file which can be distributed to translators. When
the translation is done you run another command line tool which creates
a .mo file which is used by php to do the translation.

When you change your text in a _('' '') or add a new one then you can
create a new .po file and merge it with the old .po file which will
produce a third .po file which tells the translator what is new, what
has changed only a little (fzzy matching) or what is the same as last
time. This reduces their workload.

By not using a message id in the code you can write in your own
language in the code and know straight away that the message is the one
you want. You would not have to cross reference to know what the
program is saying.

regards
Fletch


这篇关于编写多语言网站 - 如何根据语言有效地输出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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