C# 您如何本地化数据库驱动的网站
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/160335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you localize a database driven website
提问by sontek
I've been playing with the .NET built in localization features and they seem to all rely on putting data in resx files.
我一直在使用 .NET 内置的本地化功能,它们似乎都依赖于将数据放入 resx 文件中。
But most systems can't rely on this because they are database driven. So how do you solve this issue? Is there a built in .NET way, or do you create a translations table in SQL and do it all manually? And if you have to do this on the majority of your sites, is there any reason to even use the resx way of localization?
但是大多数系统不能依赖于此,因为它们是数据库驱动的。那么你如何解决这个问题呢?是否有内置的 .NET 方式,或者您是否在 SQL 中创建翻译表并手动完成所有操作?如果您必须在大多数网站上执行此操作,是否有任何理由甚至使用 resx 本地化方式?
An example of this is I have an FAQ list on my site, I keep this list in the database so I can easily add/remove more, but by putting it in the database, I have no good way have translating this information into multiple languages.
例如,我的网站上有一个常见问题列表,我将此列表保存在数据库中,以便我可以轻松添加/删除更多内容,但是通过将其放入数据库中,我无法将这些信息翻译成多种语言.
采纳答案by sontek
In my opinion, localizing dynamic content (e.g., your FAQ) should be done by you in your database. Depending on how your questions are stored, I would probably create a "locale" column and use that when selecting the FAQ questions from the database. I'm not sure if this would scale very well when you started localizing lots of tables.
在我看来,本地化动态内容(例如,您的常见问题解答)应该由您在您的数据库中完成。根据您的问题的存储方式,我可能会创建一个“区域设置”列,并在从数据库中选择常见问题解答问题时使用它。当您开始本地化大量表格时,我不确定这是否会很好地扩展。
For static content (e.g, form field labels, static text, icons, etc) you should probably be just fine using file-based resources. If you really wanted to, however, it looks like it wouldn't be super hard to create a custom resource provider implementation that could handle this.
对于静态内容(例如,表单域标签、静态文本、图标等),使用基于文件的资源应该没问题。但是,如果您真的想这样做,那么创建一个可以处理此问题的自定义资源提供程序实现似乎并不难。
Here's some related links:
以下是一些相关链接:
- http://channel9.msdn.com/forums/Coffeehouse/250892-Localizing-with-a-database-or-resx-files/
- http://weblogs.asp.net/scottgu/archive/2006/05/30/ASP.NET-2.0-Localization-_2800_Video_2C00_-Whitepaper_2C00_-and-Database-Provider-Support_2900_.aspx
- http://www.arcencus.nl/Blogs/tabid/105/EntryID/20/Default.aspx
- http://msdn.microsoft.com/en-us/library/aa905797.aspx
- http://www.codeproject.com/KB/aspnet/customsqlserverprovider.aspx
- http://channel9.msdn.com/forums/Coffeehouse/250892-Localizing-with-a-database-or-resx-files/
- http://weblogs.asp.net/scottgu/archive/2006/05/30/ASP.NET-2.0-Localization-_2800_Video_2C00_-Whitepaper_2C00_-and-Database-Provider-Support_2900_.aspx
- http://www.arcencus.nl/Blogs/tabid/105/EntryID/20/Default.aspx
- http://msdn.microsoft.com/en-us/library/aa905797.aspx
- http://www.codeproject.com/KB/aspnet/customsqlserverprovider.aspx
回答by Dan Goldstein
Currently, translation is not something that can be done automatically. The best way is to get a person to translate and use Nick's methods to show the proper language.
目前,翻译不是可以自动完成的。最好的方法是请人翻译并使用尼克的方法来展示正确的语言。
回答by Soraz
For a given item in your data model, split out the description part into a localized table with a locale Id column (LCID).
对于数据模型中的给定项目,将描述部分拆分为具有区域设置 Id 列 (LCID) 的本地化表。
So the table for Product would not in fact contain the products description or name, but only its hard and fast values (ProductId, EAN, NumberInStock, NextStockData, IsActive, IsPublished) etc.
因此,产品表实际上不包含产品描述或名称,而仅包含其硬值和快速值(ProductId、EAN、NumberInStock、NextStockData、IsActive、IsPublished)等。
ProductDescription then contains ProductId, Name, Description, LCID
ProductDescription 然后包含 ProductId、Name、Description、LCID
回答by Kibbee
I live in Canada so multilingualism is a big deal. I've seen two approaches. First option is to store all localized data for a specific record in a different table, linked to the original table by the primary key, and the locale. The second option is similar to the first, except that for each locale, there is a different table, with the locale as a suffix for the table name.
我住在加拿大,所以使用多种语言很重要。我见过两种方法。第一个选项是将特定记录的所有本地化数据存储在不同的表中,通过主键和区域设置链接到原始表。第二个选项与第一个类似,不同之处在于每个语言环境都有一个不同的表,语言环境作为表名的后缀。
Option A
选项 A
Item (ItemID, ...)
ItemLocal (ItemID,LocaleID,....)
Option B
选项 B
Item (ItemID, ...)
Item_ENUS (ItemID,....)
Item_ENGB (ItemID,....)
Item_FR (ItemID,....)
A third option I thought Of recent, which would be really nice if a database supported it natively would be to store the values for all locals in the same field. And if the field was set up as varchar-multilocal, then you would have to access it by passing a parameter to specify the language. Nothing like this exists as I know it, but it's something that I think would really make things a lot easier, and a lot more fluid.
我最近想到的第三个选项,如果数据库本身支持它,那将非常好,那就是将所有本地人的值存储在同一字段中。如果该字段设置为 varchar-multilocal,则您必须通过传递参数来指定语言来访问它。据我所知,这样的东西不存在,但我认为它确实会让事情变得更容易,更流畅。
回答by Jason Kealey
We use a mix of RESX files and Option A of Kibbee's response. We created a simple tool to manage the RESX files online: http://blog.lavablast.com/post/2008/02/RESX-file-Web-Editor.aspx
我们混合使用了 RESX 文件和 Kibbee 响应的选项 A。我们创建了一个简单的工具来在线管理 RESX 文件:http: //blog.lavablast.com/post/2008/02/RESX-file-Web-Editor.aspx