ASP.NET 数据库本地化
我正在开发一个将分布在多个国家/地区的网站,但每个国家都应该有自己的网站。我的计划是为每个国家/地区建立一个不同的数据库(具有相同的结构),但是我如何根据他们访问网站的国家/地区来选择使用哪个数据库。
我见过其他网站使用相同的原则,其中他们例如,拥有 .com 和 .co.uk 地址,无论您访问哪一个,您都会获得本地化到您所在国家/地区的内容。这是怎么做到的?是否可以根据浏览器国家/地区自定义数据库连接字符串。
这是我第一次制作跨国网站,因此尝试尽可能多地学习本地化知识
I am working on a website that is going to be distributed in multiple countries, but each county should have its own site. My plan is to have a different database(with the same structure) for each country, but how do I select which database to use depending on which county they are access the website in.
I have seen other sites that use the same principle where they have a .com and a .co.uk address for example and no matter which one you go to you are always provided with content localized to you country. How is this done? Is it possible to customize the database connection string based on the browsers country.
This is the first time I have produced a multi national site so trying to learn as much as I can about localization
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈建议您不要为每种语言使用不同的数据库。
事实上,这非常违反 DRY 原则,因为您必须在每个数据库中重复所有不依赖于语言的数据,并且如果您想更新其中一个字段,则必须在每个数据库中执行此操作。
我宁愿建议您使用 ASP.NET 的常规全局和本地资源。或者,如果您想将文本保留在数据库中,我建议保留一个包含所有数据的文本。
有多种类型的表结构可以考虑多种语言,在其中进行选择取决于您需要多少种语言和其他因素。
这里有一篇关于一些策略的好文章: 什么是最好的保存多语言数据的数据库结构?
对于自动选择语言的问题,我更喜欢根据用户的 IP 使用用户所在的国家/地区,就像 Google 和其他大型网站一样。为此,我从 maxmind 购买了 IP 数据库(50 欧元),它很容易实现,而且非常精确。
我希望这有帮助!
I would strongly suggest you not to use different databases for each language.
In fact this would be very much against the DRY principle, as you would have to repeat all the data that is not language dependent in each database and if you want to update one of those fields you would have to do it in each database.
I would rather suggest you to use the normal global and local resources of ASP.NET. Or if you want to keep the text in the database I would suggest to keep a single one with all the data.
There are many types of structures of the tables that account for multiple languages and deciding amongst them depends on how many languages you need and other factors.
here there is a good post about a few strategies: What's the best database structure to keep multilingual data?
For what concerns the selection of the language automatically I rather prefer using the country of the user based on their IP, same as Google and other big sites. To do this I bought the database of IP from maxmind (it was 50€) and it was easy to implement and very precise.
I hope this helps!
您可以在“Global.asax.cs”文件的“Application_Start()”方法中编写以下代码,该方法根据浏览器获取国家/地区名称并将“ConnectionString”存储在会话变量中。
可以使用资源文件来存储所有连接字符串,而不是在此处进行硬编码。
希望这对你有帮助!
You can write the below code in the "Application_Start()" method of the "Global.asax.cs" file which gets the country name based on the browser and stores the "ConnectionString" in a session variable.
A resource file can be used to store all the connection strings instead of hard-coding here.
Hope this helps you!!