我用英语制作了一个网站,添加一种语言的最佳方法是什么?
所以,我创建了一个大网站(不同文件中的大量文本和大量编程)。我需要添加一种语言,我该怎么办?添加第二语言并让访问者在它们之间进行选择的最快方法是什么?有什么想法吗?
谢谢。
So, I have created a big website (a lot of text in different files and a lot of programming). I need to add one more language, how should I do? What is the fastest way I can add second language and let my visitors to choose between them? Any ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
翻译是您从一开始就必须考虑的事情,尤其是对于动态网站。
gettext
,这是一个成熟的翻译工具。Translation is something you have to think about from the beginning, especially with dynamic sites.
gettext
which is a mature tool for doing translations.无论您采用哪种方法,您都需要将所有输出的字符串存储在单独的资源中。带有数组的平面文件是最快的,尽管 SQLite 数据库会更灵活。
如果您要使用数组,您基本上只需创建一些语言文件,例如 english.php:
... 和 french.php:
然后您可以创建一个静态语言类,该类将导入适当的语言文件,并返回翻译后的语言文件基于该文件中的数组的字符串。例如:
Regardless of your approach, you are going to need to store all of your outputted strings in a separate resource. Flat files with arrays would be the fastest, though an SQLite database would be more flexible.
If you were to use arrays, you would basically just make a few language files, such as english.php:
... and french.php:
Then you could make a static Language class that would import the appropriate language file, and return translated strings based on the array in that file. For example:
首先,您需要国际化您的整个网站,然后您需要将其本地化为您的目标语言。
这是另一种情况,唯一重要的数字是零、一和无穷大。要么支持零种语言(根本没有人机界面),要么支持一种语言(只需硬编码),要么支持任意数量的语言。添加一种语言并不比添加 10 种语言容易。
First you need to internationalize your entire web site, and then you need to localize it into your target language.
This is another case where the only numbers that matter are zero, one, and infinity. Either you support zero languages (there is no human interface at all), one language (which you just hardcode throughout), or any number of languages. Adding one more language is no easier than adding 10 more.
您可以将 gettext 与 poedit 一起使用,请检查此 http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
You can use gettext along with poedit, check this http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
我的建议是:将内容写入单独的 xml 文件中,每种语言一个,并且根据用户的语言,您将加载您的网站,从包含所选语言的 Xml 中检索内容。
My suggestion is: write the content in separated xml files, one for each language, and depending on the language of the user, you will load your website retrieving the content from the Xml that contains the selected language.