你如何建立一个多语言的网站? [英] How do you build a multi-language web site?

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

问题描述

我的一个朋友现在正在使用 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).

然后,当您想向用户展示新闻页面时:

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天全站免登陆