Web page multi-language support solution from csdn)

Source: Internet
Author: User
First, create a language file and add the. resx file to the project.

For example:

Message. zh-cn.resx 'simplified Chinese

Message. zh-tw.resx 'traditional Chinese

Message. en'

..............



========================================================== ====================================

Use name -- value Key-value pairs to enter the language you want to display on the page.

For example:

NAME value

Message. zh-cn.resx:

Res_loginbname:

Message. zh-tw.resx:

Res_loginbname:

Message. zh-cn.resx:

Res_loginbname Login Name:







========================================================== ====================================

Add multi-language settings in golbal. asax. Code (The browser must support cookies)



'================================================ ========================================================== ====================

'Application_beginrequest event

'

'The application_beginrequest method is an ASP. NET event that executes

'On each Web request into the portal application.

'

'The thread culture is set for each request using the language

'Settings

'

'================================================ ========================================================== ====================

Sub application_beginrequest (byval sender as object, byval e as eventargs)

Try

If not request. Cookies ("resource") is nothing or request. Cookies ("resource"). value = "" then

Thread. currentthread. currentculture = cultureinfo. createspecificculture (request. Cookies ("resource"). value)

Else

Thread. currentthread. currentculture = new cultureinfo (configurationsettings. deleetture ("defaultculture "))

End if

Thread. currentthread. currentuiculture = thread. currentthread. currentculture

Catch ex as exception

Thread. currentthread. currentculture = new cultureinfo (configurationsettings. deleetture ("defaultculture "))

End try

End sub 'application _ beginrequest



Add the following code to Web. config to set the encoding and default language, which is called in global. asax:



========================================================== ====================================

<Globalization requestencoding = "UTF-8" responseencoding = "UTF-8"/>

<Deleetask>

<Add key = "defaultculture" value = "ZH-CN"/>

<! -- ZH-CN: Simplified Chinese ZH-TW: Traditional Chinese en: English -->

</Appsettings>







========================================================== ====================================

Multiple languages are supported in the page code:



Imports system. Resources



Public class name

Inherits system. Web. UI. Page

Protected locrm as ResourceManager = new ResourceManager ("project file name. Message", GetType (Class Name). Assembly)



Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load

Lbllogin. Text = locrm. getstring ("res_login ")

End sub

End Class





========================================================== ====================================



Now the multi-language support work is complete, and then slowly go to the key

Message. zh-cn.resx 'simplified Chinese

Message. zh-tw.resx 'traditional Chinese

Message. en'



These language files are painful memories!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.