C# 为多种语言制作网站的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10533501/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 14:12:28  来源:igfitidea点击:

Best way to make website for multiple languages

c#asp.net.netlocalization

提问by Satinder singh

I have made a website using(Asp.net, c#) and its content in English. Now i have a requirement to make this website in such a way that is support multiple languages ie (German,French). Lable/Textbox/ string all values will display respective selected languages While searching i came to know there are some ways like

我已经使用(Asp.net,c#)及其英文内容制作了一个网站。现在我需要以支持多种语言的方式制作这个网站,即(德语,法语)。标签/文本框/字符串所有值都将显示各自选定的语言在搜索时我开始知道有一些方法,例如

  • Using localization
  • Use resource file.
  • Database(every thing is saved in database for different language).
  • 使用本地化
  • 使用资源文件。
  • 数据库(每件事都保存在不同语言的数据库中)。

frankly speaking I am not agree with 3rd option.

坦率地说,我不同意第三个选项。

I want to know which is the best way to go or is there any other better way?

我想知道哪种方法最好,或者还有其他更好的方法吗?

Note:Current Website was built using .NET framework 4.0/ vs 2010.

注意:当前网站是使用.NET framework 4.0/ vs 2010 构建的

Thanks

谢谢

采纳答案by Satinder singh

Sample code i have done using resource file add global.asax

我使用资源文件添加 global.asax 完成的示例代码

 void Application_BeginRequest(Object sender, EventArgs e)
        {
            // Code that runs on application startup
            HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
            if (cookie != null && cookie.Value != null)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
            }
        }

Blog Article: How to create multilanguage website in Asp.net C#

博客文章: 如何在 Asp.net C# 中创建多语言网站

回答by Coops

For dynamic content a thrid party plugin or a adding something such as Google translate would do it;

对于动态内容,第三方插件或添加诸如谷歌翻译之类的东西就可以做到;

http://translate.google.com/translate_tools

http://translate.google.com/translate_tools

FYI; Google Chrome has built in auto-translate and Chrome's popularity is growing fast... wow imagine a web where regardless of language you have access to ALL content this isn't that but I though I would share my thoughts

供参考; 谷歌浏览器内置了自动翻译功能,Chrome 的受欢迎程度正在快速增长……哇,想象一下一个网络,无论使用何种语言,您都可以访问所有内容,但我虽然会分享我的想法

回答by Standard Toaster

Resx:

回复:

http://msdn.microsoft.com/en-us/library/ms227427.aspx

http://msdn.microsoft.com/en-us/library/ms227427.aspx

http://dreamdotnet.blogspot.com/2007/01/tutorial-translating-aspnet-web.html

http://dreamdotnet.blogspot.com/2007/01/tutorial-translating-aspnet-web.html

You can use resx files for multiple languages and use the ResXResourceWrite to update them (if you want users to be able to update the files: http://msdn.microsoft.com/en-us/library/system.resources.resxresourcewriter.aspx)

您可以使用多种语言的 resx 文件并使用 ResXResourceWrite 来更新它们(如果您希望用户能够更新文件:http: //msdn.microsoft.com/en-us/library/system.resources.resxresourcewriter。 aspx)

This solution is only good for static content. If you want to be able to translate content from the database (for example if you have products stored in your database, and you want that the description of the product to be multilingual too). In this case you'll need to change you DB Scheme in order to support multilingual content.

此解决方案仅适用于静态内容。如果您希望能够翻译数据库中的内容(例如,如果您的数据库中存储了产品,并且您也希望产品的描述是多语言的)。在这种情况下,您需要更改 DB Scheme 以支持多语言内容。

PS you can use GetLocalResourceObject("key")in order to retrieve values without using web controls.

您可以使用 PS 来GetLocalResourceObject("key")在不使用 Web 控件的情况下检索值。

If you're using MVC, see the following question: How to localize ASP.NET MVC application?

如果您使用的是 MVC,请参阅以下问题:如何本地化 ASP.NET MVC 应用程序?