Windows Phone applicationProgramAs with Silverlight, if you are familiar with the globalization of Silverlight, you can skip this article. A specific demo in this article describes how to implement localization for the WP7 application and some precautions for localization.
1. Create a Windows Phone 7 Application named wp7global.
2. Right-click the project, select Add new project, select Resources file, and name it appresource, as shown in. Click OK
3. assuming that the default language of our program is English, the newly added resource file is the default language resource file of our program. Right-click the project wp7global and select Properties to open the properties page, click the assembly information button to set neutral language to English (United States), as shown in
4. add resource files in simplified Chinese and Traditional Chinese. Pay attention to file naming rules. If you want to add a resource file in Chinese, the resource file is named appresource. zh-CN.resx, appresource for traditional Chinese. zh-TW.resx, for more language naming, refer to msdn cultureinfo. The added project solution is roughly as follows:
5. close the project and use text editing tools (such as ultraedit, editplus, notepad ++) to open the project file wp7global. csproj, locate the supportedcultures tag, and enter ZH-CN; ZH-tw; In the tag to indicate the language supported by the project. For example
6. re-open the project, open the default language resource file appresource. resx, and change access modifier to public, as shown in figure
7. Create a class to point to the language resource file. Here we name it localizedstrings. The class provides a property of the type resource file.CodeAs follows:
8. Define localizedstrings to the project resource, that is, app. XAML. The specific code is as follows:
9. Then we can use the following code in our program for internationalization.
TEXT = "{binding Path = localizedresources. helloworld, source = {staticresource localizedstrings }}"
10. To demonstrate the specific effect, create a page for setting language named setting and place three radiobutton in the page, which is divided into different languages, such:
11. Set all check events to selectlanguage. The event method is as follows:
12. The above event method involves a static help class called appsettinghelper. Is a help class for application configuration information. The Code is as follows:
13. Add resources to the three resource files, such as helloworld:
14. Set the language of the program in the app. XAML. CS constructor. The rough code is as follows:
15. Run the program and you can see that Hello world is displayed by default. Click the setting button, set the language to ZH-CN, click the START key, and enter the program again. We found that Hello world has changed to "Hello, world ".
OK. The procedure for internationalization is roughly as above. The following are some precautions for internationalization.
1. do not add a string such as <link> to the resource file. The key is generally a string and can better describe the string it represents, such as deleetting.
2. one language and one resource file
3. Start the multiline control, such as the text box, and set wrap to text-wrapping to allow inconsistent strings in different languages.
4. localize a sentence. Do not split the sentence. The variable in the middle can be replaced by {0 }.
For more considerations, see http://msdn.microsoft.com/en-us/library/ff967552 (V = vs.92). aspx
The sample code in this article is as follows: