How to Use app_localresources to implement interface multi-language

Source: Internet
Author: User

Method 1: I read some methods on the Internet and thought the method below is quite good. However, in vs2008, I couldn't find the "tools-> generate local resource"
". In addition, you can provide some suggestions on how to make this interface more practical and simple.
1. Make the interface the same way as before, just note that use label to make all the text that requires a multilingual interface

2. After finishing, select this file in Solution Explorer and select Tools> generate local resource.

3. You will find that a directory named app_localresources; contains an additional resx file. For example, if your Aspx file is default. aspx, it will generate a file named default. aspx. resx.

4. open the file and check that all the text in the label has come here.

5. Open the original aspx file and check the source code. The source code is changed:

 

Method 2: I think this is actually not very good... the generated page basically corresponds to a resource file... It is not very well maintained.
You can write a public method to obtain multiple languages:
Public static string gettext (string name)
{
Return labels. ResourceManager. getstring (name );
}
Labels is the class generated by the created resource file.

In this case, you can directly set the settings where you need to set multiple languages:
For example, <a href = ""> <% = gettext ("Link") %> </a>
Background code:
This. button1.text = gettext ("OK ");
And so on ..

Set the current language environment by selecting a multi-language event during the renewal or login on the page:
For example, in application_beginrequest
String Language = request. Cookies ["language"] = NULL? Null: request. Cookies ["language"]. value;
If (! String. isnullorempty (language ))
{
System. Globalization. cultureinfo culture = new system. Globalization. cultureinfo (language );
System. Threading. thread. currentthread. currentuiculture = culture;
System. Threading. thread. currentthread. currentculture = culture;
}

 

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.