如何构建多语言网站? [英] How do you build a multi-language web site?

查看:180
本文介绍了如何构建多语言网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个朋友现在正在使用J2EE和Struts构建一个web应用程序,并准备好以多种语言显示页面。

A friend of mine is now building a web application with J2EE and Struts, and it's going to be prepared to display pages in several languages.

我被告知支持多语言网站的最佳方式是使用一个属性文件,其中存储您的网页的所有字符串,例如:

I was told that the best way to support a multi-language site is to use a properties file where you store all the strings of your pages, something like:

welcome.english = "Welcome!"
welcome.spanish = "¡Bienvenido!"
...

这个解决方案是确定的,但如果您的网站显示新闻或这样的东西(博客)?我的意思是,不是静态的内容,经常更新...保持网站的人必须在每种支持的语言中写入每个新条目,并将该条目的每个版本存储在数据库中。应用程序只加载用户所选语言的条目。

This solution is ok, but what happens if your site displays news or something like that (a blog)? I mean, content that is not static, that is updated often... The people that keep the site have to write every new entry in each supported language, and store each version of the entry in the database. The application loads only the entries in the user's chosen language.

如何设计数据库以支持这种实现?

How do you design the database to support this kind of implementation?

谢谢。

推荐答案

他们的方式我之前设计的数据库是一个包含基本信息像NewsID(int),NewsPubDate(datetime),NewsAuthor(varchar / int),然后有一个链接表NewsText,它有这些列:NewsID(int),NewsText(text),NewsLanguageID(int)。最后你有一个语言表,它有LanguageID(int)和LanguageName(varchar)。

They way I have designed the database before is to have an News-table containing basic info like NewsID (int), NewsPubDate (datetime), NewsAuthor (varchar/int) and then have a linked table NewsText that has these columns: NewsID(int), NewsText(text), NewsLanguageID(int). And at last you have a Language-table that has LanguageID(int) and LanguageName(varchar).

然后,当你想向用户显示新闻页面do:

Then, when you want to show your users the news-page you do:

SELECT NewsText FROM News INNER JOIN NewsText ON News.NewsID = NewsText.NewsID
WHERE NewsText.NewsLanguageID = <<Session["UserLanguageID"]>>

Session-bit是一个局部变量,用于在用户登录或输入时存储用户语言第一次。

That Session-bit is a local variable where you store the users language when they log in or enters the site for the first time.

这篇关于如何构建多语言网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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